From 2f226a6ce36d3c1efecc3e4f3a6700a4d51a6fd0 Mon Sep 17 00:00:00 2001 From: hoangdinhhieu Date: Fri, 14 Jan 2022 16:50:23 +0700 Subject: [PATCH] [MIG]sale_margin: migration script --- docsource/modules130-140.rst | 2 +- .../sale_margin/14.0.1.0/pre-migration.py | 26 +++++++++++++++++++ .../14.0.1.0/upgrade_analysis_work.txt | 12 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/sale_margin/14.0.1.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/sale_margin/14.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules130-140.rst b/docsource/modules130-140.rst index 60666719a40d..90bc1fd9b9aa 100644 --- a/docsource/modules130-140.rst +++ b/docsource/modules130-140.rst @@ -596,7 +596,7 @@ Module coverage 13.0 -> 14.0 +--------------------------------------------+-------------------------------------------------+ |sale_management | Done | +--------------------------------------------+-------------------------------------------------+ -|sale_margin | | +|sale_margin | Done | +--------------------------------------------+-------------------------------------------------+ |sale_mrp | | +--------------------------------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/sale_margin/14.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/sale_margin/14.0.1.0/pre-migration.py new file mode 100644 index 000000000000..9a7dcf66297c --- /dev/null +++ b/openupgrade_scripts/scripts/sale_margin/14.0.1.0/pre-migration.py @@ -0,0 +1,26 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, installed_version): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE sale_order_line + ADD COLUMN IF NOT EXISTS margin_percent double precision; + + ALTER TABLE sale_order + ADD COLUMN IF NOT EXISTS margin_percent double precision; + """, + ) + + openupgrade.logged_query( + env.cr, + """ + UPDATE sale_order_line + SET margin_percent = COALESCE(margin / NULLIF(price_subtotal, 0), 0); + + UPDATE sale_order + SET margin_percent = COALESCE(margin / NULLIF(amount_untaxed, 0), 0); + """, + ) diff --git a/openupgrade_scripts/scripts/sale_margin/14.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/sale_margin/14.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..cf54d8eb6172 --- /dev/null +++ b/openupgrade_scripts/scripts/sale_margin/14.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,12 @@ +---Models in module 'sale_margin'--- +---Fields in module 'sale_margin'--- +sale_margin / sale.order / margin_percent (float) : NEW : function, stored +sale_margin / sale.order.line / margin_percent (float) : NEW isfunction: function, stored +# DONE: pre-migration fast filled + +sale_margin / sale.order.line / purchase_price (float) : now a function +# NOTHING TO DO + +---XML records in module 'sale_margin'--- +NEW ir.ui.view: sale_margin.sale_margin_sale_order_pivot +# NOTHING TO DO