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

[13.0][FIX] account_cash_discount_write_off: use correct tags when using refunds #746

Open
wants to merge 2 commits into
base: 13.0
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions account_cash_discount_write_off/models/account_payment_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo import _, api, models
from odoo.exceptions import UserError
from odoo.tools import float_compare, float_is_zero, float_round

Expand Down Expand Up @@ -41,6 +41,11 @@ def _check_cash_discount_write_off_creation(self):
== 0
)

@api.model
def _get_tax_invoice_tax_percentage(self, tax_move_line):
tax_invoice = tax_move_line.move_id
return tax_invoice.discount_percent

def get_cash_discount_writeoff_move_values(self):
self.ensure_one()
move_line = self.move_line_id
Expand Down Expand Up @@ -99,9 +104,10 @@ def get_cash_discount_writeoff_move_values(self):
)

for tax_move_line in tax_move_lines:
tax_invoice = tax_move_line.move_id
amount = float_round(
abs(tax_move_line.balance) * tax_invoice.discount_percent / 100.0,
abs(tax_move_line.balance)
* self._get_tax_invoice_tax_percentage(tax_move_line)
/ 100.0,
precision_rounding=rounding,
)
if tax_move_line.credit > 0:
Expand All @@ -114,7 +120,7 @@ def get_cash_discount_writeoff_move_values(self):
tag_ids = []
if tax:
account = tax_move_line.account_id
is_refund = "refund" in tax_invoice.type
is_refund = "refund" in invoice.type
tax_vals = tax.compute_all(
tax_move_line.price_unit,
currency=tax_move_line.currency_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,48 @@ def test_cash_discount_with_write_off_with_taxes(self):
def test_cash_discount_with_refund(self):
woff_account = self.cash_discount_writeoff_account
woff_journal = self.cash_discount_writeoff_journal

expected_audit = "+II.D.1. for business purposes: base 17% (721)"
expected_refund_audit = "-II.D.1. for business purposes: base 17% (721)"

self.tax_17_p.invoice_repartition_line_ids.filtered(
lambda r: r.repartition_type == "tax"
).write(
{
"tag_ids": [
(
0,
False,
{
"name": expected_audit,
"applicability": "taxes",
"country_id": self.partner_agrolait.country_id.id,
},
)
],
"account_id": self.exp_account.id,
}
)

self.tax_17_p.refund_repartition_line_ids.filtered(
lambda r: r.repartition_type == "tax"
).write(
{
"tag_ids": [
(
0,
False,
{
"name": expected_refund_audit,
"applicability": "taxes",
"country_id": self.partner_agrolait.country_id.id,
},
)
],
"account_id": self.exp_account.id,
}
)

self.company.write(
{
"default_cash_discount_writeoff_account_id": woff_account.id,
Expand Down Expand Up @@ -292,3 +334,25 @@ def test_cash_discount_with_refund(self):
payment_order.generated2uploaded()

self.assertEqual(invoice.invoice_payment_state, "paid")

discount_writeoff_move_lines = self.MoveLine.search(
[("journal_id", "=", self.cash_discount_writeoff_journal.id)]
)

self.assertEqual(len(discount_writeoff_move_lines), 5)
tax_10_move_line = self.MoveLine.search(
[("id", "in", discount_writeoff_move_lines.ids), ("tag_ids", "!=", False)]
)

self.assertEqual(len(tax_10_move_line), 2)

credit_line = tax_10_move_line.filtered(lambda r: r.credit > 0)
self.assertEqual(len(credit_line), 1)
tag_credit = credit_line.tag_ids

debit_line = tax_10_move_line.filtered(lambda r: r.debit > 0)
self.assertEqual(len(debit_line), 1)
tag_debit = debit_line.tag_ids

self.assertEqual(tag_credit, tag_debit)
self.assertEqual(tag_credit.name, expected_audit)
Loading