Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0][IMP] account: assign tag tags of parent taxes to repartition lines #4576

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading