changeset 9917f3455916 in modules/stock:default details: https://hg.tryton.org/modules/stock?cmd=changeset&node=9917f3455916 description: Ignore consumable products when inactivating a location.
issue10964 review360551002 diffstat: CHANGELOG | 2 ++ location.py | 6 +++++- tests/test_module.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletions(-) diffs (83 lines): diff -r c2f056739e48 -r 9917f3455916 CHANGELOG --- a/CHANGELOG Wed Jun 15 22:03:38 2022 +0200 +++ b/CHANGELOG Fri Jun 17 11:18:13 2022 +0200 @@ -1,3 +1,5 @@ +* Ignore consumable products when inactivating locations + Version 6.4.0 - 2022-05-02 * Bug fixes (see mercurial logs for details) * Add location or warehouse in shipment tree view diff -r c2f056739e48 -r 9917f3455916 location.py --- a/location.py Wed Jun 15 22:03:38 2022 +0200 +++ b/location.py Fri Jun 17 11:18:13 2022 +0200 @@ -273,6 +273,7 @@ def get_empty_locations(cls, locations=None): pool = Pool() Move = pool.get('stock.move') + Product = pool.get('product.product') if locations is None: locations = cls.search([]) if not locations: @@ -287,8 +288,11 @@ quantities = Move.compute_quantities( query, location_ids, with_childs=True) empty = set(location_ids) + product_ids = [q[1] for q in quantities.keys()] + consumables = { + p.id for p in Product.browse(product_ids) if p.consumable} for (location_id, product), quantity in quantities.items(): - if quantity: + if quantity and product not in consumables: empty.discard(location_id) for sub_ids in grouped_slice(list(empty)): sub_ids = list(sub_ids) diff -r c2f056739e48 -r 9917f3455916 tests/test_module.py --- a/tests/test_module.py Wed Jun 15 22:03:38 2022 +0200 +++ b/tests/test_module.py Fri Jun 17 11:18:13 2022 +0200 @@ -1520,5 +1520,46 @@ product.active = False product.save() + @with_transaction() + def test_location_inactive_with_consumable_product(self): + "Test inactive location with consumable products" + pool = Pool() + Location = pool.get('stock.location') + Move = pool.get('stock.move') + Template = pool.get('product.template') + Product = pool.get('product.product') + Uom = pool.get('product.uom') + + warehouse, = Location.search([('type', '=', 'warehouse')]) + storage, = Location.search([('code', '=', 'STO')]) + lost_found, = Location.search([('type', '=', 'lost_found')]) + + unit, = Uom.search([('name', '=', "Unit")]) + template, = Template.create([{ + 'name': "Product", + 'type': 'goods', + 'default_uom': unit.id, + 'consumable': True, + }]) + product, = Product.create([{'template': template.id}]) + + company = create_company() + with set_company(company): + today = datetime.date.today() + + moves = Move.create([{ + 'product': product.id, + 'uom': unit.id, + 'quantity': 1, + 'from_location': lost_found.id, + 'to_location': storage.id, + 'planned_date': today, + 'effective_date': today, + 'company': company.id, + }]) + Move.do(moves) + warehouse.active = False + warehouse.save() + del ModuleTestCase