Skip to content

Commit e630593

Browse files
[IMP] l10n_ar_tax: revert withholding rounding patch and improve calculation
Revertimos el cambio de este pull request #1218 y mejoramos cálculo de retención tal como lo hizo odoo aquí odoo/odoo@ac521b2#diff-dab181eb3722c2603ab3586daa152293cfa7b98bdccc7bd7508eec8062de67d9R71 Ticket: 101778
1 parent 3de8064 commit e630593

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

l10n_ar_tax/models/l10n_ar_payment_withholding.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ def _tax_compute_all_helper(self):
103103
product=False,
104104
partner=False,
105105
is_refund=False,
106+
rounding_method="round_per_line",
106107
)
107-
tax_amount = self.currency_id.round(taxes_res["total_included"] - taxes_res["total_excluded"])
108-
# TODO: When Odoo fixes the compute_all method of account_tax, uncomment the line below and
109-
# remove the line above. See Adhoc ticket 101778 for more information.
110-
# tax_amount = taxes_res["taxes"][0]["amount"]
108+
tax_amount = taxes_res["taxes"][0]["amount"]
111109
tax_account_id = taxes_res["taxes"][0]["account_id"]
112110
tax_repartition_line_id = taxes_res["taxes"][0]["tax_repartition_line_id"]
113111

l10n_ar_tax/tests/test_payment_receiptbook_and_withholding.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,79 @@ def test_create_vendor_payment_with_receiptbook_and_withholdings(self):
371371
{"debit": 655000.0, "credit": 0.0, "amount_currency": 655000.0},
372372
],
373373
)
374+
375+
def test_withholding_amounts(self):
376+
"""Verify withholding amount precision under 'round_globally' rounding method.
377+
378+
With price_unit=391683 and a 4.5% withholding tax, the exact amount is
379+
391683 * 0.045 = 17625.735. Under 'round_globally', this rounds to 17625.74.
380+
The test ensures the rounding method is respected and the resulting
381+
withholding line carries the correctly rounded amount_currency.
382+
"""
383+
company = self.company_ri
384+
previous_rounding_method = company.tax_calculation_rounding_method
385+
company.tax_calculation_rounding_method = "round_globally"
386+
try:
387+
# Create a vendor bill with a single line subject to 21% VAT
388+
in_invoice_wht = self.env["account.move"].create(
389+
{
390+
"move_type": "in_invoice",
391+
"company_id": company.id,
392+
"invoice_date": self.today,
393+
"partner_id": self.env.ref("l10n_ar_tax.res_partner_adhoc_caba").id,
394+
"invoice_line_ids": [
395+
Command.create(
396+
{
397+
"product_id": self.product_a.id,
398+
"price_unit": 391683,
399+
"tax_ids": [Command.set(self.tax_21.ids)],
400+
}
401+
)
402+
],
403+
"l10n_latam_document_number": "2-5",
404+
}
405+
)
406+
in_invoice_wht.action_post()
407+
408+
# Set withholding tax rate to 4.5% (produces a non-trivial rounding case)
409+
self.tax_wth_test_1.write({"amount": 4.5})
410+
411+
# Create fiscal position with withholding for CABA partner
412+
fiscal_pos = self.env["account.fiscal.position"].create(
413+
{
414+
"name": "IIBB CABA Rounding",
415+
"l10n_ar_afip_responsibility_type_ids": [(6, 0, [self.env.ref("l10n_ar.res_IVARI").id])],
416+
"sequence": 10,
417+
"auto_apply": True,
418+
"country_id": self.env.ref("base.ar").id,
419+
"company_id": company.id,
420+
"state_ids": [(6, 0, [self.env.ref("base.state_ar_c").id])],
421+
}
422+
)
423+
self.env["account.fiscal.position.l10n_ar_tax"].create(
424+
{
425+
"fiscal_position_id": fiscal_pos.id,
426+
"default_tax_id": self.tax_wth_test_1.id,
427+
"tax_type": "withholding",
428+
}
429+
)
430+
431+
# Create payment using register payment context
432+
action_context = in_invoice_wht.action_register_payment()["context"]
433+
vals = {
434+
"journal_id": self.company_bank_journal.id,
435+
"amount": in_invoice_wht.amount_total,
436+
"date": self.today,
437+
}
438+
payment = self.env["account.payment"].with_context(**action_context).create(vals)
439+
440+
# In direct payment creation flow, amount must be net of withholdings to fully reconcile the invoice.
441+
payment.action_post()
442+
443+
self.assertEqual(payment.company_id.tax_calculation_rounding_method, "round_globally")
444+
# 391683 * 21% = 82253.43 (VAT) -> total invoice: 473936.43
445+
# 391683 * 4.5% = 17625.735 -> rounded globally to 17625.74 (withholding)
446+
# net payment (liquidity): 473936.43 - 17625.74 = 456310.69
447+
self.assertEqual(payment.l10n_ar_withholding_line_ids.amount_currency, 17625.74)
448+
finally:
449+
company.tax_calculation_rounding_method = previous_rounding_method

0 commit comments

Comments
 (0)