Ignore consumable products when inactivating a location.
issue10964 review360551002
This commit is contained in:
1 parent
a3757b74ba
commit
15c8a99407
3 files changed
+48
-1
No files matched your search
@@ -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
|
||||
|
||||
+5
-1
@@ -273,6 +273,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
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 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
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)
|
||||
|
||||
@@ -1520,5 +1520,46 @@ class StockTestCase(
|
||||
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
|
||||
Reference in new issue
Block a user