From 23eeb329cafaffea47d3ced724c4f401b027109b Mon Sep 17 00:00:00 2001 From: haumenphai Date: Sat, 18 May 2024 10:07:37 +0700 Subject: [PATCH 1/2] [OU-ADD] product: migrate to 17.0 --- docsource/modules160-170.rst | 2 +- .../product/17.0.1.2/post-migration.py | 10 ++ .../scripts/product/17.0.1.2/pre-migration.py | 31 +++++++ .../17.0.1.2/upgrade_analysis_work.txt | 91 +++++++++++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py create mode 100644 openupgrade_scripts/scripts/product/17.0.1.2/pre-migration.py create mode 100644 openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 39b03c8be720..9804bfa7b4bd 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -692,7 +692,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | privacy_lookup | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| product | | | +| product | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | product_email_template | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py b/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py new file mode 100644 index 000000000000..45ca82b766d3 --- /dev/null +++ b/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py @@ -0,0 +1,10 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env, "product", "17.0.1.2/noupdate_changes.xml") + openupgrade.delete_records_safely_by_xml_id(env, ["product.list0"]) diff --git a/openupgrade_scripts/scripts/product/17.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/product/17.0.1.2/pre-migration.py new file mode 100644 index 000000000000..a4f776906c8e --- /dev/null +++ b/openupgrade_scripts/scripts/product/17.0.1.2/pre-migration.py @@ -0,0 +1,31 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE product_tag + ALTER COLUMN color TYPE VARCHAR USING color::VARCHAR; + + UPDATE product_tag + SET color = CASE + WHEN color = '1' THEN '#F06050' + WHEN color = '2' THEN '#F4A460' + WHEN color = '3' THEN '#F7CD1F' + WHEN color = '4' THEN '#6CC1ED' + WHEN color = '5' THEN '#814968' + WHEN color = '6' THEN '#EB7E7F' + WHEN color = '7' THEN '#2C8397' + WHEN color = '8' THEN '#475577' + WHEN color = '9' THEN '#D6145F' + WHEN color = '10' THEN '#30C381' + WHEN color = '11' THEN '#9365B8' + ELSE '#3C3C3C' + END; + """, + ) diff --git a/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt new file mode 100644 index 000000000000..7258eda91f1b --- /dev/null +++ b/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt @@ -0,0 +1,91 @@ +---Models in module 'product'--- +obsolete model report.product.report_producttemplatelabel [abstract] +new model product.catalog.mixin [abstract] +new model product.document +new model report.product.report_producttemplatelabel2x7 [abstract] +new model report.product.report_producttemplatelabel4x12 [abstract] +new model report.product.report_producttemplatelabel4x12noprice [abstract] +new model report.product.report_producttemplatelabel4x7 [abstract] +# NOTHING TO DO + +---Fields in module 'product'--- +product / product.attribute / display_type (selection) : selection_keys is now '['color', 'multi', 'pills', 'radio', 'select']' ('['color', 'pills', 'radio', 'select']') +# NOTHING TO DO: add new selection: multi + +product / product.attribute.value / default_extra_price (float) : NEW +product / product.attribute.value / image (binary) : NEW attachment: True +product / product.category / product_properties_definition (properties_definition): NEW +# NOTHING TO DO: new feature + +product / product.document / _inherits : NEW _inherits: {'ir.attachment': 'ir_attachment_id'} +product / product.document / active (boolean) : NEW hasdefault: default +product / product.document / ir_attachment_id (many2one) : NEW relation: ir.attachment, required +# NOTHING TO DO: fields in new model + +product / product.packaging / product_id (many2one) : now required +# NOTHING TO DO + +product / product.pricelist / _order : _order is now 'sequence asc, id asc' ('sequence asc, id desc') +product / product.pricelist / activity_ids (one2many) : NEW relation: mail.activity +product / product.pricelist / message_follower_ids (one2many): NEW relation: mail.followers +product / product.pricelist / message_ids (one2many) : NEW relation: mail.message +# NOTHING TO DO + +product / product.pricelist.item / active (boolean) : DEL +# NOTHING TO DO + +product / product.product / activity_user_id (many2one) : not related anymore +product / product.product / activity_user_id (many2one) : now a function +product / product.product / message_main_attachment_id (many2one): DEL relation: ir.attachment +product / product.product / product_document_ids (one2many): NEW relation: product.document +# NOTHING TO DO + +product / product.supplierinfo / discount (float) : NEW +# NOTHING TO DO + +product / product.tag / color (integer) : type is now 'char' ('integer') +# DONE: handled in pre-migration + +product / product.template / activity_user_id (many2one) : not related anymore +product / product.template / activity_user_id (many2one) : now a function +product / product.template / message_main_attachment_id (many2one): DEL relation: ir.attachment +product / product.template / product_document_ids (one2many): NEW relation: product.document +product / product.template / product_properties (properties): NEW hasdefault: compute +# NOTHING TO DO + +product / product.template.attribute.line / _order : _order is now 'sequence, attribute_id, id' ('attribute_id, id') +product / product.template.attribute.line / sequence (integer) : NEW hasdefault: default +# NOTHING TO DO: new feature + +---XML records in module 'product'--- +NEW ir.actions.report: product.report_product_template_label_2x7 +NEW ir.actions.report: product.report_product_template_label_4x12 +NEW ir.actions.report: product.report_product_template_label_4x12_noprice +NEW ir.actions.report: product.report_product_template_label_4x7 +DEL ir.actions.report: product.report_product_template_label +NEW ir.model.access: product.access_product_document_user +NEW ir.model.constraint: product.constraint_product_attribute_check_multi_checkbox_no_variant +# NOTHING TO DO + +NEW ir.rule: product.product_document_comp_rule (noupdate) +NEW ir.ui.view: product.product_attribute_value_list +NEW ir.ui.view: product.product_document_form +NEW ir.ui.view: product.product_document_kanban +NEW ir.ui.view: product.product_document_list +NEW ir.ui.view: product.product_document_search +NEW ir.ui.view: product.product_product_view_tree_tag +NEW ir.ui.view: product.product_template_view_tree_tag +NEW ir.ui.view: product.product_view_kanban_catalog +NEW ir.ui.view: product.product_view_search_catalog +NEW ir.ui.view: product.report_producttemplatelabel2x7 +NEW ir.ui.view: product.report_producttemplatelabel4x12 +NEW ir.ui.view: product.report_producttemplatelabel4x12noprice +NEW ir.ui.view: product.report_producttemplatelabel4x7 +NEW ir.ui.view: product.report_simple_label4x12_no_price +# NOTHING TO DO + +DEL ir.ui.view: product.report_producttemplatelabel +# NOTHING TO DO + +DEL product.pricelist: product.list0 (noupdate) +DONE: delete in post-migration From 2e3a73d4611b8d7e4f89ac70d45db7d5c97c1ec2 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 21 Oct 2024 14:54:36 +0200 Subject: [PATCH 2/2] [OU-IMP] product: populate product_document table from attachments --- .../scripts/product/17.0.1.2/post-migration.py | 12 ++++++++++++ .../product/17.0.1.2/upgrade_analysis_work.txt | 10 +++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py b/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py index 45ca82b766d3..11867387b649 100644 --- a/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py +++ b/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py @@ -8,3 +8,15 @@ def migrate(env, version): openupgrade.load_data(env, "product", "17.0.1.2/noupdate_changes.xml") openupgrade.delete_records_safely_by_xml_id(env, ["product.list0"]) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO product_document ( + ir_attachment_id, active, create_uid, write_uid, create_date, write_date + ) + SELECT id, True, create_uid, write_uid, create_date, write_date + FROM ir_attachment + WHERE res_model IN ('product.product', 'product.template') + AND res_field IS NULL + """, + ) diff --git a/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt index 7258eda91f1b..37f52b38a032 100644 --- a/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/product/17.0.1.2/upgrade_analysis_work.txt @@ -20,7 +20,7 @@ product / product.category / product_properties_definition (propert product / product.document / _inherits : NEW _inherits: {'ir.attachment': 'ir_attachment_id'} product / product.document / active (boolean) : NEW hasdefault: default product / product.document / ir_attachment_id (many2one) : NEW relation: ir.attachment, required -# NOTHING TO DO: fields in new model +# DONE: populated in post-migration with attachments on products product / product.packaging / product_id (many2one) : now required # NOTHING TO DO @@ -37,9 +37,11 @@ product / product.pricelist.item / active (boolean) : DEL product / product.product / activity_user_id (many2one) : not related anymore product / product.product / activity_user_id (many2one) : now a function product / product.product / message_main_attachment_id (many2one): DEL relation: ir.attachment -product / product.product / product_document_ids (one2many): NEW relation: product.document # NOTHING TO DO +product / product.product / product_document_ids (one2many): NEW relation: product.document +# DONE: populated in post-migration with attachments on products + product / product.supplierinfo / discount (float) : NEW # NOTHING TO DO @@ -49,10 +51,12 @@ product / product.tag / color (integer) : type i product / product.template / activity_user_id (many2one) : not related anymore product / product.template / activity_user_id (many2one) : now a function product / product.template / message_main_attachment_id (many2one): DEL relation: ir.attachment -product / product.template / product_document_ids (one2many): NEW relation: product.document product / product.template / product_properties (properties): NEW hasdefault: compute # NOTHING TO DO +product / product.template / product_document_ids (one2many): NEW relation: product.document +# DONE: populated in post-migration with attachments on products + product / product.template.attribute.line / _order : _order is now 'sequence, attribute_id, id' ('attribute_id, id') product / product.template.attribute.line / sequence (integer) : NEW hasdefault: default # NOTHING TO DO: new feature