Skip to content

Commit

Permalink
[OU-IMP] analytic: use ir.property api to set properties
Browse files Browse the repository at this point in the history
and set them on all companies
also save account.analytic.plan#company_id for posterity
and apply noupdate changes
  • Loading branch information
hbrunn committed Oct 28, 2024
1 parent 5cd321c commit 9073f86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
29 changes: 11 additions & 18 deletions openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,28 @@ def _analytic_line_create_x_plan_column(env):

def _analytic_plan_update_applicability_into_property(env):
"""
Manually create ir.property for default_applicability of account.analytic.plan
Create ir.property for default_applicability of account.analytic.plan
in all companies as the company_id field was shifted from account.analytic.plan
to account.analytic.applicability
"""
vals_list = []
field_id = (
env["ir.model.fields"]._get("account.analytic.plan", "default_applicability").id
)
env.cr.execute(
"""
SELECT id, default_applicability, company_id FROM account_analytic_plan
SELECT id, default_applicability FROM account_analytic_plan
WHERE default_applicability != 'optional'
"""
)
for plan_id, default_applicability, company_id in env.cr.fetchall():
vals_list.append(
{
"fields_id": field_id,
"company_id": company_id,
"res_id": "account.analytic.plan,%s" % plan_id,
"name": "default_applicability",
"value": default_applicability,
"type": "selection",
}
values = dict(env.cr.fetchall())
for company in env["res.company"].search([]):
env["ir.property"].with_company(company)._set_multi(
"default_applicability",
"account.analytic.plan",
values,
)
if vals_list:
env["ir.property"].create(vals_list)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "analytic", "17.0.1.1/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ def migrate(env, version):
DROP INDEX IF EXISTS account_analytic_account_name_index;
""",
)
# Save company_id field of analytic plans for modules reinstating this
# to pick up
openupgrade.copy_columns(
env.cr, {"account_analytic_plan": [("company_id", None, None)]}
)

0 comments on commit 9073f86

Please sign in to comment.