Skip to content
Snippets Groups Projects
Commit c88fd161 authored by William Henrotin's avatar William Henrotin
Browse files

[FIX] {sale_}purchase{_stock}: select sellers depending on date


Commit 72a17baf force the PO `date_order` to be >= at ` today() to
ensure the select_seller method take the right seller price. This
introduces an error in the MPS module that may need to create PO in the
past.

Instead, this commit patch the call to `_select_seller` to take at least
`today()`

closes odoo/odoo#133759

Opw: 3167094
Related: odoo/enterprise#46623
Signed-off-by: default avatarArnold Moyaux (arm) <arm@odoo.com>
parent 10ad2506
No related branches found
No related tags found
No related merge requests found
...@@ -1223,7 +1223,7 @@ class PurchaseOrderLine(models.Model): ...@@ -1223,7 +1223,7 @@ class PurchaseOrderLine(models.Model):
seller = product_id.with_company(company_id)._select_seller( seller = product_id.with_company(company_id)._select_seller(
partner_id=partner, partner_id=partner,
quantity=uom_po_qty, quantity=uom_po_qty,
date=po.date_order and po.date_order.date(), date=max(po.date_order and po.date_order.date(), fields.Date.today()),
uom_id=product_id.uom_po_id) uom_id=product_id.uom_po_id)
taxes = product_id.supplier_taxes_id taxes = product_id.supplier_taxes_id
......
...@@ -60,7 +60,7 @@ class StockRule(models.Model): ...@@ -60,7 +60,7 @@ class StockRule(models.Model):
supplier = procurement.product_id.with_company(procurement.company_id.id)._select_seller( 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"),
quantity=procurement.product_qty, quantity=procurement.product_qty,
date=schedule_date.date(), date=max(schedule_date.date(), fields.Date.today()),
uom_id=procurement.product_uom) uom_id=procurement.product_uom)
# Fall back on a supplier for which no price may be defined. Not ideal, but better than # Fall back on a supplier for which no price may be defined. Not ideal, but better than
...@@ -259,17 +259,16 @@ class StockRule(models.Model): ...@@ -259,17 +259,16 @@ class StockRule(models.Model):
res['orderpoint_id'] = orderpoint_id.id res['orderpoint_id'] = orderpoint_id.id
return res return res
def _get_po_date(self, company_id, values):
purchase_date = min([fields.Datetime.from_string(value['date_planned']) - relativedelta(days=int(value['supplier'].delay)) for value in values])
return purchase_date - relativedelta(days=company_id.po_lead)
def _prepare_purchase_order(self, company_id, origins, values): def _prepare_purchase_order(self, company_id, origins, values):
""" Create a purchase order for procuremets that share the same domain """ Create a purchase order for procuremets that share the same domain
returned by _make_po_get_domain. returned by _make_po_get_domain.
params values: values of procurements params values: values of procurements
params origins: procuremets origins to write on the PO params origins: procuremets origins to write on the PO
""" """
purchase_date = max(self._get_po_date(company_id, values), fields.Datetime.now()) purchase_date = min([fields.Datetime.from_string(value['date_planned']) - relativedelta(days=int(value['supplier'].delay)) for value in values])
purchase_date = (purchase_date - relativedelta(days=company_id.po_lead))
# Since the procurements are grouped if they share the same domain for # Since the procurements are grouped if they share the same domain for
# PO but the PO does not exist. In this case it will create the PO from # PO but the PO does not exist. In this case it will create the PO from
......
...@@ -361,5 +361,5 @@ class TestPurchaseLeadTime(PurchaseTestCommon): ...@@ -361,5 +361,5 @@ class TestPurchaseLeadTime(PurchaseTestCommon):
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.partner_1.id)]) purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.partner_1.id)])
today = fields.Datetime.start_of(fields.Datetime.now(), 'day') today = fields.Datetime.start_of(fields.Datetime.now(), 'day')
self.assertEqual(fields.Datetime.start_of(purchase_order.date_order, 'day'), today) self.assertEqual(purchase_order.date_order, today)
self.assertEqual(fields.Datetime.start_of(purchase_order.date_planned, 'day'), today + timedelta(days=7)) self.assertEqual(fields.Datetime.start_of(purchase_order.date_planned, 'day'), today + timedelta(days=7))
...@@ -29,18 +29,19 @@ class TestLeadTime(TestCommonSalePurchaseNoChart): ...@@ -29,18 +29,19 @@ class TestLeadTime(TestCommonSalePurchaseNoChart):
def test_supplier_lead_time(self): def test_supplier_lead_time(self):
""" Basic stock configuration and a supplier with a minimum qty and a lead time """ """ Basic stock configuration and a supplier with a minimum qty and a lead time """
self.env.user.company_id.po_lead = 7
seller = self.env['product.supplierinfo'].create({ seller = self.env['product.supplierinfo'].create({
'name': self.vendor.id, 'name': self.vendor.id,
'min_qty': 1, 'min_qty': 1,
'price': 1, 'price': 10,
'delay': 7, 'date_start': fields.Date.today() - timedelta(days=1),
}) })
product = self.env['product.product'].create({ product = self.env['product.product'].create({
'name': 'corpse starch', 'name': 'corpse starch',
'type': 'product', 'type': 'product',
'seller_ids': [(6, 0, seller.ids)], 'seller_ids': [(6, 0, seller.ids)],
'route_ids': [(6, 0, (self.mto_route + self.buy_route).ids)] 'route_ids': [(6, 0, (self.mto_route + self.buy_route).ids)],
}) })
so = self.env['sale.order'].with_user(self.user_salesperson).create({ so = self.env['sale.order'].with_user(self.user_salesperson).create({
...@@ -59,9 +60,4 @@ class TestLeadTime(TestCommonSalePurchaseNoChart): ...@@ -59,9 +60,4 @@ class TestLeadTime(TestCommonSalePurchaseNoChart):
so.action_confirm() so.action_confirm()
po = self.env['purchase.order'].search([('partner_id', '=', self.vendor.id)]) po = self.env['purchase.order'].search([('partner_id', '=', self.vendor.id)])
self.assertEqual(po.order_line.price_unit, seller.price)
start_of_day = lambda x: fields.Datetime.start_of(x, 'day')
today = start_of_day(fields.Datetime.now())
self.assertEqual(start_of_day(po.date_order), today)
self.assertEqual(start_of_day(po.date_planned), today + timedelta(days=7))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment