From 87f3e99335148dec96405754da802de5f5261f65 Mon Sep 17 00:00:00 2001 From: Walid Date: Fri, 15 Mar 2024 15:00:15 +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#157860 X-original-commit: 5b255d9f4a9ddcada49da7603cc26d95b8c05a9d Signed-off-by: William Henrotin (whe) Signed-off-by: Walid Hanniche (waha) --- addons/purchase/models/purchase.py | 3 +- .../tests/test_replenish_wizard.py | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 025d2fe50bc6a..978f2fa50857f 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1448,8 +1448,9 @@ def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, com 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 7ed82d33bb9fb..2f947af09e90a 100644 --- a/addons/purchase_stock/tests/test_replenish_wizard.py +++ b/addons/purchase_stock/tests/test_replenish_wizard.py @@ -248,3 +248,33 @@ def test_chose_supplier_4(self): self.assertEqual(last_po_id.partner_id, vendor1) self.assertEqual(last_po_id.order_line.price_unit, 60) + + 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', + })] + }) + + 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, + }) + 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)