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] l10n_be: migration account.account.tag #4432

Open
wants to merge 16 commits into
base: 13.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
172 changes: 172 additions & 0 deletions addons/l10n_be/migrations/13.0.2.0/openupgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---Models in module 'l10n_be'---
---Fields in module 'l10n_be'---
---XML records in module 'l10n_be'---
DEL account.account.tag: l10n_be.tax_tag_00
DEL account.account.tag: l10n_be.tax_tag_01
DEL account.account.tag: l10n_be.tax_tag_02
DEL account.account.tag: l10n_be.tax_tag_03
DEL account.account.tag: l10n_be.tax_tag_44
DEL account.account.tag: l10n_be.tax_tag_45
DEL account.account.tag: l10n_be.tax_tag_46L
DEL account.account.tag: l10n_be.tax_tag_46T
DEL account.account.tag: l10n_be.tax_tag_47
DEL account.account.tag: l10n_be.tax_tag_48s44
DEL account.account.tag: l10n_be.tax_tag_48s46L
DEL account.account.tag: l10n_be.tax_tag_48s46T
DEL account.account.tag: l10n_be.tax_tag_49
DEL account.account.tag: l10n_be.tax_tag_54
DEL account.account.tag: l10n_be.tax_tag_55
DEL account.account.tag: l10n_be.tax_tag_56
DEL account.account.tag: l10n_be.tax_tag_57
DEL account.account.tag: l10n_be.tax_tag_59
DEL account.account.tag: l10n_be.tax_tag_61
DEL account.account.tag: l10n_be.tax_tag_62
DEL account.account.tag: l10n_be.tax_tag_63
DEL account.account.tag: l10n_be.tax_tag_64
DEL account.account.tag: l10n_be.tax_tag_81
DEL account.account.tag: l10n_be.tax_tag_81_not_deductible
DEL account.account.tag: l10n_be.tax_tag_82
DEL account.account.tag: l10n_be.tax_tag_82_not_deductible
DEL account.account.tag: l10n_be.tax_tag_83
DEL account.account.tag: l10n_be.tax_tag_83_not_deductible
DEL account.account.tag: l10n_be.tax_tag_84
DEL account.account.tag: l10n_be.tax_tag_85
DEL account.account.tag: l10n_be.tax_tag_85_not_deductible
DEL account.account.tag: l10n_be.tax_tag_86
DEL account.account.tag: l10n_be.tax_tag_87
DEL account.account.tag: l10n_be.tax_tag_88
NEW account.account.template: l10n_be.a4001
NEW account.account.template: l10n_be.a62021
NEW account.account.template: l10n_be.a62022
NEW account.account.template: l10n_be.a6231
NEW account.account.template: l10n_be.a7492
NEW account.fiscal.position.template: l10n_be.fiscal_position_template_5
NEW account.reconcile.model.template: l10n_be.compte_attente_template
DEL account.tax.group: l10n_be.tax_group_tva_0_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_12_cocont (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_12_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_12_non_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_21_50_deductible (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_21_cocont (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_21_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_21_non_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_6_cocont (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_6_eu (noupdate)
DEL account.tax.group: l10n_be.tax_group_tva_6_non_eu (noupdate)
NEW account.tax.report.line: l10n_be.tax_report_line_00
NEW account.tax.report.line: l10n_be.tax_report_line_01
NEW account.tax.report.line: l10n_be.tax_report_line_02
NEW account.tax.report.line: l10n_be.tax_report_line_03
NEW account.tax.report.line: l10n_be.tax_report_line_44
NEW account.tax.report.line: l10n_be.tax_report_line_45
NEW account.tax.report.line: l10n_be.tax_report_line_46L
NEW account.tax.report.line: l10n_be.tax_report_line_46T
NEW account.tax.report.line: l10n_be.tax_report_line_47
NEW account.tax.report.line: l10n_be.tax_report_line_48s44
NEW account.tax.report.line: l10n_be.tax_report_line_48s46L
NEW account.tax.report.line: l10n_be.tax_report_line_48s46T
NEW account.tax.report.line: l10n_be.tax_report_line_49
NEW account.tax.report.line: l10n_be.tax_report_line_54
NEW account.tax.report.line: l10n_be.tax_report_line_55
NEW account.tax.report.line: l10n_be.tax_report_line_56
NEW account.tax.report.line: l10n_be.tax_report_line_57
NEW account.tax.report.line: l10n_be.tax_report_line_59
NEW account.tax.report.line: l10n_be.tax_report_line_61
NEW account.tax.report.line: l10n_be.tax_report_line_62
NEW account.tax.report.line: l10n_be.tax_report_line_63
NEW account.tax.report.line: l10n_be.tax_report_line_64
NEW account.tax.report.line: l10n_be.tax_report_line_71
NEW account.tax.report.line: l10n_be.tax_report_line_72
NEW account.tax.report.line: l10n_be.tax_report_line_81
NEW account.tax.report.line: l10n_be.tax_report_line_82
NEW account.tax.report.line: l10n_be.tax_report_line_83
NEW account.tax.report.line: l10n_be.tax_report_line_84
NEW account.tax.report.line: l10n_be.tax_report_line_85
NEW account.tax.report.line: l10n_be.tax_report_line_86
NEW account.tax.report.line: l10n_be.tax_report_line_87
NEW account.tax.report.line: l10n_be.tax_report_line_88
NEW account.tax.report.line: l10n_be.tax_report_title_operations
NEW account.tax.report.line: l10n_be.tax_report_title_operations_entree
NEW account.tax.report.line: l10n_be.tax_report_title_operations_sortie
NEW account.tax.report.line: l10n_be.tax_report_title_operations_sortie_46
NEW account.tax.report.line: l10n_be.tax_report_title_operations_sortie_48
NEW account.tax.report.line: l10n_be.tax_report_title_taxes
NEW account.tax.report.line: l10n_be.tax_report_title_taxes_deductibles
NEW account.tax.report.line: l10n_be.tax_report_title_taxes_dues
NEW account.tax.report.line: l10n_be.tax_report_title_taxes_soldes
DEL account.tax.template: l10n_be.attn_VAT-IN-V61
DEL account.tax.template: l10n_be.attn_VAT-IN-V62
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-06-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-12-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V81-21-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-EU-G-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-EU-G-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-EU-S-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-EU-S-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-06-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-EU-G-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-EU-G-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-EU-S-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-EU-S-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-12-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-EU-G-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-EU-G-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-EU-S-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-EU-S-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-21-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-CAR-EXC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V82-CAR-EXC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-06-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-12-ROW-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-CC-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-EU-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-EU-C2
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-ROW-CC-C1
DEL account.tax.template: l10n_be.attn_VAT-IN-V83-21-ROW-CC-C2

DEL res.country.state: l10n_be.state_be_van
DEL res.country.state: l10n_be.state_be_vbr
DEL res.country.state: l10n_be.state_be_vli
DEL res.country.state: l10n_be.state_be_vov
DEL res.country.state: l10n_be.state_be_vwv
DEL res.country.state: l10n_be.state_be_wbr
DEL res.country.state: l10n_be.state_be_wht
DEL res.country.state: l10n_be.state_be_wlg
DEL res.country.state: l10n_be.state_be_wlx
DEL res.country.state: l10n_be.state_be_wna
# DONE: pre-migration: delete ir.model.data entries
180 changes: 180 additions & 0 deletions addons/l10n_be/migrations/13.0.2.0/post-00-update_custom_taxes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
from openupgradelib import openupgrade
import logging

_logger = logging.getLogger(__name__)


# This is tables of correspondance between old tags and the new tax tags
# based on the tax tag used in the account.tax.template
base_invoice_tag_xmlids = [
("tax_tag_00", "+00"),
("tax_tag_01", "+01"),
("tax_tag_02", "+02"),
("tax_tag_03", "+03"),
("tax_tag_44", "+44"),
("tax_tag_45", "+45"),
("tax_tag_46L", "+46L"),
("tax_tag_46T", "+46T"),
("tax_tag_47", "+47"),
("tax_tag_81", "+81"),
("tax_tag_82", "+82"),
("tax_tag_83", "+83"),
("tax_tag_86", "+86"),
("tax_tag_87", "+87"),
("tax_tag_88", "+88"),
("tax_tag_81_not_deductible", "+81"),
("tax_tag_82_not_deductible", "+82"),
("tax_tag_83_not_deductible", "+83"),
]

tax_invoice_tag_xmlids = [
("tax_tag_54", "+54"),
("tax_tag_55", "-55"),
("tax_tag_56", "-56"),
("tax_tag_57", "-57"),
("tax_tag_59", "+59"),
("tax_tag_82", "+82"),
("tax_tag_82_not_deductible", "+82"),
]

base_refund_tag_xmlids = [
("tax_tag_48s44", "+48s44"),
("tax_tag_48s46L", "+48s46L"),
("tax_tag_48s46T", "+48s46T"),
("tax_tag_49", "+49"),
("tax_tag_81", "-81"),
("tax_tag_82", "-82"),
("tax_tag_83", "-83"),
("tax_tag_84", "+84"),
("tax_tag_85", "+85"),
("tax_tag_86", "-86"),
("tax_tag_87", "-87"),
("tax_tag_88", "-88"),
("tax_tag_81_not_deductible", "-81"),
("tax_tag_82_not_deductible", "-82"),
("tax_tag_83_not_deductible", "-83"),
("tax_tag_85_not_deductible", "+85"),
]

tax_refund_tag_xmlids = [
("tax_tag_63", "+63"),
("tax_tag_64", "+64"),
("tax_tag_82", "-82"),
("tax_tag_82_not_deductible", "-82"),
]

tax_unclassified_tag_xmlids = [
"tax_tag_61",
"tax_tag_62",
]


def update_custom_account_tax(env):
"""This function tries to update custom account.tax"""
# get old tags and extract their code names
correspondance = {
("invoice", "base"): [
(env.ref("l10n_be." + xmlid), new_name)
for xmlid, new_name in base_invoice_tag_xmlids
],
("invoice", "tax"): [
(env.ref("l10n_be." + xmlid), new_name)
for xmlid, new_name in tax_invoice_tag_xmlids
],
("refund", "base"): [
(env.ref("l10n_be." + xmlid), new_name)
for xmlid, new_name in base_refund_tag_xmlids
],
("refund", "tax"): [
(env.ref("l10n_be." + xmlid), new_name)
for xmlid, new_name in tax_refund_tag_xmlids
],
}

def get_parent_tax_tags(account_tax):
"""Return old tags that were linked on the parent tax if any"""
parent_tax_id = (
env["account.tax"]
.with_context(active_test=False)
.search([("children_tax_ids", "in", account_tax.id)], limit=1)
)
if not parent_tax_id:
return None
env.cr.execute(
"""SELECT account_account_tag_id
FROM account_tax_account_tag
WHERE account_tax_id = %s
""",
(parent_tax_id.id,),
)
parent_tax_tags = [int(res[0]) for res in env.cr.fetchall()]
parent_tax_tag_ids = (
env["account.account.tag"]
.with_context(active_test=False)
.search([("id", "in", parent_tax_tags)])
)
return parent_tax_tag_ids

def get_new_tag_names(tag_ids, old_tags):
"""Return list of code and old_tags for tag_ids that exists in
old_tags
"""
keep_tags = []
for tag in tag_ids:
for old_tag, new_name in old_tags:
if tag == old_tag:
keep_tags.append(new_name)
return keep_tags

def repartition_lines_iter(account_tax):
"""Special loop over repartition lines in an account.tax"""
for repartition in account_tax.invoice_repartition_line_ids:
yield ("invoice", repartition)
for repartition in account_tax.refund_repartition_line_ids:
yield ("refund", repartition)

custom_account_tax_ids = (
env["account.tax"]
.with_context(active_test=False)
.search([])
)
for account_tax in custom_account_tax_ids:
parent_tax_tag_ids = get_parent_tax_tags(account_tax)
for reptype, repartition in repartition_lines_iter(account_tax):
key = (reptype, repartition.repartition_type)
# keep right tags
if (
repartition.repartition_type == "base"
and parent_tax_tag_ids is not None
):
keep_tags = get_new_tag_names(
parent_tax_tag_ids, correspondance[key]
)
else:
keep_tags = get_new_tag_names(
repartition.tag_ids, correspondance[key]
)
# fix special cases
# tag "82" can not be set on tax lines if other tags are
# assigned to these tax lines
if (
repartition.repartition_type == "tax"
and len(keep_tags) > 1
):
if "+82" in keep_tags:
keep_tags.remove("+82")
if "-82" in keep_tags:
keep_tags.remove("-82")
# convert tags
new_tags = env["account.account.tag"]
for new_name in keep_tags:
new_tag = env["account.account.tag"].search(
[("name", "=", new_name)], limit=1,
)
new_tags |= new_tag
repartition.tag_ids = new_tags


@openupgrade.migrate()
def migrate(env, version):
update_custom_account_tax(env)
Loading
Loading