[FIX] stock: muliple rules leadtime

Steps to Reproduce on Runbot:
- Install MRP
- Create a second warehouse
- Go to Warehouse -> Routes -> Manufacturing.
- Set the "Supplied Warehouse" to the first warehouse.
- In Inventory > Opertaions > Replenishment
- Create a new Replenishment with Manufacturing route
- click on Replenishment information (small "i" button)
- Expected singelton traceback error.

Fix:
get_lead_time in Manufacturing expects a single rule
using _get_rule to deteermine the correct rule as the
comment sugessted

opw-3838099

closes odoo/odoo#163318

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Walid
2024-04-26 17:18:00 +00:00
parent e1c623127f
commit 168ec21e6e
2 changed files with 37 additions and 2 deletions
+32
View File
@@ -40,6 +40,38 @@ class TestMrpReplenish(TestMrpCommon):
wizard3 = self._create_wizard(product, wh)
self.assertEqual(fields.Datetime.from_string('2023-01-06 00:00:00'), wizard3.date_planned)
def test_mrp_orderpoint_leadtime(self):
self.warehouse = self.env.ref('stock.warehouse0')
route_manufacture = self.warehouse.manufacture_pull_id.route_id
route_manufacture.supplied_wh_id = self.warehouse
route_manufacture.supplier_wh_id = self.warehouse
route_manufacture.rule_ids.delay = 2
product_1 = self.env['product.product'].create({
'name': 'Cake',
'type': 'product',
'route_ids': [(6, 0, [route_manufacture.id])]
})
self.env['mrp.bom'].create({
'product_tmpl_id': product_1.product_tmpl_id.id,
'produce_delay': 4,
'product_qty': 1,
})
# setup orderpoint (reordering rule)
rr = self.env['stock.warehouse.orderpoint'].create({
'name': 'Cake RR',
'location_id': self.warehouse.lot_stock_id.id,
'product_id': product_1.id,
'product_min_qty': 0,
'product_max_qty': 5,
})
info = self.env['stock.replenishment.info'].create({'orderpoint_id': rr.id})
# for manufacturing delay should be taken from the bom
self.assertEqual("4.0 days", info.wh_replenishment_option_ids.lead_time)
def test_mrp_delay_bom(self):
route = self.env.ref('mrp.route_warehouse0_manufacture')
product = self.product_4
@@ -118,8 +118,11 @@ class StockReplenishmentOption(models.TransientModel):
@api.depends('replenishment_info_id')
def _compute_lead_time(self):
for record in self:
lead_time = record.route_id.rule_ids._get_lead_days(record.product_id)[0]['total_delay'] #TO FIX: use _get_rule to avoid singleton issue
record.lead_time = str(lead_time) + " days"
rule = self.env['procurement.group']._get_rule(record.product_id, record.location_id, {
'route_ids': record.route_id,
'warehouse_id': record.warehouse_id,
})
record.lead_time = str(rule._get_lead_days(record.product_id)[0]['total_delay'] if rule else 0) + " days"
@api.depends('warehouse_id', 'free_qty', 'uom', 'qty_to_order')
def _compute_warning_message(self):