From 9073f86a0e62b90af90e9e9bb3fc886b9086c6e1 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 21 Oct 2024 13:50:26 +0200 Subject: [PATCH] [OU-IMP] analytic: use ir.property api to set properties and set them on all companies also save account.analytic.plan#company_id for posterity and apply noupdate changes --- .../analytic/17.0.1.1/post-migration.py | 29 +++++++------------ .../analytic/17.0.1.1/pre-migration.py | 5 ++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py b/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py index dd88553c7243..59e6298a7f0f 100644 --- a/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py @@ -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, diff --git a/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py index f542950d4c43..513fc404e63e 100644 --- a/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py @@ -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)]} + )