From e1e8f33ca9deb9a42dcbd593bddd7fd831685d07 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#119063 X-original-commit: 3cd5b9b7688ef7e6c6fa4fce1c0ad319fb577745 Signed-off-by: William Henrotin (whe) --- addons/purchase_stock/models/stock_move.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_move.py b/addons/purchase_stock/models/stock_move.py index af9e63f0b96..9f9f02cf0ba 100644 --- a/addons/purchase_stock/models/stock_move.py +++ b/addons/purchase_stock/models/stock_move.py @@ -151,13 +151,6 @@ class StockMove(models.Model): 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_ids': [Command.clear()]}) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 15dddecc5d5..5b276e1cbbf 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -56,6 +56,8 @@ class StockRule(models.Model): 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"), @@ -321,12 +323,3 @@ class StockRule(models.Model): 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'].partner_id - move_values['restrict_partner_id'] = partner.id - return move_values