-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
[14.0][IMP]Account_invoice_triple_discount: For in invoice_line_ids and not in line_ids #1442
Changes from 4 commits
18e8df2
e90c53f
d25a872
69c4fdf
c6e7391
7fc2600
9a26232
10df6db
43cf80b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,25 @@ def setUpClass(cls): | |
) | ||
cls.sale_journal = cls.Journal.search([("type", "=", "sale")], limit=1) | ||
|
||
@classmethod | ||
def _create_refund(cls, tax=False, date=False, in_type=False): | ||
odooNextev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
refund_form = Form( | ||
cls.env["account.move"].with_context(default_move_type="in_refund") | ||
) | ||
# refund_form.partner_id = partner | ||
odooNextev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
refund_form.name = "Test Refund for Triple Discount" | ||
|
||
with refund_form.invoice_line_ids.new() as refund_line: | ||
refund_line.quantity = 1.00 | ||
refund_line.name = "test refund line" | ||
refund_line.price_unit = 100.00 | ||
if tax: | ||
refund_line.tax_ids.clear() | ||
refund_line.tax_ids.add(tax) | ||
|
||
refund = refund_form.save() | ||
return refund | ||
|
||
def create_simple_invoice(self, amount): | ||
invoice_form = Form( | ||
self.AccountMove.with_context( | ||
|
@@ -164,3 +183,26 @@ def test_04_discounts_decimals_tax(self): | |
invoice_form.save() | ||
|
||
self.assertEqual(invoice.amount_tax, 177.61) | ||
|
||
def test_05_refund_negative_taxes(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this locally and this test is passing even without the changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SirTakobi now I fixed this test and without our fix in _recompute_tax_lines it fails There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||
""" | ||
Tests refund negative taxes | ||
""" | ||
invoice = self._create_refund(0) | ||
invoice_form = Form(invoice) | ||
|
||
with invoice_form.invoice_line_ids.edit(0) as line_form: | ||
line_form.name = "Negative amounts" | ||
line_form.quantity = 10 | ||
line_form.price_unit = -2.00 | ||
invoice_form.save() | ||
for line in invoice.line_ids: | ||
line.with_context(check_move_validity=False).update( | ||
{"price_unit": -line.price_unit} | ||
) | ||
invoice.with_context(check_move_validity=False)._recompute_dynamic_lines( | ||
recompute_all_taxes=True, | ||
) | ||
invoice._check_balanced() | ||
self.assertEqual(invoice.move_type, "in_refund") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, editing the invoice with I tried this locally and here the
I know this is only the test and you are not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SirTakobi Thanks for your review. I tried to add a test to replace behavior of l10n_it_fatturapa if there are some negative lines https://github.com/OCA/l10n-italy/blob/14.0/l10n_it_fatturapa_in/models/account.py#L321. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SirTakobi I made some changes and now the invoice is balanced. Could you please check if everything look good to you? Thanks |
||
self.assertEqual(round(invoice.amount_total, 2), 23.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test, now I can check what is going wrong.
As you suggested, for some reason the sign of
price_unit
of the tax line is changed when calling https://github.com/odoo/odoo/blob/5a3a8d0b1fcc982f813ca77f744a0612abbe7b94/addons/account/models/account_move.py#L602; the method itself is not very clear to me, but the actual switch might be happening in https://github.com/odoo/odoo/blob/5a3a8d0b1fcc982f813ca77f744a0612abbe7b94/addons/account/models/account_move.py#L628.Apparently the module is trying to manage adding multiple discounts on the tax lines but we can skip them, and we probably should also because multiple discounts can only be assigned on invoice lines (not tax lines) from the UI.
Another fix might be to only edit the lines that we have to: for instance skip the lines that have no
aggregated_discount
because for those lines the module is only writing the sameprice_unit
anddiscount
after callingsuper
, that is not very useful