From c6f3ab2d41b3a2db3c244157c17dba3efd17149d Mon Sep 17 00:00:00 2001 From: Walid Date: Fri, 22 Mar 2024 11:59:20 +0100 Subject: [PATCH] [FIX] purchase: fallback to standard price if no pricelist Steps to reproduce: - Create pricelist with an end date in the past for a stored product - Click on manual replenishement - The created PO will have a price of 0 Bug: if no valid pricelist is found unit price is set to 0 product standard price is a better fallback opw-3692985 closes odoo/odoo#158650 X-original-commit: ed106e70f908deda819007fc68feaa44074c0472 Signed-off-by: William Henrotin (whe) Signed-off-by: Walid Hanniche (waha) --- addons/purchase/models/purchase_order_line.py | 3 +- .../tests/test_replenish_wizard.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/purchase_order_line.py b/addons/purchase/models/purchase_order_line.py index 17b0d5ba4f7..45d0fd86971 100644 --- a/addons/purchase/models/purchase_order_line.py +++ b/addons/purchase/models/purchase_order_line.py @@ -594,8 +594,9 @@ class PurchaseOrderLine(models.Model): product_taxes = product_id.supplier_taxes_id.filtered(lambda x: x.company_id.id == company_id.id) taxes = po.fiscal_position_id.map_tax(product_taxes) + price_unit = seller.price if seller else product_id.standard_price price_unit = self.env['account.tax']._fix_tax_included_price_company( - seller.price, product_taxes, taxes, company_id) if seller else 0.0 + price_unit, product_taxes, taxes, company_id) if price_unit and seller and po.currency_id and seller.currency_id != po.currency_id: price_unit = seller.currency_id._convert( price_unit, po.currency_id, po.company_id, po.date_order or fields.Date.today()) diff --git a/addons/purchase_stock/tests/test_replenish_wizard.py b/addons/purchase_stock/tests/test_replenish_wizard.py index 8e561fcb204..73e8b4a45a2 100644 --- a/addons/purchase_stock/tests/test_replenish_wizard.py +++ b/addons/purchase_stock/tests/test_replenish_wizard.py @@ -417,3 +417,37 @@ class TestReplenishWizard(TestStockCommon): }) wizard.supplier_id = supplier self.assertEqual(fields.Datetime.from_string('2023-01-08 00:00:00'), wizard.date_planned) + + def test_unit_price_expired_price_list(self): + vendor = self.env['res.partner'].create({ + 'name': 'Contact', + 'type': 'contact', + }) + product = self.env['product.product'].create({ + 'name': 'Product', + 'standard_price': 60, + 'seller_ids': [(0, 0, { + 'partner_id': vendor.id, + 'price': 1.0, + 'date_end': '2019-01-01', + })], + 'route_ids': [(6, 0, [ + self.env.ref('purchase_stock.route_warehouse0_buy').id + ])], + }) + + 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 + }) + replenish_wizard.launch_replenishment() + last_po_id = self.env['purchase.order'].search([ + ('origin', 'ilike', '%Manual Replenishment%'), + ])[-1] + + self.assertEqual(last_po_id.partner_id, vendor) + self.assertEqual(last_po_id.order_line.price_unit, 60)