From ec98fca58e9c91aa780d96e2cc893bb7c4de10d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Wed, 12 May 2021 14:37:54 +0200 Subject: [PATCH] [MIG] repair --- .../13.0.1.0/openupgrade_analysis.txt | 2 +- .../13.0.1.0/openupgrade_analysis_work.txt | 33 ++++++++++ .../migrations/13.0.1.0/post-migration.py | 63 +++++++++++++++++++ .../migrations/13.0.1.0/pre-migration.py | 15 +++++ .../openupgrade/doc/source/modules120-130.rst | 2 +- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 addons/repair/migrations/13.0.1.0/openupgrade_analysis_work.txt create mode 100644 addons/repair/migrations/13.0.1.0/post-migration.py create mode 100644 addons/repair/migrations/13.0.1.0/pre-migration.py diff --git a/addons/repair/migrations/13.0.1.0/openupgrade_analysis.txt b/addons/repair/migrations/13.0.1.0/openupgrade_analysis.txt index 4ff594da483c..bd91ee08b47f 100644 --- a/addons/repair/migrations/13.0.1.0/openupgrade_analysis.txt +++ b/addons/repair/migrations/13.0.1.0/openupgrade_analysis.txt @@ -23,4 +23,4 @@ NEW ir.ui.view: repair.view_repair_graph NEW ir.ui.view: repair.view_repair_pivot NEW ir.ui.view: repair.view_repair_tag_form NEW ir.ui.view: repair.view_repair_tag_search -NEW ir.ui.view: repair.view_repair_tag_tree +NEW ir.ui.view: repair.view_repair_tag_tree \ No newline at end of file diff --git a/addons/repair/migrations/13.0.1.0/openupgrade_analysis_work.txt b/addons/repair/migrations/13.0.1.0/openupgrade_analysis_work.txt new file mode 100644 index 000000000000..24c4ae326f61 --- /dev/null +++ b/addons/repair/migrations/13.0.1.0/openupgrade_analysis_work.txt @@ -0,0 +1,33 @@ +---Models in module 'repair'--- +new model repair.tags +# NOTHING TO DO +---Fields in module 'repair'--- +repair / account.move / repair_ids (one2many) : NEW relation: repair.order +repair / account.move.line / repair_fee_ids (one2many) : NEW relation: repair.fee +repair / account.move.line / repair_line_ids (one2many) : NEW relation: repair.line +# NOTHING TO DO +repair / repair.fee / invoice_line_id (many2one) : relation is now 'account.move.line' ('account.invoice.line') [nothing to do] +repair / repair.line / invoice_line_id (many2one) : relation is now 'account.move.line' ('account.invoice.line') [nothing to do] +repair / repair.order / invoice_id (many2one) : relation is now 'account.move' ('account.invoice') [nothing to do] +# DONE: post-migration: refilled many2one tables +repair / repair.order / tag_ids (many2many) : NEW relation: repair.tags +# NOTHING TO DO +repair / repair.order / user_id (many2one) : NEW relation: res.users, hasdefault +# DONE: Set all records with create_uid +repair / repair.tags / color (integer) : NEW +repair / repair.tags / name (char) : NEW required +# NOTHING TO DO +---XML records in module 'repair'--- +NEW ir.actions.act_window: repair.action_repair_order_graph +NEW ir.actions.act_window: repair.action_repair_order_tag +NEW ir.model.access: repair.access_repair_tag_user +NEW ir.ui.menu: repair.repair_menu +NEW ir.ui.menu: repair.repair_menu_config +NEW ir.ui.menu: repair.repair_menu_reporting +NEW ir.ui.menu: repair.repair_menu_tag +NEW ir.ui.view: repair.view_repair_graph +NEW ir.ui.view: repair.view_repair_pivot +NEW ir.ui.view: repair.view_repair_tag_form +NEW ir.ui.view: repair.view_repair_tag_search +NEW ir.ui.view: repair.view_repair_tag_tree +# NOTHING TO DO \ No newline at end of file diff --git a/addons/repair/migrations/13.0.1.0/post-migration.py b/addons/repair/migrations/13.0.1.0/post-migration.py new file mode 100644 index 000000000000..a7dfbee60340 --- /dev/null +++ b/addons/repair/migrations/13.0.1.0/post-migration.py @@ -0,0 +1,63 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from psycopg2 import sql +from openupgradelib import openupgrade + + +def update_repair_fee_invoice_relation(env): + openupgrade.logged_query( + env.cr, sql.SQL( + """UPDATE repair_fee rf + SET invoice_line_id = aml.id + FROM account_move_line aml + WHERE rf.{} = aml.old_invoice_line_id""" + ).format( + sql.Identifier(openupgrade.get_legacy_name("invoice_line_id")) + ), + ) + + +def update_repair_line_invoice_relation(env): + openupgrade.logged_query( + env.cr, sql.SQL( + """UPDATE repair_line rl + SET invoice_line_id = aml.id + FROM account_move_line aml + WHERE rl.{} = aml.old_invoice_line_id""" + ).format( + sql.Identifier(openupgrade.get_legacy_name("invoice_line_id")) + ), + ) + + +def update_repair_order_invoice_relation(env): + openupgrade.logged_query( + env.cr, sql.SQL( + """UPDATE repair_order ro + SET invoice_id = am.id + FROM account_move am + WHERE ro.{} = am.old_invoice_id""" + ).format( + sql.Identifier(openupgrade.get_legacy_name("invoice_id")) + ), + ) + + +def update_repair_order_user_id(env): + openupgrade.logged_query( + env.cr, """ + UPDATE repair_order + SET user_id = create_uid""", + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data( + env.cr, "repair", + "migrations/13.0.1.0/noupdate_changes.xml" + ) + update_repair_fee_invoice_relation(env) + update_repair_line_invoice_relation(env) + update_repair_order_invoice_relation(env) + update_repair_order_user_id(env) diff --git a/addons/repair/migrations/13.0.1.0/pre-migration.py b/addons/repair/migrations/13.0.1.0/pre-migration.py new file mode 100644 index 000000000000..f7af2fdfea6a --- /dev/null +++ b/addons/repair/migrations/13.0.1.0/pre-migration.py @@ -0,0 +1,15 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +_rename_columns = { + "repair_fee": [('invoice_line_id', None)], + "repair_line": [('invoice_line_id', None)], + "repair_order": [('invoice_id', None)], +} + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_columns(env.cr, _rename_columns) diff --git a/odoo/openupgrade/doc/source/modules120-130.rst b/odoo/openupgrade/doc/source/modules120-130.rst index cb05f67f3e34..e42c95a93b7c 100644 --- a/odoo/openupgrade/doc/source/modules120-130.rst +++ b/odoo/openupgrade/doc/source/modules120-130.rst @@ -551,7 +551,7 @@ missing in the new release are marked with |del|. +----------------------------------------------+-------------------------------------------------+ |rating | Nothing to do | +----------------------------------------------+-------------------------------------------------+ -|repair | | +|repair | Done | +----------------------------------------------+-------------------------------------------------+ |resource | Done | +----------------------------------------------+-------------------------------------------------+