Skip to content

Commit

Permalink
[MIG] purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Feb 16, 2021
1 parent abb3c84 commit e56fb69
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 4 deletions.
6 changes: 3 additions & 3 deletions addons/purchase/migrations/13.0.1.2/noupdate_changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<record id="purchase_order_report_comp_rule" model="ir.rule">
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
<record id="seq_purchase_order" model="ir.sequence">
<field name="prefix">P</field>
</record>
<!-- <record id="seq_purchase_order" model="ir.sequence">-->
<!-- <field name="prefix">P</field>-->
<!-- </record>-->
</odoo>
71 changes: 71 additions & 0 deletions addons/purchase/migrations/13.0.1.2/openupgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -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
72 changes: 72 additions & 0 deletions addons/purchase/migrations/13.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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
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")
34 changes: 34 additions & 0 deletions addons/purchase/migrations/13.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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""",
)
2 changes: 1 addition & 1 deletion odoo/openupgrade/doc/source/modules120-130.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ missing in the new release are marked with |del|.
+----------------------------------------------+-------------------------------------------------+
|project_timesheet_holidays | |
+----------------------------------------------+-------------------------------------------------+
|purchase | |
|purchase | Done |
+----------------------------------------------+-------------------------------------------------+
|purchase_mrp | |
+----------------------------------------------+-------------------------------------------------+
Expand Down

0 comments on commit e56fb69

Please sign in to comment.