From e56fb6960d1a6afa7271631da2a565eab168cede Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 22 Apr 2020 11:13:05 +0200 Subject: [PATCH] [MIG] purchase --- .../migrations/13.0.1.2/noupdate_changes.xml | 6 +- .../13.0.1.2/openupgrade_analysis_work.txt | 71 ++++++++++++++++++ .../migrations/13.0.1.2/post-migration.py | 72 +++++++++++++++++++ .../migrations/13.0.1.2/pre-migration.py | 34 +++++++++ .../openupgrade/doc/source/modules120-130.rst | 2 +- 5 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt create mode 100644 addons/purchase/migrations/13.0.1.2/post-migration.py create mode 100644 addons/purchase/migrations/13.0.1.2/pre-migration.py diff --git a/addons/purchase/migrations/13.0.1.2/noupdate_changes.xml b/addons/purchase/migrations/13.0.1.2/noupdate_changes.xml index abfcb054d567..e9c0974ea986 100644 --- a/addons/purchase/migrations/13.0.1.2/noupdate_changes.xml +++ b/addons/purchase/migrations/13.0.1.2/noupdate_changes.xml @@ -15,7 +15,7 @@ ['|',('company_id','=',False),('company_id', 'in', company_ids)] - - P - + + + diff --git a/addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt b/addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt new file mode 100644 index 000000000000..57fa0d7ce297 --- /dev/null +++ b/addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt @@ -0,0 +1,71 @@ +---Models in module 'purchase'--- +---Fields in module 'purchase'--- +purchase / account.invoice / purchase_id (many2one) : DEL relation: purchase.order +purchase / account.move / purchase_id (many2one) : NEW relation: purchase.order +# NOTHING TO DO: the new field becomes non stored + +purchase / account.invoice / vendor_bill_purchase_id (many2one): DEL relation: purchase.bill.union +purchase / account.move / purchase_vendor_bill_id (many2one): NEW relation: purchase.bill.union +# NOTHING TO DO: the new field becomes non stored + +purchase / account.invoice.line / purchase_line_id (many2one) : DEL relation: purchase.order.line +purchase / account.move.line / purchase_line_id (many2one) : NEW relation: purchase.order.line +purchase / purchase.order.line / invoice_lines (one2many) : relation is now 'account.move.line' ('account.invoice.line') [nothing to do] +# DONE: post-migration: mapping + +purchase / purchase.order / currency_rate (float) : NEW isfunction: function, stored +# NOTHING TO DO: new field to compute every PO in the company currency + +purchase / purchase.order / date_approve (date) : type is now 'datetime' ('date') +# DONE: handled the change of type from 'date' to 'datetime' + +purchase / purchase.order / date_planned (datetime) : not a function anymore +# NOTHING TO DO: Previously, "date_planned" was computed and set while the creation of PO, now field will be empty until user fills it + +purchase / purchase.order / invoice_ids (many2many) : relation is now 'account.move' ('account.invoice') [nothing to do] +purchase / purchase.order / invoice_ids (many2many) : table is now 'account_move_purchase_order_rel' ('account_invoice_purchase_order_rel') +# DONE: post-migration: fill account_move_purchase_order_rel table + +purchase / purchase.order.line / display_type (selection) : NEW selection_keys: ['line_note', 'line_section'], hasdefault +# NOTHING TO DO: new feature: add section and note on order line + +purchase / purchase.order.line / qty_received (float) : now a function +purchase / purchase.order.line / qty_received_manual (float) : NEW +purchase / purchase.order.line / qty_received_method (selection): NEW selection_keys: ['manual'], isfunction: function, stored +# DONE: pre/post/end-migration: done the same as done in v12 sale module for qty_delivered* + +---XML records in module 'purchase'--- +DEL ir.actions.act_window: purchase.action_invoice_pending +DEL ir.actions.act_window: purchase.purchase_open_invoice +DEL ir.actions.act_window.view: purchase.action_invoice__supplier_tree1_view2 +DEL ir.actions.act_window.view: purchase.action_invoice_supplier_tree1_view1 +# NOTHING TO DO: noupdate=0 records + +NEW ir.model.access: purchase.access_account_move_purchase +DEL ir.model.access: purchase.access_account_invoice_purchase +NEW ir.model.access: purchase.access_account_move_purchase_manager +DEL ir.model.access: purchase.access_account_invoice_purchase_manager +# DONE: pre-migration: renamed xmlids + +DEL ir.model.access: purchase.access_account_invoice_line_purchase +DEL ir.model.access: purchase.access_account_invoice_line_purchase_manager +DEL ir.model.access: purchase.access_account_invoice_tax_purchase +DEL ir.model.access: purchase.access_product_price_history_purchase_manager +DEL ir.model.access: purchase.access_product_price_history_purchase_user +# NOTHING TO DO: noupdate=0 records + +NEW ir.module.category: base.module_category_operations_purchase (noupdate) +# NOTHING TO DO: New noupdate=1 records + +NEW ir.ui.menu: purchase.menu_purchase_products +NEW ir.ui.menu: purchase.menu_report_purchase +DEL ir.ui.menu: purchase.menu_procurement_management_pending_invoice +DEL ir.ui.menu: purchase.menu_purchase_control +NEW ir.ui.view: purchase.purchase_order_view_activity +NEW ir.ui.view: purchase.purchase_order_view_search +NEW ir.ui.view: purchase.purchase_order_view_tree +NEW ir.ui.view: purchase.view_move_form_inherit_purchase +DEL ir.ui.view: purchase.view_invoice_line_form_inherit_purchase +DEL ir.ui.view: purchase.view_invoice_supplier_purchase_form +DEL res.groups: purchase.group_manage_vendor_price +# NOTHING TO DO: noupdate=0 records diff --git a/addons/purchase/migrations/13.0.1.2/post-migration.py b/addons/purchase/migrations/13.0.1.2/post-migration.py new file mode 100644 index 000000000000..3f3a03979664 --- /dev/null +++ b/addons/purchase/migrations/13.0.1.2/post-migration.py @@ -0,0 +1,72 @@ +# Copyright 2020 ForgeFlow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +def move_fields_from_invoice_to_moves(env): + openupgrade.logged_query( + env.cr, """ + UPDATE account_move_line aml + SET purchase_line_id = ail.purchase_line_id + FROM account_invoice_line ail + WHERE aml.old_invoice_line_id = ail.id AND + ail.purchase_line_id IS NOT NULL""" + ) + + +def change_type_purchase_order_date_approve(env): + openupgrade.logged_query( + env.cr, """ + UPDATE purchase_order + SET date_approve = {date}::TIMESTAMP AT TIME ZONE 'UTC' + WHERE {date} IS NOT NULL + """.format(date=openupgrade.get_legacy_name('date_approve')) + ) + + +def fill_account_move_purchase_order_rel_table(env): + openupgrade.logged_query( + env.cr, """ + INSERT INTO account_move_purchase_order_rel ( + purchase_order_id, account_move_id) + SELECT rel.purchase_order_id, am.id + FROM account_invoice_purchase_order_rel rel + JOIN account_invoice ai ON rel.account_invoice_id = ai.id + JOIN account_move am ON am.old_invoice_id = ai.id + ON CONFLICT DO NOTHING""" + ) + + +def fill_purchase_order_line_qty_received_method(cr): + if openupgrade.column_exists(cr, 'purchase_order', 'picking_type_id'): + # purchase_stock is installed + # set qty_delivered_method = 'stock_moves' + openupgrade.logged_query( + cr, """ + UPDATE purchase_order_line pol + SET qty_received_method = 'stock_moves', qty_received_manual = NULL + 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')""" + ) + # set qty_received_method = 'manual' + openupgrade.logged_query( + cr, """ + UPDATE purchase_order_line pol + SET qty_received_method = 'manual' + FROM product_product pp + LEFT JOIN product_template pt ON pp.product_tmpl_id = pt.id + WHERE pol.qty_received_method IS NULL AND pol.product_id = pp.id + AND pt.type IN ('consu', 'service')""" + ) + + +@openupgrade.migrate() +def migrate(env, version): + move_fields_from_invoice_to_moves(env) + change_type_purchase_order_date_approve(env) + fill_account_move_purchase_order_rel_table(env) + fill_purchase_order_line_qty_received_method(env.cr) + openupgrade.load_data( + env.cr, "purchase", "migrations/13.0.1.2/noupdate_changes.xml") diff --git a/addons/purchase/migrations/13.0.1.2/pre-migration.py b/addons/purchase/migrations/13.0.1.2/pre-migration.py new file mode 100644 index 000000000000..0a5a97b2a310 --- /dev/null +++ b/addons/purchase/migrations/13.0.1.2/pre-migration.py @@ -0,0 +1,34 @@ +# Copyright 2020 ForgeFlow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_column_copies = { + 'purchase_order_line': [ + ('qty_received', 'qty_received_manual', None), + ], +} + +_column_renames = { + 'purchase_order': [ + ('date_approve', None), + ], +} + +_xmlid_renames = [ + ("purchase.access_account_invoice_purchase", + "purchase.access_account_move_purchase"), + ("purchase.access_account_invoice_purchase_manager", + "purchase.access_account_move_purchase_manager"), +] + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.copy_columns(env.cr, _column_copies) + openupgrade.rename_columns(env.cr, _column_renames) + openupgrade.rename_xmlids(env.cr, _xmlid_renames) + openupgrade.logged_query( + env.cr, """ + ALTER TABLE purchase_order_line + ADD COLUMN qty_received_method varchar""", + ) diff --git a/odoo/openupgrade/doc/source/modules120-130.rst b/odoo/openupgrade/doc/source/modules120-130.rst index 10119d3012ea..73d7fee1b4b4 100644 --- a/odoo/openupgrade/doc/source/modules120-130.rst +++ b/odoo/openupgrade/doc/source/modules120-130.rst @@ -537,7 +537,7 @@ missing in the new release are marked with |del|. +----------------------------------------------+-------------------------------------------------+ |project_timesheet_holidays | | +----------------------------------------------+-------------------------------------------------+ -|purchase | | +|purchase | Done | +----------------------------------------------+-------------------------------------------------+ |purchase_mrp | | +----------------------------------------------+-------------------------------------------------+