[IMP] mrp: add pre-production rules' delays in _get_lead_days
If there are pre-production rules, their delays should also be added to the total delay of a manufacture route. Task-3081481 closes odoo/odoo#137810 Related: odoo/enterprise#48516 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
78e44dc5a3
commit
461d311b73
@@ -203,6 +203,15 @@ class StockRule(models.Model):
|
||||
if not bypass_delay_description:
|
||||
delay_description.append((_('Manufacturing Lead Time'), _('+ %d day(s)', manufacture_delay)))
|
||||
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
|
||||
# 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
|
||||
|
||||
@@ -3598,3 +3598,21 @@ class TestMrpOrder(TestMrpCommon):
|
||||
update_quantity_wizard.change_prod_qty()
|
||||
new_picking = mo.picking_ids
|
||||
self.assertEqual(len(new_picking), 1, "Return picking should not be created in done Transfer")
|
||||
|
||||
def test_manufacture_lead_days(self):
|
||||
"""Test the lead days computation for manufacturing route.
|
||||
"""
|
||||
rule = self.env['stock.rule'].search([('action', '=', 'manufacture')], limit=1)
|
||||
|
||||
self.env.company.manufacturing_lead = 1
|
||||
self.bom_1.days_to_prepare_mo = 2
|
||||
self.bom_1.produce_delay = 3
|
||||
delays, _ = rule._get_lead_days(self.bom_1.product_id, bom=self.bom_1)
|
||||
self.assertEqual(delays['total_delay'], self.env.company.manufacturing_lead + self.bom_1.days_to_prepare_mo + self.bom_1.produce_delay)
|
||||
|
||||
# switch to the 3 steps, only pre-production rules delays will be taken into account
|
||||
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
|
||||
warehouse.manufacture_steps = 'pbm_sam'
|
||||
warehouse.pbm_route_id.rule_ids.delay = 100
|
||||
delays, _ = rule._get_lead_days(self.bom_1.product_id, bom=self.bom_1)
|
||||
self.assertEqual(delays['total_delay'], self.env.company.manufacturing_lead + self.bom_1.days_to_prepare_mo + self.bom_1.produce_delay + 100 * 2)
|
||||
|
||||
Reference in New Issue
Block a user