-
-
Notifications
You must be signed in to change notification settings - Fork 785
[16.0][OU-ADD] stock: migration #3966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env.cr, "stock", "16.0.1.1/noupdate_changes.xml") |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,131 @@ | ||||||||||||||||||
| from openupgradelib import openupgrade | ||||||||||||||||||
|
|
||||||||||||||||||
| _models_renames = [ | ||||||||||||||||||
| ("stock.location.route", "stock.route"), | ||||||||||||||||||
| ("stock.production.lot", "stock.lot"), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| _tables_renames = [ | ||||||||||||||||||
| ("stock_location_route", "stock_route"), | ||||||||||||||||||
| ("stock_production_lot", "stock_lot"), | ||||||||||||||||||
| ("stock_location_route_categ", "stock_route_categ"), | ||||||||||||||||||
| ("stock_location_route_packaging", "stock_route_packaging"), | ||||||||||||||||||
| ("stock_location_route_move", "stock_route_move"), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| _columns_renames = { | ||||||||||||||||||
| "stock_move_line": [ | ||||||||||||||||||
| ("product_qty", "reserved_qty"), | ||||||||||||||||||
| ("product_uom_qty", "reserved_uom_qty"), | ||||||||||||||||||
| ], | ||||||||||||||||||
| "stock_rule": [ | ||||||||||||||||||
| ("location_id", "location_dest_id"), | ||||||||||||||||||
| ], | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| _fields_renames = [ | ||||||||||||||||||
| ("stock.move.line", "stock_move_line", "product_qty", "reserved_qty"), | ||||||||||||||||||
| ("stock.move.line", "stock_move_line", "product_uom_qty", "reserved_uom_qty"), | ||||||||||||||||||
| ("stock.rule", "stock_rule", "location_id", "location_dest_id"), | ||||||||||||||||||
| ("stock.picking", "stock_picking", "move_lines", "move_ids"), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _update_stock_quant_storage_category_id(env): | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| ALTER TABLE stock_quant | ||||||||||||||||||
| ADD COLUMN IF NOT EXISTS storage_category_id INTEGER | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| UPDATE stock_quant | ||||||||||||||||||
| SET storage_category_id = stock_location.storage_category_id | ||||||||||||||||||
| FROM stock_location | ||||||||||||||||||
| WHERE stock_quant.location_id = stock_location.id | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _update_sol_product_category_name(env): | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| ALTER TABLE stock_move_line | ||||||||||||||||||
| ADD COLUMN IF NOT EXISTS product_category_name CHARACTER VARYING | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| UPDATE stock_move_line AS sml | ||||||||||||||||||
| SET product_category_name = category.complete_name | ||||||||||||||||||
| FROM product_product AS product | ||||||||||||||||||
| JOIN product_template AS product_tmpl | ||||||||||||||||||
| ON product_tmpl.id = product.product_tmpl_id | ||||||||||||||||||
| JOIN product_category AS category | ||||||||||||||||||
| ON category.id = product_tmpl.categ_id | ||||||||||||||||||
| WHERE sml.product_id = product.id | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _compute_stock_location_replenish_location(env): | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| ALTER TABLE stock_location | ||||||||||||||||||
| ADD COLUMN IF NOT EXISTS replenish_location BOOLEAN | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| WITH location_info as ( | ||||||||||||||||||
| SELECT sl.id as id, | ||||||||||||||||||
| CASE | ||||||||||||||||||
| WHEN sl.usage = 'internal' AND sl.id = sw.lot_stock_id THEN True | ||||||||||||||||||
| ELSE FALSE | ||||||||||||||||||
|
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| END as replenish_location_status | ||||||||||||||||||
| FROM stock_location sl | ||||||||||||||||||
| LEFT JOIN stock_warehouse sw | ||||||||||||||||||
| ON sw.id = sl.warehouse_id | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The warehouse is a computed value that is new being stored, I tried adding the field using
Is there a reason this cannot be moved the the post migration? allowing the module to calculate the values for us? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This left join does not work because the field does not exist and if it does exist it will be empty. you have to change it to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can confirm this fix |
||||||||||||||||||
| ) | ||||||||||||||||||
| UPDATE stock_location sl | ||||||||||||||||||
| SET replenish_location = info.replenish_location_status | ||||||||||||||||||
| FROM location_info info | ||||||||||||||||||
| WHERE sl.id = info.id | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _update_stock_quant_package_pack_date(env): | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| ALTER TABLE stock_quant_package | ||||||||||||||||||
| ADD COLUMN IF NOT EXISTS pack_date DATE | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
| openupgrade.logged_query( | ||||||||||||||||||
| env.cr, | ||||||||||||||||||
| """ | ||||||||||||||||||
| UPDATE stock_quant_package | ||||||||||||||||||
| SET pack_date = DATE(create_date) | ||||||||||||||||||
| """, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| @openupgrade.migrate() | ||||||||||||||||||
| def migrate(env, version): | ||||||||||||||||||
| openupgrade.rename_tables(env.cr, _tables_renames) | ||||||||||||||||||
| openupgrade.rename_models(env.cr, _models_renames) | ||||||||||||||||||
| openupgrade.rename_fields(env, _fields_renames) | ||||||||||||||||||
| openupgrade.rename_columns(env.cr, _columns_renames) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already covered by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confirmed, reserved_qty is renamed by openupgrade.rename_fields(env, _fields_renames) and after by openupgrade.rename_columns(env.cr, _columns_renames)
Comment on lines
+124
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the order of execution of methods is not correct and gives errors
Suggested change
|
||||||||||||||||||
| _update_stock_quant_storage_category_id(env) | ||||||||||||||||||
| _update_stock_quant_package_pack_date(env) | ||||||||||||||||||
| _update_sol_product_category_name(env) | ||||||||||||||||||
| _compute_stock_location_replenish_location(env) | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| ---Models in module 'stock'--- | ||
| obsolete model stock.location.route | ||
| obsolete model stock.production.lot | ||
| # DONE: pre-migration: renamed model | ||
|
|
||
| new model lot.label.layout [transient] | ||
| new model picking.label.type [transient] | ||
| # NOTHING TO DO | ||
|
|
||
| new model stock.lot | ||
| # DONE: pre-migration: renamed model | ||
|
|
||
| new model stock.replenishment.option [transient] | ||
| # NOTHING TO DO | ||
|
|
||
| new model stock.route | ||
| # DONE: pre-migration: renamed model | ||
|
|
||
| ---Fields in module 'stock'--- | ||
| stock / barcode.rule / type (False) : selection_keys is now '['alias', 'expiration_date', 'location', 'location_dest', 'lot', 'pack_date', 'package', 'package_type', 'product', 'quantity', 'use_date', 'weight']' ('['alias', 'expiration_date', 'location', 'location_dest', 'lot', 'package', 'package_type', 'packaging_date', 'product', 'quantity', 'use_date', 'weight']') | ||
| # NOTHING TO DO: no keys change in module | ||
|
|
||
| stock / product.category / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / product.category / route_ids (many2many) : table is now 'stock_route_categ' ('stock_location_route_categ') | ||
| # DONE: pre-migration: renamed table | ||
|
|
||
| stock / product.category / total_route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / product.packaging / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / product.packaging / route_ids (many2many) : table is now 'stock_route_packaging' ('stock_location_route_packaging') | ||
| # DONE: pre-migration: renamed table | ||
|
|
||
| stock / product.product / route_from_categ_ids (many2many): relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / product.product / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / product.template / detailed_type (False) : selection_keys is now '['consu', 'product', 'service']' ('['consu', 'gift', 'product', 'service']') | ||
| # NOTHING TO DO: no keys changhe in module | ||
|
|
||
| stock / product.template / route_from_categ_ids (many2many): relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / product.template / route_from_categ_ids (many2many): table is now 'stock.route' ('stock.location.route') | ||
| # NOTHING TO DO: related fields | ||
|
|
||
| stock / product.template / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.location / replenish_location (boolean) : NEW hasdefault: compute | ||
| #DONE: pre-migration: create column and precompute values | ||
|
|
||
| stock / stock.location / warehouse_id (many2one) : is now stored | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.location.route / active (boolean) : DEL | ||
| stock / stock.location.route / categ_ids (many2many) : DEL relation: product.category | ||
| stock / stock.location.route / company_id (many2one) : DEL relation: res.company | ||
| stock / stock.location.route / name (char) : DEL required | ||
| stock / stock.location.route / packaging_ids (many2many) : DEL relation: product.packaging | ||
| stock / stock.location.route / packaging_selectable (boolean): DEL | ||
| stock / stock.location.route / product_categ_selectable (boolean): DEL | ||
| stock / stock.location.route / product_ids (many2many) : DEL relation: product.template | ||
| stock / stock.location.route / product_selectable (boolean) : DEL | ||
| stock / stock.location.route / rule_ids (one2many) : DEL relation: stock.rule | ||
| stock / stock.location.route / sequence (integer) : DEL | ||
| stock / stock.location.route / supplied_wh_id (many2one) : DEL relation: stock.warehouse | ||
| stock / stock.location.route / supplier_wh_id (many2one) : DEL relation: stock.warehouse | ||
| stock / stock.location.route / warehouse_ids (many2many) : DEL relation: stock.warehouse | ||
| stock / stock.location.route / warehouse_selectable (boolean): DEL | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.lot / activity_ids (one2many) : NEW relation: mail.activity | ||
| stock / stock.lot / company_id (many2one) : NEW relation: res.company, required | ||
| stock / stock.lot / message_follower_ids (one2many): NEW relation: mail.followers | ||
| stock / stock.lot / message_ids (one2many) : NEW relation: mail.message | ||
| stock / stock.lot / message_main_attachment_id (many2one): NEW relation: ir.attachment | ||
| stock / stock.lot / name (char) : NEW required, hasdefault: default | ||
| stock / stock.lot / note (html) : NEW | ||
| stock / stock.lot / product_id (many2one) : NEW relation: product.product, required | ||
| stock / stock.lot / product_uom_id (many2one) : NEW relation: uom.uom, isrelated: related, stored | ||
| stock / stock.lot / quant_ids (one2many) : NEW relation: stock.quant | ||
| stock / stock.lot / ref (char) : NEW | ||
| stock / stock.lot / website_message_ids (one2many): NEW relation: mail.message | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.move / lot_ids (many2many) : relation is now 'stock.lot' ('stock.production.lot') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.move / quantity_done (float) : is now stored | ||
| # NOTHING TO DO: handle by ORM, can improve in the future | ||
|
|
||
| stock / stock.move / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.move / route_ids (many2many) : table is now 'stock_route_move' ('stock_location_route_move') | ||
| # DONE: pre-migration: renamed table | ||
|
|
||
| stock / stock.move.line / lot_id (many2one) : relation is now 'stock.lot' ('stock.production.lot') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.move.line / product_category_name (char) : NEW isrelated: related, stored | ||
| # DONE: pre-migratiion: create column and fill values | ||
|
|
||
| stock / stock.move.line / product_qty (float) : DEL | ||
| stock / stock.move.line / product_uom_qty (float) : DEL required | ||
| stock / stock.move.line / reserved_qty (float) : NEW isfunction: function, stored | ||
| stock / stock.move.line / reserved_uom_qty (float) : NEW required, hasdefault: default | ||
| # DONE: pre-migration: rename columns | ||
|
|
||
| stock / stock.package.type / base_weight (float) : NEW | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.picking / move_ids (one2many) : NEW relation: stock.move | ||
| stock / stock.picking / move_lines (one2many) : DEL relation: stock.move | ||
| # DONE: pre-migration: rename fields | ||
|
|
||
| stock / stock.picking.type / auto_show_reception_report (boolean): NEW | ||
| stock / stock.picking.type / create_backorder (selection) : NEW required, selection_keys: ['always', 'ask', 'never'], hasdefault: default | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.production.lot / activity_ids (one2many) : DEL relation: mail.activity | ||
| stock / stock.production.lot / company_id (many2one) : DEL relation: res.company, required | ||
| stock / stock.production.lot / message_follower_ids (one2many): DEL relation: mail.followers | ||
| stock / stock.production.lot / message_ids (one2many) : DEL relation: mail.message | ||
| stock / stock.production.lot / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| stock / stock.production.lot / name (char) : DEL required | ||
| stock / stock.production.lot / note (html) : DEL | ||
| stock / stock.production.lot / product_id (many2one) : DEL relation: product.product, required | ||
| stock / stock.production.lot / product_uom_id (many2one) : DEL relation: uom.uom | ||
| stock / stock.production.lot / quant_ids (one2many) : DEL relation: stock.quant | ||
| stock / stock.production.lot / ref (char) : DEL | ||
| stock / stock.production.lot / website_message_ids (one2many): DEL relation: mail.message | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.quant / lot_id (many2one) : relation is now 'stock.lot' ('stock.production.lot') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.quant / storage_category_id (many2one): NEW relation: stock.storage.category, isrelated: related, stored | ||
| # DONE: pre-migration: create column and fill values | ||
|
|
||
| stock / stock.quant.package / pack_date (date) : NEW hasdefault: default | ||
| # DONE: pre-migration: create column and fill values | ||
|
|
||
| stock / stock.route / active (boolean) : NEW hasdefault: default | ||
| stock / stock.route / categ_ids (many2many) : NEW relation: product.category | ||
| stock / stock.route / company_id (many2one) : NEW relation: res.company, hasdefault: default | ||
| stock / stock.route / name (char) : NEW required | ||
| stock / stock.route / packaging_ids (many2many) : NEW relation: product.packaging | ||
| stock / stock.route / packaging_selectable (boolean): NEW | ||
| stock / stock.route / product_categ_selectable (boolean): NEW | ||
| stock / stock.route / product_ids (many2many) : NEW relation: product.template | ||
| stock / stock.route / product_selectable (boolean) : NEW hasdefault: default | ||
| stock / stock.route / rule_ids (one2many) : NEW relation: stock.rule | ||
| stock / stock.route / sequence (integer) : NEW hasdefault: default | ||
| stock / stock.route / supplied_wh_id (many2one) : NEW relation: stock.warehouse | ||
| stock / stock.route / supplier_wh_id (many2one) : NEW relation: stock.warehouse | ||
| stock / stock.route / warehouse_ids (many2many) : NEW relation: stock.warehouse | ||
| stock / stock.route / warehouse_selectable (boolean): NEW | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.rule / location_dest_id (many2one) : NEW relation: stock.location, required | ||
| stock / stock.rule / location_id (many2one) : DEL relation: stock.location, required | ||
| # DONE: pre-migration: renamed columns | ||
|
|
||
| stock / stock.rule / route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.scrap / lot_id (many2one) : relation is now 'stock.lot' ('stock.production.lot') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| stock / stock.scrap / scrap_qty (float) : now a function | ||
| # NOTHING TO DO: handle by ORM | ||
|
|
||
| stock / stock.warehouse / crossdock_route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.warehouse / delivery_route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.warehouse / reception_route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.warehouse / resupply_route_ids (one2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.warehouse / route_ids (many2many) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| stock / stock.warehouse.orderpoint / route_id (many2one) : relation is now 'stock.route' ('stock.location.route') [nothing to do] | ||
| # NOTHING TO DO | ||
|
|
||
| ---XML records in module 'stock'--- | ||
| NEW ir.actions.act_window: stock.action_product_stock_view | ||
| DEL ir.actions.act_window: stock.report_stock_quantity_action | ||
| DEL ir.actions.act_window: stock.report_stock_quantity_action_product | ||
| NEW ir.actions.report: stock.action_report_picking_packages | ||
| DEL ir.actions.report: stock.stock_replenishment_report_product_product_action | ||
| DEL ir.actions.report: stock.stock_replenishment_report_product_template_action | ||
| NEW ir.actions.server: stock.action_revert_inventory_adjustment | ||
| NEW ir.model.access: stock.access_product_tag_stock_manager | ||
| NEW ir.model.access: stock.access_stock_lot_label_layout_user | ||
| NEW ir.model.access: stock.access_stock_lot_user | ||
| NEW ir.model.access: stock.access_stock_picking_label_type_user | ||
| NEW ir.model.access: stock.access_stock_replenish_option | ||
| DEL ir.model.access: stock.access_stock_production_lot_user | ||
| NEW ir.ui.menu: stock.menu_product_stock | ||
| DEL ir.ui.menu: stock.menu_forecast_inventory | ||
| DEL ir.ui.menu: stock.menu_storage_categoty_capacity_config | ||
| NEW ir.ui.view: stock.duplicated_sn_warning | ||
| NEW ir.ui.view: stock.lot_label_layout_form_picking | ||
| NEW ir.ui.view: stock.picking_label_type_form | ||
| NEW ir.ui.view: stock.product_product_stock_tree | ||
| NEW ir.ui.view: stock.product_search_form_view_stock_report | ||
| NEW ir.ui.view: stock.replenishment_option_tree_view | ||
| NEW ir.ui.view: stock.replenishment_option_warning_view | ||
| NEW ir.ui.view: stock.report_picking_packages | ||
| DEL ir.ui.view: stock.stock_report_view_search | ||
| DEL ir.ui.view: stock.view_warehouse_orderpoint_tree_editable_config | ||
| NEW res.groups: stock.group_stock_lot_print_gs1 | ||
| DEL res.groups: stock.group_auto_reception_report | ||
| DEL stock.location.route: stock.route_warehouse0_mto (noupdate) | ||
| NEW stock.route: stock.route_warehouse0_mto (noupdate) | ||
| # NOTHINGH TO DO |
Uh oh!
There was an error while loading. Please reload this page.