[FIX] product,purchase_stock: get correct supplier for lead days

Resupplying a product with a purchase order ask to choose the suitable
supplier to put on the purchase order. Another search is perform on top
of that to compute de date to order in order to respect the lead days
promise by the supplier. The issue is that the first search is done with
the orderpoint company into account but not the second one.

This commit passes the company to _select_seller when computing the total
lead days required for an order.

opw : 2557125

closes odoo/odoo#72466

X-original-commit: c1bd985ef6a77c8848c4a2a8b92508511d9d8638
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2021-06-21 16:06:12 +00:00
parent 7ac3a391a1
commit 64df3f8d09
2 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ class StockRule(models.Model):
delay, delay_description = super()._get_lead_days(product)
bypass_delay_description = self.env.context.get('bypass_delay_description')
buy_rule = self.filtered(lambda r: r.action == 'buy')
seller = product._prepare_sellers()
seller = product.with_company(buy_rule.company_id)._select_seller()
if not buy_rule or not seller:
return delay, delay_description
buy_rule.ensure_one()
@@ -273,6 +273,9 @@ class TestPurchaseLeadTime(PurchaseTestCommon):
def test_reordering_days_to_purchase(self):
company = self.env.ref('base.main_company')
company2 = self.env['res.company'].create({
'name': 'Second Company',
})
company.write({'po_lead': 0.00})
self.patcher = patch('odoo.addons.stock.models.stock_orderpoint.fields.Date', wraps=fields.Date)
self.mock_date = self.patcher.start()
@@ -280,19 +283,30 @@ class TestPurchaseLeadTime(PurchaseTestCommon):
vendor = self.env['res.partner'].create({
'name': 'Colruyt'
})
vendor2 = self.env['res.partner'].create({
'name': 'Delhaize'
})
self.env.company.days_to_purchase = 2.0
product = self.env['product.product'].create({
'name': 'Chicory',
'type': 'product',
'seller_ids': [(0, 0, {'name': vendor.id, 'delay': 1.0})]
'seller_ids': [
(0, 0, {'name': vendor2.id, 'delay': 15.0, 'company_id': company2.id}),
(0, 0, {'name': vendor.id, 'delay': 1.0, 'company_id': company.id})
]
})
orderpoint_form = Form(self.env['stock.warehouse.orderpoint'])
orderpoint_form.product_id = product
orderpoint_form.product_min_qty = 0.0
orderpoint = orderpoint_form.save()
orderpoint_form = Form(self.env['stock.warehouse.orderpoint'].with_company(company2))
orderpoint_form.product_id = product
orderpoint_form.product_min_qty = 0.0
orderpoint = orderpoint_form.save()
warehouse = self.env['stock.warehouse'].search([], limit=1)
delivery_moves = self.env['stock.move']
for i in range(0, 6):