-
-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2310 from ForgeFlow/13.0-mig-purchase-scripts
[13.0][MIG] purchase
- Loading branch information
Showing
6 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
---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. Performance is not bad on this computed, so we keep it for now. | ||
|
||
purchase / purchase.order / date_approve (date) : type is now 'datetime' ('date') | ||
# DONE: pre-migration: Rename column for preserving data | ||
# DONE: post-migration: Take the value from the mail.tracking.value that adds the chatter | ||
|
||
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 the same as done in v12 sale module for qty_delivered | ||
# DONE: pre-migration: Copy column qty_received > qty_received_manual | ||
# DONE: post-migration: Adjust method to manual according current compute method | ||
|
||
---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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2020 ForgeFlow <http://www.forgeflow.com> | ||
# 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 po | ||
SET date_approve = mm.date | ||
FROM mail_message mm | ||
WHERE mm.subtype_id = %s | ||
AND mm.model = 'purchase.order' | ||
AND mm.res_id = po.id""", | ||
(env.ref('purchase.mt_rfq_approved').id, ), | ||
) | ||
|
||
|
||
def fill_account_move_purchase_order_rel_table(env): | ||
# Remove temp table and re-create m2m table through ORM method | ||
openupgrade.logged_query(env.cr, "DROP TABLE account_move_purchase_order_rel") | ||
Move = env["purchase.order"] | ||
Move._fields["invoice_ids"].update_db(Move, False) | ||
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_move am ON am.old_invoice_id = rel.account_invoice_id | ||
ON CONFLICT DO NOTHING""" | ||
) | ||
|
||
|
||
def fill_purchase_order_line_qty_received_method(cr): | ||
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.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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2020 ForgeFlow <http://www.forgeflow.com> | ||
# 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""", | ||
) | ||
# Add temporary table for avoiding the automatic launch of the compute method | ||
openupgrade.logged_query( | ||
env.cr, "CREATE TABLE account_move_purchase_order_rel (temp INTEGER)", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters