Skip to content

Commit

Permalink
[FIX] account: set company for tax_group (#658)
Browse files Browse the repository at this point in the history
* [FIX] account: set company for tax_group

-Forget to set company_id for tax_group
[FIX] l10n_vn: wrong value for pre-fix company_id of xml_id

- if just select id from res_company then env.cr.fetchall() will return
like [(1, ), (2, )]

* Update pre-migration.py

* Update pre-migration.py

* Update openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py

---------

Co-authored-by: Roy Le <[email protected]>
  • Loading branch information
ndd-odoo and royle-vietnam authored Jun 7, 2024
1 parent 87364f0 commit 9a9a2b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,20 @@ def _account_tax_migration(env):
)

for tax_group_id, company_ids in env.cr.fetchall():
first_company_id = company_ids[:1]

first_company_id = company_ids[:1] and company_ids[0]

openupgrade.logged_query(
env.cr,
f"""
UPDATE account_tax_group
SET company_id = {first_company_id}
WHERE id = {tax_group_id}
""",
)
imd = env["ir.model.data"].search(
[("res_id", "=", tax_group_id), ("model", "=", "account.tax.group")]
)
tax_group_name = imd.name
imd.write({"name": f"{first_company_id}_{imd.name}"})

for company_id in company_ids[1:]:
Expand All @@ -513,8 +522,8 @@ def _account_tax_migration(env):
)

new_tax_group_id = env.cr.fetchone()[0]
vals = {"res_id": new_tax_group_id, "name": f"{company_id}_{imd.name}"}
imd.copy(default=vals)
new_imp = imd.copy(default={"res_id": new_tax_group_id})
new_imp.write({"name": f"{company_id}_{tax_group_name}"})

openupgrade.logged_query(
env.cr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def _vn_coa_rename_xml_id(env):
we need to rename some xml_id like tax or tax.group
in order to avoid duplication
"""
env.cr.execute("""SELECT id FROM res_company WHERE chart_template = 'vn'""")
env.cr.execute(
"""SELECT array_agg(id) FROM res_company WHERE chart_template = 'vn'"""
)
xmlids_renames = []
for company_id in env.cr.fetchall():
for tax_group_xmlid in _account_tax_group_xmlid:
Expand Down

0 comments on commit 9a9a2b1

Please sign in to comment.