Skip to content

Commit

Permalink
[FIX] purchase_stock: wrong supplier from orderpoint:
Browse files Browse the repository at this point in the history
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#114845

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
  • Loading branch information
amoyaux committed Mar 15, 2023
1 parent 176271d commit 34c58ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
7 changes: 0 additions & 7 deletions addons/purchase_stock/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
11 changes: 2 additions & 9 deletions addons/purchase_stock/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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

0 comments on commit 34c58ba

Please sign in to comment.