From c25f4359942a9ee0035cb08bc69a0c25c6f8258f Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 20 May 2020 09:14:47 +0000 Subject: [PATCH] [FIX] purchase_stock: vendor choice in multi-company MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set two companies (A and B); - Set intercompany flows enabled between company A and B with synchronization of PO/SO; - create a product X is configured as follows in company B: - Storable product; - Routes “Buy” and “Dropship”; - Vendors price list set with vendor = company A. - Product X is configured as follows in company A: - Storable product; - Reordering rule Min 0 / Max 0; - Route “Buy”; - Vendors price list set with vendor = 'External Vendor'. - Create and validate a sale order for product X to final customer within company B; Odoo will automatically create a purchase order for product X to company A within company B; - Validate the purchase order in company B; Odoo will automatically create a sale order for product X to company B within company A; - If there is no available stock in warehouse A; Odoo will automatically create a purchase order for product X within company A. Before this commit, the purchase order is created with vendor as 'Company A'. As '_select_seller' is run in sudo mode (see: https://github.com/odoo/odoo/blob/a16c4a0dabe58ab2cfade353c113387ae5bcd572/addons/stock/models/stock_rule.py#L458), so is not company-aware, therefore the first matching supplier is chosen. Now, the purchase order will be created with vendor as 'External Vendor'. opw-2255989 closes odoo/odoo#51596 closes odoo/odoo#51908 X-original-commit: e2dd8ea7544fba659810ba829433fce7099c1d40 Signed-off-by: Jorge Pinna Puissant (jpp) --- addons/purchase_stock/models/stock_rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index b10cd241544..620f8b087e3 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -54,7 +54,7 @@ class StockRule(models.Model): if procurement.values.get('supplierinfo_id'): supplier = procurement.values['supplierinfo_id'] else: - supplier = procurement.product_id._select_seller( + supplier = procurement.product_id.with_company(procurement.company_id.id)._select_seller( partner_id=procurement.values.get("supplierinfo_name"), quantity=procurement.product_qty, date=schedule_date.date(),