diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 4965db73158ebabfbf98b49f152979750c5aeefe..2237a985de3ed0e72e67495e3e0fa26e05822e02 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1413,7 +1413,7 @@ class PurchaseOrderLine(models.Model): seller = product_id.with_company(company_id)._select_seller( partner_id=partner, 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) product_taxes = product_id.supplier_taxes_id.filtered(lambda x: x.company_id.id == company_id.id) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 6fb77d51d7d0463ed6f1749b8ad7c38e1af3798d..07990b6b2edd119ffdaca73f9d0c419cdcbf5eba 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -62,7 +62,7 @@ class StockRule(models.Model): supplier = procurement.product_id.with_company(procurement.company_id.id)._select_seller( partner_id=procurement.values.get("supplierinfo_name"), quantity=procurement.product_qty, - date=procurement_date_planned.date(), + date=max(procurement_date_planned.date(), fields.Date.today()), uom_id=procurement.product_uom) # Fall back on a supplier for which no price may be defined. Not ideal, but better than diff --git a/addons/sale_purchase_stock/tests/test_lead_time.py b/addons/sale_purchase_stock/tests/test_lead_time.py new file mode 100644 index 0000000000000000000000000000000000000000..c29bf843fee5b499005454b9bb94fd44bf2dc2ba --- /dev/null +++ b/addons/sale_purchase_stock/tests/test_lead_time.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import timedelta + +from odoo import fields +from odoo.tests import tagged +from odoo.addons.sale_purchase.tests.common import TestCommonSalePurchaseNoChart + + +@tagged('post_install', '-at_install') +class TestLeadTime(TestCommonSalePurchaseNoChart): + + @classmethod + def setUpClass(cls): + super(TestLeadTime, cls).setUpClass() + + cls.buy_route = cls.env.ref('purchase_stock.route_warehouse0_buy') + cls.mto_route = cls.env.ref('stock.route_warehouse0_mto') + cls.mto_route.active = True + cls.vendor = cls.env['res.partner'].create({'name': 'The Emperor'}) + cls.user_salesperson = cls.env['res.users'].with_context(no_reset_password=True).create({ + 'name': 'Le Grand Horus', + 'login': 'grand.horus', + 'email': 'grand.horus@chansonbelge.dz', + }) + + + def test_supplier_lead_time(self): + """ 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({ + 'name': self.vendor.id, + 'min_qty': 1, + 'price': 10, + 'date_start': fields.Date.today() - timedelta(days=1), + }) + + product = self.env['product.product'].create({ + 'name': 'corpse starch', + 'type': 'product', + 'seller_ids': [(6, 0, seller.ids)], + 'route_ids': [(6, 0, (self.mto_route + self.buy_route).ids)], + }) + + so = self.env['sale.order'].with_user(self.user_salesperson).create({ + 'partner_id': self.partner_a.id, + 'user_id': self.user_salesperson.id, + }) + self.env['sale.order.line'].create({ + 'name': product.name, + 'product_id': product.id, + 'product_uom_qty': 1, + 'product_uom': product.uom_id.id, + 'price_unit': product.list_price, + 'tax_id': False, + 'order_id': so.id, + }) + so.action_confirm() + + po = self.env['purchase.order'].search([('partner_id', '=', self.vendor.id)]) + self.assertEqual(po.order_line.price_unit, seller.price)