[FIX] mrp: compute lead days in multi warehouse flow

Since 461d311b73, the manufacture rule lead time is taken into
account in the date computation for the procurement. The issue comes
from the fact we assume there is only one warehouse related to the stock
rules chain.

closes odoo/odoo#147261

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
William Henrotin
2024-01-08 21:58:28 +00:00
parent 4b096631ad
commit a394d39332
2 changed files with 57 additions and 9 deletions
+11 -9
View File
@@ -210,16 +210,18 @@ class StockRule(models.Model):
if bom.type == 'normal':
# pre-production rules
warehouse = self.location_dest_id.warehouse_id
if warehouse.manufacture_steps != 'mrp_one_step':
wh_manufacture_rules = product._get_rules_from_location(product.property_stock_production, route_ids=warehouse.pbm_route_id)
extra_delays, extra_delay_description = (wh_manufacture_rules - self)._get_lead_days(product, **values)
for key, value in extra_delays.items():
delays[key] += value
delay_description += extra_delay_description
for wh in warehouse:
if wh.manufacture_steps != 'mrp_one_step':
wh_manufacture_rules = product._get_rules_from_location(product.property_stock_production, route_ids=wh.pbm_route_id)
extra_delays, extra_delay_description = (wh_manufacture_rules - self)._get_lead_days(product, **values)
for key, value in extra_delays.items():
delays[key] += value
delay_description += extra_delay_description
# manufacturing security lead time
security_delay = self.picking_type_id.company_id.manufacturing_lead
delays['total_delay'] += security_delay
delays['security_lead_days'] += security_delay
for comp in self.picking_type_id.company_id:
security_delay = comp.manufacturing_lead
delays['total_delay'] += security_delay
delays['security_lead_days'] += security_delay
if not bypass_delay_description:
delay_description.append((_('Manufacture Security Lead Time'), _('+ %d day(s)', security_delay)))
days_to_order = values.get('days_to_order', bom.days_to_prepare_mo)
+46
View File
@@ -82,6 +82,52 @@ class TestWarehouseMrp(common.TestMrpCommon):
self.assertTrue(self.warehouse_1.manu_type_id.active)
self.assertIn(manu_route, warehouse_1_stock_manager._get_all_routes())
def test_multi_warehouse_resupply(self):
""" test a multi warehouse flow give a correct date delay
product_6 is sold from warehouse_1, its component (product_4) is
resupplied from warehouse_2 and manufactured in warehouse_2.
Everything in mto """
mto = self.env.ref('stock.route_warehouse0_mto')
mto.active = True
warehouse_2 = self.env['stock.warehouse'].create({
'name': 'Warehouse 2',
'code': 'WH2',
})
# product 4 can only be manufacture in WH2
self.bom_1.picking_type_id = warehouse_2.manu_type_id
self.warehouse_1.manufacture_steps = "pbm"
self.warehouse_1.resupply_wh_ids = [(6, 0, [warehouse_2.id])]
self.product_6.route_ids = [(6, 0, [
self.env.ref('mrp.route_warehouse0_manufacture').id,
mto.id,
])]
self.product_4.route_ids = [(6, 0, [
self.warehouse_1.resupply_route_ids.id,
self.env.ref('stock.route_warehouse0_mto').id,
mto.id,
])]
warehouse_2.resupply_route_ids.rule_ids.procure_method = 'make_to_order'
customer_location = self.env.ref('stock.stock_location_customers')
pg = self.env['procurement.group'].create({'name': 'Test-pg-mtso-mto'})
self.env['procurement.group'].run([
pg.Procurement(
self.product_6,
5.0,
self.product_6.uom_id,
customer_location,
'test_ressuply',
'test_ressuply',
self.warehouse_1.company_id,
{
'warehouse_id': self.warehouse_1,
'group_id': pg,
},
),
])
def test_manufacturing_scrap(self):
"""
Testing to do a scrap of consumed material.