From ef4a6797513644171b657ad7bd50324b3ffb398e Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 23 Apr 2020 11:08:08 +0200 Subject: [PATCH 1/2] [MIG] puchase_stock --- .../13.0.1.2/openupgrade_analysis_work.txt | 16 +++++++ .../migrations/13.0.1.2/post-migration.py | 44 +++++++++++++++++++ .../openupgrade/doc/source/modules120-130.rst | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt create mode 100644 addons/purchase_stock/migrations/13.0.1.2/post-migration.py diff --git a/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt b/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt new file mode 100644 index 00000000000..0da2cc021d7 --- /dev/null +++ b/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt @@ -0,0 +1,16 @@ +---Models in module 'purchase_stock'--- +---Fields in module 'purchase_stock'--- +purchase_stock / purchase.order.line / propagate_cancel (boolean) : NEW hasdefault +# DONE: post-migration: set propagate_cancel = False when is not propagated, by default is True + +purchase_stock / purchase.order.line / propagate_date (boolean) : NEW +purchase_stock / purchase.order.line / propagate_date_minimum_delta (integer): NEW +# DONE: post-migration: done similar as done in stock module + +purchase_stock / purchase.order.line / qty_received_method (False) : NEW selection_keys: ['manual', 'stock_moves'], mode: modify +# NOTHING TO DO: handled in purchase module + +---XML records in module 'purchase_stock'--- +DEL ir.ui.menu: purchase_stock.menu_action_picking_tree_in_move +DEL ir.ui.view: purchase_stock.stock_production_lot_view_form_simple +# NOTHING TO DO diff --git a/addons/purchase_stock/migrations/13.0.1.2/post-migration.py b/addons/purchase_stock/migrations/13.0.1.2/post-migration.py new file mode 100644 index 00000000000..da5e86e9ef5 --- /dev/null +++ b/addons/purchase_stock/migrations/13.0.1.2/post-migration.py @@ -0,0 +1,44 @@ +# Copyright 2020 ForgeFlow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +def fix_purchase_order_line_propagate_cancel(env): + openupgrade.logged_query( + env.cr, """ + UPDATE purchase_order_line pol + SET propagate_cancel = FALSE + FROM stock_move sm + WHERE sm.purchase_line_id = pol.id AND sm.propagate_cancel = FALSE + """ + ) + + +def fill_propagate_date_minimum_delta(env): + # purchase order line + openupgrade.logged_query( + env.cr, """ + UPDATE purchase_order_line pol + SET propagate_date_minimum_delta = rc.propagation_minimum_delta + FROM res_company rc + WHERE pol.company_id = rc.id AND + pol.propagate_date_minimum_delta IS NULL + AND rc.propagation_minimum_delta IS NOT NULL + """ + ) + openupgrade.logged_query( + env.cr, """ + UPDATE purchase_order_line pol + SET propagate_date = TRUE + FROM ir_config_parameter icp + WHERE pol.propagate_date IS NULL + AND icp.key = 'stock.use_propagation_minimum_delta' + AND icp.value = 'True' + """ + ) + + +@openupgrade.migrate() +def migrate(env, version): + fix_purchase_order_line_propagate_cancel(env) + fill_propagate_date_minimum_delta(env) diff --git a/odoo/openupgrade/doc/source/modules120-130.rst b/odoo/openupgrade/doc/source/modules120-130.rst index b7230e8c021..8a9f058e98d 100644 --- a/odoo/openupgrade/doc/source/modules120-130.rst +++ b/odoo/openupgrade/doc/source/modules120-130.rst @@ -547,7 +547,7 @@ missing in the new release are marked with |del|. +----------------------------------------------+-------------------------------------------------+ | |new| purchase_requisition_stock | | +----------------------------------------------+-------------------------------------------------+ -|purchase_stock | | +|purchase_stock | Done | +----------------------------------------------+-------------------------------------------------+ |rating | Nothing to do | +----------------------------------------------+-------------------------------------------------+ From 74159588c29fe964fa407d305c6056c533d16e1e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 8 May 2021 12:08:07 +0200 Subject: [PATCH 2/2] [OU-IMP] purchase_stock: Add qty_received_method = 'stock_moves' here --- addons/purchase_stock/__manifest__.py | 2 +- .../13.0.1.2/openupgrade_analysis_work.txt | 2 +- .../migrations/13.0.1.2/post-migration.py | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/purchase_stock/__manifest__.py b/addons/purchase_stock/__manifest__.py index a9b8b7ce404..118481fa98b 100644 --- a/addons/purchase_stock/__manifest__.py +++ b/addons/purchase_stock/__manifest__.py @@ -26,6 +26,6 @@ 'data/purchase_stock_demo.xml', ], 'installable': True, - 'auto_install': False, + 'auto_install': True, 'post_init_hook': '_create_buy_rules', } diff --git a/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt b/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt index 0da2cc021d7..138aa344e7d 100644 --- a/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt +++ b/addons/purchase_stock/migrations/13.0.1.2/openupgrade_analysis_work.txt @@ -8,7 +8,7 @@ purchase_stock / purchase.order.line / propagate_date_minimum_delta (intege # DONE: post-migration: done similar as done in stock module purchase_stock / purchase.order.line / qty_received_method (False) : NEW selection_keys: ['manual', 'stock_moves'], mode: modify -# NOTHING TO DO: handled in purchase module +# DONE: post-migration: filled proper lines with the new method ---XML records in module 'purchase_stock'--- DEL ir.ui.menu: purchase_stock.menu_action_picking_tree_in_move diff --git a/addons/purchase_stock/migrations/13.0.1.2/post-migration.py b/addons/purchase_stock/migrations/13.0.1.2/post-migration.py index da5e86e9ef5..edd5bedf74d 100644 --- a/addons/purchase_stock/migrations/13.0.1.2/post-migration.py +++ b/addons/purchase_stock/migrations/13.0.1.2/post-migration.py @@ -1,4 +1,5 @@ # Copyright 2020 ForgeFlow +# Copyright 2021 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openupgradelib import openupgrade @@ -9,8 +10,7 @@ def fix_purchase_order_line_propagate_cancel(env): UPDATE purchase_order_line pol SET propagate_cancel = FALSE FROM stock_move sm - WHERE sm.purchase_line_id = pol.id AND sm.propagate_cancel = FALSE - """ + WHERE sm.purchase_line_id = pol.id AND NOT sm.propagate_cancel""" ) @@ -38,7 +38,21 @@ def fill_propagate_date_minimum_delta(env): ) +def fill_purchase_order_line__qty_received_method(env): + """Set qty_delivered_method = 'stock_moves' on proper lines.""" + openupgrade.logged_query( + env.cr, """ + UPDATE purchase_order_line pol + SET qty_received_method = 'stock_moves', qty_received_manual = 0 + FROM product_product pp + LEFT JOIN product_template pt ON pp.product_tmpl_id = pt.id + WHERE pol.product_id = pp.id AND pol.display_type IS NULL + AND pt.type IN ('consu', 'product')""" + ) + + @openupgrade.migrate() def migrate(env, version): fix_purchase_order_line_propagate_cancel(env) fill_propagate_date_minimum_delta(env) + fill_purchase_order_line__qty_received_method(env)