@@ -851,13 +851,21 @@ def create_account_tax_repartition_lines(env):
851
851
def move_tags_from_taxes_to_repartition_lines (env ):
852
852
openupgrade .logged_query (
853
853
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
+ )
854
861
INSERT INTO account_account_tag_account_tax_repartition_line_rel (
855
862
account_tax_repartition_line_id, account_account_tag_id)
856
863
SELECT atrl.id, atat.account_account_tag_id
857
864
FROM account_tax_account_tag atat
865
+ JOIN tax2parent ON atat.account_tax_id=tax2parent.parent_id
858
866
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)
861
869
ON CONFLICT DO NOTHING"""
862
870
)
863
871
openupgrade .logged_query (
@@ -944,14 +952,22 @@ def assign_account_tags_to_move_lines(env):
944
952
# move lines with taxes
945
953
openupgrade .logged_query (
946
954
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
+ )
947
962
INSERT INTO account_account_tag_account_move_line_rel (
948
963
account_move_line_id, account_account_tag_id)
949
964
SELECT aml.id, aat_atr_rel.account_account_tag_id
950
965
FROM account_move_line aml
951
966
JOIN account_move am ON aml.move_id = am.id
952
967
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
953
969
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')
955
971
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
956
972
aat_atr_rel.account_tax_repartition_line_id = atrl.id
957
973
WHERE aml.old_invoice_line_id IS NOT NULL AND am.type in ('out_invoice', 'in_invoice')
0 commit comments