[FIX] {sale_}purchase{_stock}: select sellers depending on date
Commit 72a17bafba6e7 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#134217 Opw: 3167094 X-original-commit: a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com> Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -1402,7 +1402,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user