Skip to content

Commit e55cd7d

Browse files
committed
[FIX] l10n_ar_tax: fix counterpart amount on own-check payments with withholdings
When paying a vendor with multiple own checks and withholding taxes, the counterpart (payable) line was being computed incorrectly: - The withholding reversal was applied only to liquidity_lines[0], which in the own-checks case holds the first check amount rather than a residual line, corrupting individual check balances. - As a result the move did not balance and Odoo added an automatic balancing line instead of cancelling the full supplier debt. Fix: detect the outbound own-checks multi-liquidity case and: 1. Apply the withholding reversal to the last (residual) liquidity line, leaving all other check lines untouched. 2. Recompute the counterpart balance directly from the sum of all liquidity + write-off + withholding lines, so the payable account always cancels the gross amount (net + withholdings). closes #1373 Signed-off-by: Felipe Garcia Suez <feg@adhoc.com.ar>
1 parent 12f4ea1 commit e55cd7d

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

l10n_ar_tax/models/account_payment.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ def _compute_payment_total(self):
9292
def _onchange_withholdings(self):
9393
# solo queremos re-computar en pagos de proveedor
9494
for rec in self.filtered(
95-
lambda x: x.partner_type == "supplier"
96-
and x.payment_method_code
97-
not in [
98-
"in_third_party_checks",
99-
"out_third_party_checks",
100-
"return_third_party_checks",
101-
"new_third_party_checks",
102-
]
95+
lambda x: (
96+
x.partner_type == "supplier"
97+
and x.payment_method_code
98+
not in [
99+
"in_third_party_checks",
100+
"out_third_party_checks",
101+
"return_third_party_checks",
102+
"new_third_party_checks",
103+
]
104+
)
103105
):
104106
# el compute_withholdings o el _compute_withholdings?
105107
amount = rec.amount + rec.payment_difference
@@ -229,11 +231,9 @@ def _prepare_move_withholding_lines(self, default_values):
229231

230232
def _prepare_move_lines_per_type(self, write_off_line_vals=None, force_balance=None):
231233
res = super()._prepare_move_lines_per_type(write_off_line_vals=write_off_line_vals, force_balance=force_balance)
232-
233234
# we adjust liquidity and counterpart lines because in ARG payment amount is already net of withholdings
234235
# whereas odoo expects it to be gross and subtracts withholdings from it.
235236
wth_lines = res.get("withholding_lines", [])
236-
237237
if wth_lines:
238238
wth_balance = sum(line["balance"] for line in wth_lines)
239239
# Suma directa de amount_currency de las líneas de retención. Cuando el pago es en moneda
@@ -257,16 +257,23 @@ def _prepare_move_lines_per_type(self, write_off_line_vals=None, force_balance=N
257257
has_forced_amount = bool(self.force_amount_company_currency)
258258

259259
liquidity_lines = res.get("liquidity_lines", [])
260+
own_checks_multiline = (
261+
self.payment_type == "outbound"
262+
and self.payment_method_code == "own_checks"
263+
and len(liquidity_lines) > 1
264+
)
260265
if liquidity_lines:
266+
target_line = liquidity_lines[-1] if own_checks_multiline else liquidity_lines[0]
261267
if not has_forced_amount:
262-
liquidity_lines[0]["balance"] += wth_balance
268+
target_line["balance"] += wth_balance
263269
# Revertimos el ajuste de amount_currency que hizo base Odoo (usó raw_wth_amount_currency
264270
# para restarlo de la liquidez).
265-
liquidity_lines[0]["amount_currency"] += raw_wth_amount_currency
271+
target_line["amount_currency"] += raw_wth_amount_currency
272+
266273
# if after adjustment the liquidity line is 0, we remove it
267274
# esto podria ir a payment_pro y que cualquier liquidity line en zero no se cree (Es para caso de
268275
# puro write off y/o solo retenciones)
269-
if self.company_currency_id.is_zero(liquidity_lines[0]["balance"]):
276+
if self.company_currency_id.is_zero(target_line["balance"]):
270277
res["liquidity_lines"] = []
271278
counterpart_lines = res.get("counterpart_lines", [])
272279
if counterpart_lines:
@@ -324,9 +331,11 @@ def _compute_withholding_warning(self):
324331
ya que todavía no tenemos implementado cálculos de retenciones ajustados por diferencia de cambio"""
325332
self.withholding_warning = False
326333
for rec in self.filtered(
327-
lambda x: x.state == "draft"
328-
and x.l10n_ar_withholding_line_ids
329-
and (x.currency_id != x.company_id.currency_id or x._use_counterpart_currency())
334+
lambda x: (
335+
x.state == "draft"
336+
and x.l10n_ar_withholding_line_ids
337+
and (x.currency_id != x.company_id.currency_id or x._use_counterpart_currency())
338+
)
330339
):
331340
# Verificar si la deuda está gestionada en moneda extranjera
332341
dest_currency = rec.destination_account_id.currency_id

0 commit comments

Comments
 (0)