From 34c58ba990e5a1b444d3116e78a03b688b3e2c1f Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 10 Mar 2023 14:31:18 +0000 Subject: [PATCH] [FIX] purchase_stock: wrong supplier from orderpoint: Use case to reproduce: - Set "receive good in input and then stock" on the warehouse. - Set two suppliers on a product. one from a partner (higher priority) and one from a child partner (lower priority). - Set the child partner as the vendor on the replenishment report. - Order a replenishment for the product. It happens due to an hack that use a field on `stock.move` in order to temporaly store the partner among the moves until the RFQ. But this field is a many2one on `res.partner` model and not on `product.supplierinfo` `_run_buy` receive a partner and still use `_select_seller` with the partner in order to find the best pricelist. But it won't use the specific supplier price list set on the orderpoint. In order to fix, we don't store anymore the price list partner on the intermediate move. In run_buy we receive the orderpoint if it's the origin of the procurement. On the orderpoint the supplierinfo is set. So we take it from there. opw-3180945 closes odoo/odoo#114845 Signed-off-by: William Henrotin (whe) --- addons/purchase_stock/models/stock.py | 7 ------- addons/purchase_stock/models/stock_rule.py | 11 ++--------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py index d898de0920469..4407598dc5561 100644 --- a/addons/purchase_stock/models/stock.py +++ b/addons/purchase_stock/models/stock.py @@ -99,13 +99,6 @@ def _prepare_move_split_vals(self, uom_qty): vals['purchase_line_id'] = self.purchase_line_id.id return vals - def _prepare_procurement_values(self): - proc_values = super()._prepare_procurement_values() - if self.restrict_partner_id: - proc_values['supplierinfo_name'] = self.restrict_partner_id - self.restrict_partner_id = False - return proc_values - def _clean_merged(self): super(StockMove, self)._clean_merged() self.write({'created_purchase_line_id': False}) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 71910424c178b..f25dbc9d478e0 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -56,6 +56,8 @@ def _run_buy(self, procurements): supplier = False if procurement.values.get('supplierinfo_id'): supplier = procurement.values['supplierinfo_id'] + elif procurement.values.get('orderpoint_id') and procurement.values['orderpoint_id'].supplier_id: + supplier = procurement.values['orderpoint_id'].supplier_id else: supplier = procurement.product_id.with_company(procurement.company_id.id)._select_seller( partner_id=procurement.values.get("supplierinfo_name"), @@ -332,12 +334,3 @@ def _push_prepare_move_copy_values(self, move_to_copy, new_date): res = super(StockRule, self)._push_prepare_move_copy_values(move_to_copy, new_date) res['purchase_line_id'] = None return res - - def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values): - move_values = super()._get_stock_move_values(product_id, product_qty, product_uom, location_id, name, origin, company_id, values) - if values.get('supplierinfo_name'): - move_values['restrict_partner_id'] = values['supplierinfo_name'].id - elif values.get('supplierinfo_id'): - partner = values['supplierinfo_id'].name - move_values['restrict_partner_id'] = partner.id - return move_values