Set context stock_date_end
This commit is contained in:
parent
c8ee4c5bf7
commit
eb854679d5
16
product.py
16
product.py
|
@ -39,28 +39,36 @@ class Product:
|
|||
|
||||
@classmethod
|
||||
def get_quantity(cls, products, name):
|
||||
Location = Pool().get('stock.location')
|
||||
pool = Pool()
|
||||
Location = pool.get('stock.location')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
context = Transaction().context
|
||||
|
||||
# not locations in context
|
||||
if not context.get('locations'):
|
||||
warehouses = Location.search([('type', '=', 'warehouse')])
|
||||
location_ids = [w.storage_location.id for w in warehouses]
|
||||
with Transaction().set_context(locations=location_ids):
|
||||
with Transaction().set_context(locations=location_ids, stock_date_end=today):
|
||||
return cls._get_quantity(products, name, location_ids, products)
|
||||
# return super (with locations in context)
|
||||
return super(Product, cls).get_quantity(products, name)
|
||||
|
||||
@classmethod
|
||||
def search_quantity(cls, name, domain=None):
|
||||
Location = Pool().get('stock.location')
|
||||
pool = Pool()
|
||||
Location = pool.get('stock.location')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
context = Transaction().context
|
||||
|
||||
# not locations in context
|
||||
if not context.get('locations'):
|
||||
warehouses = Location.search([('type', '=', 'warehouse')])
|
||||
location_ids = [w.storage_location.id for w in warehouses]
|
||||
with Transaction().set_context(locations=location_ids):
|
||||
with Transaction().set_context(locations=location_ids, stock_date_end=today):
|
||||
return cls._search_quantity(name, location_ids, domain)
|
||||
# return super (with locations in context)
|
||||
return super(Product, cls).search_quantity(name, domain=None)
|
||||
|
|
Loading…
Reference in New Issue