From 3a95eb4fae02316ff1cd2c133bfedeaca3be68b2 Mon Sep 17 00:00:00 2001 From: Guillermo Rojo Date: Wed, 30 Sep 2026 16:15:38 +0200 Subject: [PATCH] [OU-FIX] l10n_es: keep the accounts of group taxes Up to 12.0 the reverse charge and intra-community purchase taxes of l10n_es are group taxes: the group holds no account, and its two children hold 472 and 477. The repartition lines created for each group took their account from the group itself, so the tax lines were left without one, and a bill posted after the migration put both tax amounts on the expense account of its line. Give each tax repartition line of the group the account of its child's one, matched by repartition type and sign, as the move lines are matched to their repartition line a few lines below. Assisted-by: Claude Opus 5.5 --- .../migrations/13.0.4.0/post-migration.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/l10n_es/migrations/13.0.4.0/post-migration.py b/addons/l10n_es/migrations/13.0.4.0/post-migration.py index 8e7929679815..1b446b399a48 100644 --- a/addons/l10n_es/migrations/13.0.4.0/post-migration.py +++ b/addons/l10n_es/migrations/13.0.4.0/post-migration.py @@ -73,6 +73,26 @@ def use_new_taxes_and_repartition_lines_on_move_lines(env): FROM account_tax WHERE id IN %%s""" % column, (tuple(tax_ids), ), ) + # A group tax holds no account: its children do. Each tax repartition + # line takes the account of its child's one, matched as the move + # lines are matched to their repartition line below. + for tax_column in ("invoice_tax_id", "refund_tax_id"): + openupgrade.logged_query( + env.cr, sql.SQL(""" + UPDATE account_tax_repartition_line atrl2 + SET account_id = atrl.account_id + FROM account_tax_repartition_line atrl + JOIN account_tax at ON atrl.{column} = at.id + JOIN account_tax_filiation_rel rel ON rel.child_tax = at.id + WHERE atrl2.{column} = rel.parent_tax + AND atrl2.repartition_type = 'tax' + AND atrl.repartition_type = 'tax' + AND SIGN(at.amount) = SIGN(atrl2.factor_percent) + AND atrl2.account_id IS NULL + AND rel.parent_tax IN %s + """).format(column=sql.Identifier(tax_column)), + (tuple(tax_ids), ), + ) if children_tax_ids: # assure children taxes are not parent taxes openupgrade.logged_query(