From 3e73ebcf2fa65f83c0543c2252faff39550f6e46 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Mon, 25 Sep 2023 12:57:12 +0200 Subject: [PATCH] [FIX] purchase_discount: Don't call _select_seller without product --- purchase_discount/models/purchase_order.py | 2 +- .../tests/test_purchase_discount.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/purchase_discount/models/purchase_order.py b/purchase_discount/models/purchase_order.py index 78db6ecaa48..e502da8d6c0 100644 --- a/purchase_discount/models/purchase_order.py +++ b/purchase_discount/models/purchase_order.py @@ -88,7 +88,7 @@ def _compute_price_unit_and_date_planned_and_name(self): selected one. """ res = super()._compute_price_unit_and_date_planned_and_name() - for line in self: + for line in self.filtered("product_id"): seller = line.product_id._select_seller( partner_id=line.partner_id, quantity=line.product_qty, diff --git a/purchase_discount/tests/test_purchase_discount.py b/purchase_discount/tests/test_purchase_discount.py index 1bdae8b82fe..c17c2ae0027 100644 --- a/purchase_discount/tests/test_purchase_discount.py +++ b/purchase_discount/tests/test_purchase_discount.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields -from odoo.tests.common import TransactionCase +from odoo.tests.common import Form, TransactionCase class TestPurchaseOrder(TransactionCase): @@ -108,6 +108,15 @@ def setUpClass(cls): "price_unit": 10.0, } ) + cls.po_line_4 = po_model.create( + { + "order_id": cls.purchase_order.id, + "display_type": "line_section", + "name": "Test Section", + "product_qty": 0.0, + "product_uom_qty": 0.0, + } + ) def test_purchase_order_vals(self): self.assertEqual(self.po_line_1.price_subtotal, 5.0) @@ -169,6 +178,12 @@ def test_report_price_unit(self): self.assertEqual(rec.price_total, 5) self.assertEqual(rec.discount, 50) + def test_no_product(self): + purchase_form = Form(self.purchase_order) + with purchase_form.order_line.edit(3) as line: + line.product_qty = 0.0 + self.assertEqual(self.po_line_4.discount, 0.0) + def test_invoice(self): invoice = self.env["account.move"].new( {