Skip to content

Commit d6fe272

Browse files
authored
Merge pull request #4576 from hbrunn/13.0-account-add-parent-tax-tags
[13.0][IMP] account: assign tag tags of parent taxes to repartition lines
2 parents e71da52 + 1818ae1 commit d6fe272

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

addons/account/migrations/13.0.1.1/post-migration.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,21 @@ def create_account_tax_repartition_lines(env):
851851
def move_tags_from_taxes_to_repartition_lines(env):
852852
openupgrade.logged_query(
853853
env.cr, """
854+
WITH RECURSIVE tax2parent(tax_id, parent_id) AS (
855+
SELECT id, id FROM account_tax
856+
UNION ALL
857+
SELECT rel.child_tax, rel.parent_tax
858+
FROM account_tax_filiation_rel rel
859+
JOIN tax2parent ON tax2parent.parent_id=rel.child_tax
860+
)
854861
INSERT INTO account_account_tag_account_tax_repartition_line_rel (
855862
account_tax_repartition_line_id, account_account_tag_id)
856863
SELECT atrl.id, atat.account_account_tag_id
857864
FROM account_tax_account_tag atat
865+
JOIN tax2parent ON atat.account_tax_id=tax2parent.parent_id
858866
JOIN account_tax_repartition_line atrl ON
859-
(atat.account_tax_id = atrl.invoice_tax_id OR
860-
atat.account_tax_id = atrl.refund_tax_id)
867+
(tax2parent.tax_id = atrl.invoice_tax_id OR
868+
tax2parent.tax_id = atrl.refund_tax_id)
861869
ON CONFLICT DO NOTHING"""
862870
)
863871
openupgrade.logged_query(
@@ -944,14 +952,22 @@ def assign_account_tags_to_move_lines(env):
944952
# move lines with taxes
945953
openupgrade.logged_query(
946954
env.cr, """
955+
WITH RECURSIVE tax2child(tax_id, child_id) AS (
956+
SELECT id, id FROM account_tax
957+
UNION ALL
958+
SELECT rel.parent_tax, rel.child_tax
959+
FROM account_tax_filiation_rel rel
960+
JOIN tax2child ON tax2child.child_id=rel.parent_tax
961+
)
947962
INSERT INTO account_account_tag_account_move_line_rel (
948963
account_move_line_id, account_account_tag_id)
949964
SELECT aml.id, aat_atr_rel.account_account_tag_id
950965
FROM account_move_line aml
951966
JOIN account_move am ON aml.move_id = am.id
952967
JOIN account_move_line_account_tax_rel amlatr ON amlatr.account_move_line_id = aml.id
968+
JOIN tax2child ON amlatr.account_tax_id=tax2child.child_id
953969
JOIN account_tax_repartition_line atrl ON (
954-
atrl.invoice_tax_id = amlatr.account_tax_id AND atrl.repartition_type = 'base')
970+
atrl.invoice_tax_id = tax2child.tax_id AND atrl.repartition_type = 'base')
955971
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
956972
aat_atr_rel.account_tax_repartition_line_id = atrl.id
957973
WHERE aml.old_invoice_line_id IS NOT NULL AND am.type in ('out_invoice', 'in_invoice')

0 commit comments

Comments
 (0)