Skip to content

Commit

Permalink
[FIX] l10n_it_withholding_tax: Do not generate WT moves and amount du…
Browse files Browse the repository at this point in the history
…ring refund
  • Loading branch information
eLBati committed Apr 2, 2024
1 parent 5b2b00b commit 2f69aeb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
11 changes: 10 additions & 1 deletion l10n_it_withholding_tax/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ def create(self, vals_list):
paying_invoice = move_lines.filtered(lambda x: x.exists()).move_id.filtered(
lambda x: x.is_invoice()
)

# If we are reconciling a vendor bill and its refund,
# we do not need to generate Withholding Tax Moves
# or change the reconciliation amount
in_refunding = len(paying_invoice) == 2 and set(
paying_invoice.mapped("move_type")
) == {"in_invoice", "in_refund"}
# XXX
# the following code mimics 12.0 behaviour; probably it's not correct
if paying_invoice:
if not in_refunding:
paying_invoice = first(paying_invoice)
else:
paying_invoice = self.env["account.move"].browse()

# Limit value of reconciliation
if (
Expand Down
46 changes: 46 additions & 0 deletions l10n_it_withholding_tax/tests/test_withholding_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,49 @@ def test_refund_wt_propagation(self):

# Assert: The refund has the Withholding Tax flag enabled
self.assertTrue(refund.withholding_tax)

def test_refund_reconciliation_amount(self):
"""
When a refund is created, the amount reconciled
is the whole amount of the vendor bill.
"""
# Arrange: Create a bill
bill = self._create_bill()
bill_amount = bill.amount_total

# Act: Create a refund
refund = self._get_refund(bill)

# Assert: The reconciliation is for the whole bill
reconciliation = self.env["account.partial.reconcile"].search(
[
("debit_move_id", "in", refund.move_id.line_ids.ids),
("credit_move_id", "in", bill.move_id.line_ids.ids),
]
)
self.assertEqual(reconciliation.amount, bill_amount)

def test_refund_wt_moves(self):
"""
When a refund is created,
no Withholding Tax Moves are created.
"""
# Arrange: Create a bill
bill = self._create_bill()

# Act: Create a refund
refund = self._get_refund(bill)

# Assert: There are no Withholding Tax Moves
reconciliation = self.env["account.partial.reconcile"].search(
[
("debit_move_id", "in", refund.move_id.line_ids.ids),
("credit_move_id", "in", bill.move_id.line_ids.ids),
]
)
withholding_tax_moves = self.env["withholding.tax.move"].search(
[
("reconcile_partial_id", "=", reconciliation.id),
]
)
self.assertFalse(withholding_tax_moves)

0 comments on commit 2f69aeb

Please sign in to comment.