Skip to content

Commit

Permalink
Merge pull request #4576 from hbrunn/13.0-account-add-parent-tax-tags
Browse files Browse the repository at this point in the history
[13.0][IMP] account: assign tag tags of parent taxes to repartition lines
  • Loading branch information
pedrobaeza authored Oct 4, 2024
2 parents e71da52 + 1818ae1 commit d6fe272
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions addons/account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,21 @@ def create_account_tax_repartition_lines(env):
def move_tags_from_taxes_to_repartition_lines(env):
openupgrade.logged_query(
env.cr, """
WITH RECURSIVE tax2parent(tax_id, parent_id) AS (
SELECT id, id FROM account_tax
UNION ALL
SELECT rel.child_tax, rel.parent_tax
FROM account_tax_filiation_rel rel
JOIN tax2parent ON tax2parent.parent_id=rel.child_tax
)
INSERT INTO account_account_tag_account_tax_repartition_line_rel (
account_tax_repartition_line_id, account_account_tag_id)
SELECT atrl.id, atat.account_account_tag_id
FROM account_tax_account_tag atat
JOIN tax2parent ON atat.account_tax_id=tax2parent.parent_id
JOIN account_tax_repartition_line atrl ON
(atat.account_tax_id = atrl.invoice_tax_id OR
atat.account_tax_id = atrl.refund_tax_id)
(tax2parent.tax_id = atrl.invoice_tax_id OR
tax2parent.tax_id = atrl.refund_tax_id)
ON CONFLICT DO NOTHING"""
)
openupgrade.logged_query(
Expand Down Expand Up @@ -944,14 +952,22 @@ def assign_account_tags_to_move_lines(env):
# move lines with taxes
openupgrade.logged_query(
env.cr, """
WITH RECURSIVE tax2child(tax_id, child_id) AS (
SELECT id, id FROM account_tax
UNION ALL
SELECT rel.parent_tax, rel.child_tax
FROM account_tax_filiation_rel rel
JOIN tax2child ON tax2child.child_id=rel.parent_tax
)
INSERT INTO account_account_tag_account_move_line_rel (
account_move_line_id, account_account_tag_id)
SELECT aml.id, aat_atr_rel.account_account_tag_id
FROM account_move_line aml
JOIN account_move am ON aml.move_id = am.id
JOIN account_move_line_account_tax_rel amlatr ON amlatr.account_move_line_id = aml.id
JOIN tax2child ON amlatr.account_tax_id=tax2child.child_id
JOIN account_tax_repartition_line atrl ON (
atrl.invoice_tax_id = amlatr.account_tax_id AND atrl.repartition_type = 'base')
atrl.invoice_tax_id = tax2child.tax_id AND atrl.repartition_type = 'base')
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
aat_atr_rel.account_tax_repartition_line_id = atrl.id
WHERE aml.old_invoice_line_id IS NOT NULL AND am.type in ('out_invoice', 'in_invoice')
Expand Down

0 comments on commit d6fe272

Please sign in to comment.