[FIX] purchase_stock: replenishment correct vendor from wizard
Steps to reproduce:
- Create a product with 2 vendors
- Click replenish on the product page and select the second vendor
- The PO is created for the first vendor
Bug:
the replenishment will create a move which will create/edit a PO
the selected supplier is discarded
Fix:
set the partner on the procurement group to keep track of it
note:
'supplierinfo_name' no longer used, will be removed in master
related test ("test_procure_not_default_partner") is now irrelevant
opw-3776680
closes odoo/odoo#161974
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -60,7 +60,7 @@ class StockRule(models.Model):
|
||||
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"),
|
||||
partner_id=procurement.values.get("supplierinfo_name") or (procurement.values.get("group_id") and procurement.values.get("group_id").partner_id),
|
||||
quantity=procurement.product_qty,
|
||||
date=max(procurement_date_planned.date(), fields.Date.today()),
|
||||
uom_id=procurement.product_uom)
|
||||
|
||||
@@ -451,3 +451,44 @@ class TestReplenishWizard(TestStockCommon):
|
||||
|
||||
self.assertEqual(last_po_id.partner_id, vendor)
|
||||
self.assertEqual(last_po_id.order_line.price_unit, 60)
|
||||
|
||||
def test_correct_supplier(self):
|
||||
self.env['stock.warehouse'].search([], limit=1).reception_steps = 'two_steps'
|
||||
product = self.env['product.product'].create({
|
||||
'name': 'Product',
|
||||
'route_ids': [(6, 0, [
|
||||
self.env.ref('purchase_stock.route_warehouse0_buy').id
|
||||
])],
|
||||
})
|
||||
partner_a, partner_b = self.env['res.partner'].create([
|
||||
{'name': "partner_a"},
|
||||
{'name': "partner_b"},
|
||||
])
|
||||
self.env['product.supplierinfo'].create([{
|
||||
'partner_id': partner_a.id,
|
||||
'product_id': product.id,
|
||||
'price': 1.0,
|
||||
}, {
|
||||
'partner_id': partner_b.id,
|
||||
'product_id': product.id,
|
||||
'price': 10.0,
|
||||
}, {
|
||||
'partner_id': partner_b.id,
|
||||
'product_id': product.id,
|
||||
'price': 100.0,
|
||||
}])
|
||||
|
||||
replenish_wizard = self.env['product.replenish'].create({
|
||||
'product_id': product.id,
|
||||
'product_tmpl_id': product.product_tmpl_id.id,
|
||||
'product_uom_id': self.uom_unit.id,
|
||||
'quantity': 1,
|
||||
'warehouse_id': self.wh.id,
|
||||
'route_id': self.env.ref('purchase_stock.route_warehouse0_buy').id,
|
||||
'supplier_id': product.seller_ids[2].id # partner_b price 100$
|
||||
})
|
||||
replenish_wizard.launch_replenishment()
|
||||
po = self.env['purchase.order'].search([
|
||||
('partner_id', '=', partner_b.id)
|
||||
])
|
||||
self.assertEqual(po.amount_untaxed, 10, "best price is 10$")
|
||||
|
||||
@@ -51,6 +51,7 @@ class ProductReplenish(models.TransientModel):
|
||||
res = super()._prepare_run_values()
|
||||
if self.supplier_id:
|
||||
res['supplierinfo_id'] = self.supplier_id
|
||||
res['group_id'].partner_id = self.supplier_id.partner_id
|
||||
return res
|
||||
|
||||
def action_stock_replenishment_info(self):
|
||||
|
||||
Reference in New Issue
Block a user