Set context stock_date_end

This commit is contained in:
resteve 2016-02-23 09:23:14 +01:00
parent c8ee4c5bf7
commit eb854679d5

View file

@ -39,28 +39,36 @@ class Product:
@classmethod @classmethod
def get_quantity(cls, products, name): 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 context = Transaction().context
# not locations in context # not locations in context
if not context.get('locations'): if not context.get('locations'):
warehouses = Location.search([('type', '=', 'warehouse')]) warehouses = Location.search([('type', '=', 'warehouse')])
location_ids = [w.storage_location.id for w in warehouses] 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 cls._get_quantity(products, name, location_ids, products)
# return super (with locations in context) # return super (with locations in context)
return super(Product, cls).get_quantity(products, name) return super(Product, cls).get_quantity(products, name)
@classmethod @classmethod
def search_quantity(cls, name, domain=None): 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 context = Transaction().context
# not locations in context # not locations in context
if not context.get('locations'): if not context.get('locations'):
warehouses = Location.search([('type', '=', 'warehouse')]) warehouses = Location.search([('type', '=', 'warehouse')])
location_ids = [w.storage_location.id for w in warehouses] 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 cls._search_quantity(name, location_ids, domain)
# return super (with locations in context) # return super (with locations in context)
return super(Product, cls).search_quantity(name, domain=None) return super(Product, cls).search_quantity(name, domain=None)