Skip to content

Commit

Permalink
[FIX] purchase_discount: Don't call _select_seller without product
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed Sep 25, 2023
1 parent 5eee66b commit 3e73ebc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion purchase_discount/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion purchase_discount/tests/test_purchase_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
{
Expand Down

0 comments on commit 3e73ebc

Please sign in to comment.