Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][FIX] sale_fixed_discount: SOL discount propagation to invoice line #3150

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sale_fixed_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ def _convert_to_tax_base_line_dict(self, **kwargs):

return super()._convert_to_tax_base_line_dict()

@api.onchange("discount_fixed", "price_unit")
def _onchange_discount_fixed(self):
self.discount = self._get_discount_from_fixed_discount()
@api.depends("discount_fixed", "price_unit")
def _compute_discount(self):
lines_with_discount_fixed = self.filtered(lambda sol: sol.discount_fixed)
for line in lines_with_discount_fixed:
line.discount = line._get_discount_from_fixed_discount()
return super(SaleOrderLine, self - lines_with_discount_fixed)

def _get_discount_from_fixed_discount(self):
"""Calculate the discount percentage from the fixed discount amount."""
Expand Down
23 changes: 22 additions & 1 deletion sale_fixed_discount/tests/test_sale_fixed_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def test_02_fixed_discount_mismatch(self):
line.discount = 5.0

def test_03_fixed_discount_invoice(self):
"""Test discount_fixed value propagation to account.move"""
"""Test discount_fixed value propagation to account.move.
Case of editing order line by using UI.
"""
with Form(self.sale) as sale_order:
with sale_order.order_line.edit(0) as line:
line.discount_fixed = 20.0
Expand All @@ -102,6 +104,10 @@ def test_03_fixed_discount_invoice(self):
self.sale._create_invoices()

self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0)
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0)

self.assertEqual(self.sale.invoice_ids.tax_totals["amount_untaxed"], 180.0)
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_total"], 207.0)

def test_04_fixed_discount_without_price(self):
with Form(self.sale) as sale_order:
Expand All @@ -112,3 +118,18 @@ def test_04_fixed_discount_without_price(self):
self.assertEqual(line.discount, 0.0)
self.assertEqual(line.price_subtotal, 0.0)
self.assertEqual(self.sale.amount_total, 0.0)

def test_05_fixed_discount_invoice(self):
"""Test discount_fixed value propagation to account.move.
Case of editing order line without using UI (onchange would be not triggered).
"""
self.sale.order_line.discount_fixed = 20.0

self.sale.action_confirm()
self.sale._create_invoices()

self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0)
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0)

self.assertEqual(self.sale.invoice_ids.tax_totals["amount_untaxed"], 180.0)
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_total"], 207.0)
Loading