Skip to content

Commit 29d01c7

Browse files
committed
[FIX] sale: correct fixed taxes with early payment discount
Issue: The fixed tax value is doubled in `sale` when an early payment discount is applied. Steps to reproduce: - Create a fixed tax of $20 for example - Create a payment term with an early discount of 10% if paid before 10 days - Select "Always (upon invoice)" - In Sale create a new quotation with a line of $100 and the fixed tax - Select the created payment term - The tax value is doubled ($40) Cause: To compute the payment terms `_add_base_lines_for_early_payment_discount` (added in this [commit](odoo@781678f)) is adding two lines: - one with the negative amount of the payment term and the taxes - one with the positive amount of the payment term The goal is to compute the taxes on the discounted untaxed amount of the line. The original line compute the taxes for the undiscounted amount. The first added line computes the taxes for the amount of the discount and is negative. When adding the two the result is the tax value computed from the discounted untaxed amount. The issue is that a fixed will always have the same value, this means that the tax amount of the first added line will be positive and the same as the original line. When adding the two the amount is doubled. Solution: We don't add taxes with fixed amount on the first add line. opw-4868011 closes odoo#220657 X-original-commit: 90423ef Signed-off-by: Laurent Smet (las) <las@odoo.com> Signed-off-by: Mathieu Coutant (mcou) <mcou@odoo.com>
1 parent ff569b5 commit 29d01c7

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

addons/sale/models/sale_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _add_base_lines_for_early_payment_discount(self):
534534
currency_id=currency,
535535
sign=1,
536536
special_type='early_payment',
537-
tax_ids=line.tax_ids,
537+
tax_ids=line.tax_ids.flatten_taxes_hierarchy().filtered(lambda tax: tax.amount_type != 'fixed'),
538538
))
539539
epd_lines.append(self.env['account.tax']._prepare_base_line_for_taxes_computation(
540540
record=self,

addons/sale/tests/test_taxes_tax_totals_summary.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,86 @@ def test_apply_mixed_epd_discount(self):
136136
},
137137
soft_checking=True,
138138
)
139+
140+
def test_apply_mixed_epd_discount_fixed_tax(self):
141+
"""
142+
When applying an epd - mixed payment term, the fixed tax amount should be the same.
143+
"""
144+
tax_a = self.fixed_tax(20.0)
145+
early_payment_term = self.env['account.payment.term'].create({
146+
'name': "early_payment_term",
147+
'early_pay_discount_computation': 'mixed',
148+
'discount_percentage': 10,
149+
'discount_days': 10,
150+
'early_discount': True,
151+
'line_ids': [
152+
Command.create({
153+
'value': 'percent',
154+
'value_amount': 100,
155+
'nb_days': 20,
156+
}),
157+
],
158+
})
159+
160+
sale_order = self.env['sale.order'].create({
161+
'partner_id': self.partner.id,
162+
'payment_term_id': early_payment_term.id,
163+
'order_line': [
164+
Command.create({
165+
'product_id': self.product.id,
166+
'price_unit': 100,
167+
'tax_ids': [Command.set(tax_a.ids)],
168+
}),
169+
],
170+
})
171+
self.assert_sale_order_tax_totals_summary(
172+
sale_order,
173+
{
174+
'base_amount_currency': 100.0,
175+
'tax_amount_currency': 20.0,
176+
'total_amount_currency': 120.0,
177+
},
178+
soft_checking=True,
179+
)
180+
181+
def test_apply_mixed_epd_discount_percent_and_fixed_tax(self):
182+
"""
183+
When applying an epd - mixed payment term, the percent tax should be computed based on the discounted untaxed amount.
184+
"""
185+
tax_a = self.percent_tax(15.0)
186+
tax_b = self.fixed_tax(20.0)
187+
early_payment_term = self.env['account.payment.term'].create({
188+
'name': "early_payment_term",
189+
'early_pay_discount_computation': 'mixed',
190+
'discount_percentage': 10,
191+
'discount_days': 10,
192+
'early_discount': True,
193+
'line_ids': [
194+
Command.create({
195+
'value': 'percent',
196+
'value_amount': 100,
197+
'nb_days': 20,
198+
}),
199+
],
200+
})
201+
202+
sale_order = self.env['sale.order'].create({
203+
'partner_id': self.partner.id,
204+
'payment_term_id': early_payment_term.id,
205+
'order_line': [
206+
Command.create({
207+
'product_id': self.product.id,
208+
'price_unit': 100,
209+
'tax_ids': [Command.set((tax_a + tax_b).ids)],
210+
}),
211+
],
212+
})
213+
self.assert_sale_order_tax_totals_summary(
214+
sale_order,
215+
{
216+
'base_amount_currency': 100.0,
217+
'tax_amount_currency': 33.5,
218+
'total_amount_currency': 133.5,
219+
},
220+
soft_checking=True,
221+
)

0 commit comments

Comments
 (0)