From 64df3f8d09d4b4e68f39748e0ad8d44fc8e8acd6 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Fri, 18 Jun 2021 11:00:24 +0000 Subject: [PATCH] [FIX] product,purchase_stock: get correct supplier for lead days Resupplying a product with a purchase order ask to choose the suitable supplier to put on the purchase order. Another search is perform on top of that to compute de date to order in order to respect the lead days promise by the supplier. The issue is that the first search is done with the orderpoint company into account but not the second one. This commit passes the company to _select_seller when computing the total lead days required for an order. opw : 2557125 closes odoo/odoo#72466 X-original-commit: c1bd985ef6a77c8848c4a2a8b92508511d9d8638 Signed-off-by: William Henrotin --- addons/purchase_stock/models/stock_rule.py | 2 +- .../tests/test_purchase_lead_time.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 2064f76b6e8..db8b008612d 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -150,7 +150,7 @@ class StockRule(models.Model): delay, delay_description = super()._get_lead_days(product) bypass_delay_description = self.env.context.get('bypass_delay_description') buy_rule = self.filtered(lambda r: r.action == 'buy') - seller = product._prepare_sellers() + seller = product.with_company(buy_rule.company_id)._select_seller() if not buy_rule or not seller: return delay, delay_description buy_rule.ensure_one() diff --git a/addons/purchase_stock/tests/test_purchase_lead_time.py b/addons/purchase_stock/tests/test_purchase_lead_time.py index d99c084dbd7..486dbefe270 100644 --- a/addons/purchase_stock/tests/test_purchase_lead_time.py +++ b/addons/purchase_stock/tests/test_purchase_lead_time.py @@ -273,6 +273,9 @@ class TestPurchaseLeadTime(PurchaseTestCommon): def test_reordering_days_to_purchase(self): company = self.env.ref('base.main_company') + company2 = self.env['res.company'].create({ + 'name': 'Second Company', + }) company.write({'po_lead': 0.00}) self.patcher = patch('odoo.addons.stock.models.stock_orderpoint.fields.Date', wraps=fields.Date) self.mock_date = self.patcher.start() @@ -280,19 +283,30 @@ class TestPurchaseLeadTime(PurchaseTestCommon): vendor = self.env['res.partner'].create({ 'name': 'Colruyt' }) + vendor2 = self.env['res.partner'].create({ + 'name': 'Delhaize' + }) self.env.company.days_to_purchase = 2.0 product = self.env['product.product'].create({ 'name': 'Chicory', 'type': 'product', - 'seller_ids': [(0, 0, {'name': vendor.id, 'delay': 1.0})] + 'seller_ids': [ + (0, 0, {'name': vendor2.id, 'delay': 15.0, 'company_id': company2.id}), + (0, 0, {'name': vendor.id, 'delay': 1.0, 'company_id': company.id}) + ] }) orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) orderpoint_form.product_id = product orderpoint_form.product_min_qty = 0.0 orderpoint = orderpoint_form.save() + orderpoint_form = Form(self.env['stock.warehouse.orderpoint'].with_company(company2)) + orderpoint_form.product_id = product + orderpoint_form.product_min_qty = 0.0 + orderpoint = orderpoint_form.save() + warehouse = self.env['stock.warehouse'].search([], limit=1) delivery_moves = self.env['stock.move'] for i in range(0, 6):