From dc2b11ed4bf36fd7821a067a4e165f54caa51342 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 13:02:57 +0200 Subject: [PATCH 01/27] First part of product migration analysis. XML ID migration complete --- .../migrations/8.0.1.1/modified_data.xml | 25 ++++ .../8.0.1.1/openupgrade_analysis_WORK.txt | 115 ++++++++++++++++++ .../8.0.1.1/post-modified_noupdate_data.py | 6 + 3 files changed, 146 insertions(+) create mode 100644 addons/product/migrations/8.0.1.1/modified_data.xml create mode 100644 addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt create mode 100644 addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py diff --git a/addons/product/migrations/8.0.1.1/modified_data.xml b/addons/product/migrations/8.0.1.1/modified_data.xml new file mode 100644 index 000000000000..93c05c245d06 --- /dev/null +++ b/addons/product/migrations/8.0.1.1/modified_data.xml @@ -0,0 +1,25 @@ + + + + ['|',('company_id','=',False),('company_id','=',user.company_id.id)] + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + + + + 1000 + + All + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + + + + + + diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt new file mode 100644 index 000000000000..fdc2032cbb89 --- /dev/null +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -0,0 +1,115 @@ +---Fields in module 'product'--- +product / product.attribute / name (char) : NEW required: required +product / product.attribute / value_ids (one2many) : NEW relation: product.attribute.value +product / product.attribute.line / attribute_id (many2one) : NEW relation: product.attribute, required: required +product / product.attribute.line / product_tmpl_id (many2one) : NEW relation: product.template, required: required +product / product.attribute.line / value_ids (many2many) : NEW relation: product.attribute.value +product / product.attribute.price / price_extra (float) : NEW +product / product.attribute.price / product_tmpl_id (many2one) : NEW relation: product.template, required: required +product / product.attribute.price / value_id (many2one) : NEW relation: product.attribute.value, required: required +product / product.attribute.value / attribute_id (many2one) : NEW relation: product.attribute, required: required +product / product.attribute.value / name (char) : NEW required: required +product / product.attribute.value / price_ids (one2many) : NEW relation: product.attribute.price +product / product.attribute.value / product_ids (many2many) : NEW relation: product.product +product / product.attribute.value / sequence (integer) : NEW +product / product.packaging / height (float) : DEL +product / product.packaging / length (float) : DEL +product / product.packaging / ul_container (many2one) : NEW relation: product.ul +product / product.packaging / weight_ul (float) : DEL +product / product.packaging / width (float) : DEL +product / product.price.history / company_id (many2one) : NEW relation: res.company, required: required, req_default: function +product / product.price.history / cost (float) : NEW +product / product.price.history / datetime (datetime) : NEW +product / product.price.history / product_template_id (many2one): NEW relation: product.template, required: required +product / product.product / attribute_value_ids (many2many): NEW relation: product.attribute.value +product / product.product / color (integer) : DEL +product / product.product / image (binary) : now a function +product / product.product / image_variant (binary) : NEW +product / product.product / incoming_qty (float) : module is now 'stock' ('product') +product / product.product / message_last_post (datetime) : NEW +product / product.product / outgoing_qty (float) : module is now 'stock' ('product') +product / product.product / price_extra (float) : now a function +product / product.product / price_margin (float) : DEL +product / product.product / qty_available (float) : module is now 'stock' ('product') +product / product.product / variants (char) : DEL +product / product.product / virtual_available (float) : module is now 'stock' ('product') +product / product.supplierinfo / product_id (many2one) : DEL relation: product.template, required: required +product / product.supplierinfo / product_tmpl_id (many2one) : NEW relation: product.template, required: required +product / product.template / active (boolean) : NEW +product / product.template / attribute_line_ids (one2many) : NEW relation: product.attribute.line +product / product.template / color (integer) : NEW +product / product.template / cost_method (selection) : module is now 'stock_account' ('product') +product / product.template / cost_method (selection) : now a function +product / product.template / cost_method (selection) : selection_keys is now '['average', 'real', 'standard']' ('['average', 'standard']') +product / product.template / image (binary) : NEW +product / product.template / message_ids (one2many) : NEW relation: mail.message +product / product.template / message_last_post (datetime) : NEW +product / product.template / packaging (one2many) : NEW relation: product.packaging +product / product.template / produce_delay (float) : DEL +product / product.template / product_variant_ids (one2many): NEW relation: product.product, required: required +product / product.template / standard_price (float) : now a function +product / product.ul / height (float) : NEW +product / product.ul / length (float) : NEW +product / product.ul / weight (float) : NEW +product / product.ul / width (float) : NEW + + + +---XML records in module 'product'--- +NEW ir.actions.act_window: product.product_template_action +NEW ir.actions.act_window: product.product_variant_action +NEW ir.actions.act_window: product.variants_template_action +DEL ir.actions.act_window: product.product_normal_action_puchased +DEL ir.actions.act_window: product.product_template_action_tree +DEL ir.actions.act_window.view: product.open_view_product_form1 +DEL ir.actions.act_window.view: product.open_view_product_kanban1 +DEL ir.actions.act_window.view: product.open_view_product_tree1 +NEW ir.actions.report.xml: product.action_report_pricelist +DEL ir.actions.report.xml: product.report_product_pricelist +## ir.actions: the doc says we can safely ignore these + +NEW ir.model.access: product.access_product_attribute +NEW ir.model.access: product.access_product_attribute_line +NEW ir.model.access: product.access_product_attribute_line_sale_manager +NEW ir.model.access: product.access_product_attribute_price +NEW ir.model.access: product.access_product_attribute_price_sale_manager +NEW ir.model.access: product.access_product_attribute_sale_manager +NEW ir.model.access: product.access_product_attribute_value +NEW ir.model.access: product.access_product_attribute_value_sale_manager +NEW ir.model.access: product.access_product_price_history_employee +## access rules: let them be for now + + +NEW ir.ui.menu: product.menu_product_template_action +NEW ir.ui.view: product.product_template_form_view_variant_button +NEW ir.ui.view: product.product_template_kanban_view +NEW ir.ui.view: product.product_template_kanban_view_variant_button +NEW ir.ui.view: product.product_template_search_view +NEW ir.ui.view: product.report_pricelist +NEW ir.ui.view: product.variants_template_tree_view +DEL ir.ui.view: product.product_variant_form_view +DEL ir.ui.view: product.product_variant_tree_view +DEL ir.ui.view_sc: product.ir_ui_view_sc_product0 +## ir.ui.* doc says we can ignore + +DEL process.node: product.process_node_product0 +DEL process.node: product.process_node_supplier0 +DEL process.process: product.process_process_productprocess0 +DEL process.transition: product.process_transition_supplierofproduct0 +## process addon removed -> nothing to do + +NEW product.uom: product.product_uom_floz +NEW product.uom: product.product_uom_foot +NEW product.uom: product.product_uom_gal +NEW product.uom: product.product_uom_inch +NEW product.uom: product.product_uom_lb +NEW product.uom: product.product_uom_mile +NEW product.uom: product.product_uom_oz +NEW product.uom: product.product_uom_qt +## great new stuff, std upgrade should work by itself + +DEL res.groups: product.group_costing_method +DEL res.groups: product.group_product_variant +## well... probably nothing to do either... + +## modified no update records listed in modified_data.xml diff --git a/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py b/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py new file mode 100644 index 000000000000..7ea5e631b75f --- /dev/null +++ b/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py @@ -0,0 +1,6 @@ + +import openupgrade + +@openupgrade.migrate +def migrate(cr, version): + openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') From 1252ab41a009e46e765389571061958b943e410b Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:16:57 +0200 Subject: [PATCH 02/27] fix missing dependency in product in v8 --- addons/product/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/__openerp__.py b/addons/product/__openerp__.py index 83ecea958869..469941620e1a 100644 --- a/addons/product/__openerp__.py +++ b/addons/product/__openerp__.py @@ -25,7 +25,7 @@ 'version': '1.1', 'author': 'OpenERP SA', 'category': 'Sales Management', - 'depends': ['base', 'decimal_precision', 'mail'], + 'depends': ['base', 'decimal_precision', 'mail', 'report'], 'demo': [ 'product_demo.xml', 'product_image_demo.xml', From 12403313d61722c8b63d5623c6f194da4fedd382 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:18:10 +0200 Subject: [PATCH 03/27] updated product migration analysis --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 72 ++++++++++++++----- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index fdc2032cbb89..a3522cb16778 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -12,46 +12,84 @@ product / product.attribute.value / name (char) : NEW re product / product.attribute.value / price_ids (one2many) : NEW relation: product.attribute.price product / product.attribute.value / product_ids (many2many) : NEW relation: product.product product / product.attribute.value / sequence (integer) : NEW + +## new model, will be handled by standard migration + + +product / product.packaging / ul_container (many2one) : NEW relation: product.ul product / product.packaging / height (float) : DEL +product / product.ul / height (float) : NEW product / product.packaging / length (float) : DEL -product / product.packaging / ul_container (many2one) : NEW relation: product.ul +product / product.ul / length (float) : NEW product / product.packaging / weight_ul (float) : DEL +product / product.ul / weight (float) : NEW product / product.packaging / width (float) : DEL +product / product.ul / width (float) : NEW +## new relation ul_container, and the dimensions are moved there +## TODO later because rarely used feature + + product / product.price.history / company_id (many2one) : NEW relation: res.company, required: required, req_default: function product / product.price.history / cost (float) : NEW product / product.price.history / datetime (datetime) : NEW product / product.price.history / product_template_id (many2one): NEW relation: product.template, required: required +# new fields -> nothing to do + +product / product.template / attribute_line_ids (one2many) : NEW relation: product.attribute.line product / product.product / attribute_value_ids (many2many): NEW relation: product.attribute.value -product / product.product / color (integer) : DEL -product / product.product / image (binary) : now a function -product / product.product / image_variant (binary) : NEW -product / product.product / incoming_qty (float) : module is now 'stock' ('product') -product / product.product / message_last_post (datetime) : NEW -product / product.product / outgoing_qty (float) : module is now 'stock' ('product') -product / product.product / price_extra (float) : now a function -product / product.product / price_margin (float) : DEL -product / product.product / qty_available (float) : module is now 'stock' ('product') -product / product.product / variants (char) : DEL -product / product.product / virtual_available (float) : module is now 'stock' ('product') +# nothing to do + + product / product.supplierinfo / product_id (many2one) : DEL relation: product.template, required: required product / product.supplierinfo / product_tmpl_id (many2one) : NEW relation: product.template, required: required +# seller_ids moved from product.product to product.template product / product.template / active (boolean) : NEW -product / product.template / attribute_line_ids (one2many) : NEW relation: product.attribute.line +# need to move seller_ids from product.product to product.template + product / product.template / color (integer) : NEW +product / product.product / color (integer) : DEL +## color moved up in template + product / product.template / cost_method (selection) : module is now 'stock_account' ('product') product / product.template / cost_method (selection) : now a function product / product.template / cost_method (selection) : selection_keys is now '['average', 'real', 'standard']' ('['average', 'standard']') +# TODO + product / product.template / image (binary) : NEW +product / product.product / image (binary) : now afunction +# need to move up to template + +product / product.product / image_variant (binary) : NEW +# nothing to do + product / product.template / message_ids (one2many) : NEW relation: mail.message product / product.template / message_last_post (datetime) : NEW +# now product.template derives from mail template +# TODO : move up messages +product / product.product / message_last_post (datetime) : NEW + + product / product.template / packaging (one2many) : NEW relation: product.packaging +# TODO later once issue #291 is solved + product / product.template / produce_delay (float) : DEL +# moved in mrp, defined on product.product + product / product.template / product_variant_ids (one2many): NEW relation: product.product, required: required +# nothing to do? + product / product.template / standard_price (float) : now a function -product / product.ul / height (float) : NEW -product / product.ul / length (float) : NEW -product / product.ul / weight (float) : NEW -product / product.ul / width (float) : NEW +# nothing to do + +product / product.product / incoming_qty (float) : module is now 'stock' ('product') +# function field nothing to do + +product / product.product / outgoing_qty (float) : module is now 'stock' ('product') +product / product.product / price_extra (float) : now a function +product / product.product / price_margin (float) : DEL +product / product.product / qty_available (float) : module is now 'stock' ('product') +product / product.product / variants (char) : DEL +product / product.product / virtual_available (float) : module is now 'stock' ('product') From d8f8b1bede44e759b599a16e367e3388cf148946 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:20:10 +0200 Subject: [PATCH 04/27] first pass at product migration script --- .../migrations/8.0.1.1/post-migration.py | 33 +++++++++++++++++++ .../8.0.1.1/post-modified_noupdate_data.py | 6 ---- .../migrations/8.0.1.1/pre-migration.py | 25 ++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 addons/product/migrations/8.0.1.1/post-migration.py delete mode 100644 addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py create mode 100644 addons/product/migrations/8.0.1.1/pre-migration.py diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py new file mode 100644 index 000000000000..deed2c8785fd --- /dev/null +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -0,0 +1,33 @@ +from openerp.openupgrade import openupgrade + +def load_data(cr): + openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') + +def move_fields(cr): + execute = openupgrade.logged_query + queries = [ """ + UPDATE product_supplierinfo + SET product_tmpl_id=(SELECT product_tmpl_id + FROM product_product + WHERE product_product.id=product_supplierinfo.%s) + """ % openupgrade.get_legacy_name('product_id'), + """ + UPDATE product_template as pt + SET color=(SELECT pp1.%s + FROM product_product as pp1 + WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), + image=(SELECT pp2.%s + FROM product_product as pp2 + WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1) + """ % (openupgrade.get_legacy_name('color'), + openupgrade.get_legacy_name('image') + ), + ] + for sql in queries: + execute(cr, sql) + +@openupgrade.migrate() +def migrate(cr, version): + move_fields() + load_data() + diff --git a/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py b/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py deleted file mode 100644 index 7ea5e631b75f..000000000000 --- a/addons/product/migrations/8.0.1.1/post-modified_noupdate_data.py +++ /dev/null @@ -1,6 +0,0 @@ - -import openupgrade - -@openupgrade.migrate -def migrate(cr, version): - openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py new file mode 100644 index 000000000000..1bb169ededb1 --- /dev/null +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -0,0 +1,25 @@ +from openerp.openupgrade import openupgrade + +column_renames = { + # Using magic None value to trigger call to get_legacy_name() + 'product_supplierinfo': [ + ('product_id', None), + ], + 'product_product': + [ + ('color', None), + ('image', None), + ], + 'product_template':[ + ('produce_delay', None), # need to handle in mrp migration + ] + } + +def migrate_packaging(cr): + pass # XXX + +@openupgrade.migrate() +def migrate(cr, version): + openupgrade.rename_columns(cr, column_renames) + migrate_packaging() + From adb73d2d05827fdee54809db87f2a7105c5ed229 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:30:18 +0200 Subject: [PATCH 05/27] fix bad refactoring --- addons/product/migrations/8.0.1.1/post-migration.py | 8 +++++--- addons/product/migrations/8.0.1.1/pre-migration.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index deed2c8785fd..df95a7de5dea 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -1,9 +1,10 @@ from openerp.openupgrade import openupgrade +from openerp import pooler, SUPERUSER_ID def load_data(cr): openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') -def move_fields(cr): +def move_fields(cr, pool): execute = openupgrade.logged_query queries = [ """ UPDATE product_supplierinfo @@ -28,6 +29,7 @@ def move_fields(cr): @openupgrade.migrate() def migrate(cr, version): - move_fields() - load_data() + pool = pooler.get_pool(cr.dbname) + move_fields(cr, pool) + load_data(cr) diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index 1bb169ededb1..f9d98880ab14 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -21,5 +21,5 @@ def migrate_packaging(cr): @openupgrade.migrate() def migrate(cr, version): openupgrade.rename_columns(cr, column_renames) - migrate_packaging() + migrate_packaging(cr) From 776c954961ce6996ff07eb9c52d2f0517dc56914 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:44:45 +0200 Subject: [PATCH 06/27] compute active attribute of template from attribute of variants --- .../migrations/8.0.1.1/openupgrade_analysis_WORK.txt | 12 +++++++----- addons/product/migrations/8.0.1.1/post-migration.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index a3522cb16778..6138a5e97003 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -13,7 +13,7 @@ product / product.attribute.value / price_ids (one2many) : NEW re product / product.attribute.value / product_ids (many2many) : NEW relation: product.product product / product.attribute.value / sequence (integer) : NEW -## new model, will be handled by standard migration +## OK new model, will be handled by standard migration product / product.packaging / ul_container (many2one) : NEW relation: product.ul @@ -33,19 +33,21 @@ product / product.price.history / company_id (many2one) : NEW re product / product.price.history / cost (float) : NEW product / product.price.history / datetime (datetime) : NEW product / product.price.history / product_template_id (many2one): NEW relation: product.template, required: required -# new fields -> nothing to do +# OK new fields -> nothing to do product / product.template / attribute_line_ids (one2many) : NEW relation: product.attribute.line product / product.product / attribute_value_ids (many2many): NEW relation: product.attribute.value -# nothing to do +# OK nothing to do product / product.supplierinfo / product_id (many2one) : DEL relation: product.template, required: required product / product.supplierinfo / product_tmpl_id (many2one) : NEW relation: product.template, required: required -# seller_ids moved from product.product to product.template -product / product.template / active (boolean) : NEW +# OK seller_ids moved from product.product to product.template # need to move seller_ids from product.product to product.template +product / product.template / active (boolean) : NEW +# OK: copy + product / product.template / color (integer) : NEW product / product.product / color (integer) : DEL ## color moved up in template diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index df95a7de5dea..3000202dcd43 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -27,9 +27,21 @@ def move_fields(cr, pool): for sql in queries: execute(cr, sql) +def copy_fields(cr, pool): + product_tmpl= pool['product.template'] + product_obj= pool['product.product'] + # copy the active field from product to template + ctx = {'active_test': False} + tmpl_ids = product_tmpl.search(cr, SUPERUSER_ID, [], context=ctx) + for template in product_tmpl.browse(cr, SUPERUSER_ID, tmpl_ids, context=ctx): + template.write({'active': any(variant.active + for variant in template.product_variant_ids) + }) + @openupgrade.migrate() def migrate(cr, version): pool = pooler.get_pool(cr.dbname) move_fields(cr, pool) + copy_fields(cr, pool) load_data(cr) From db73bf7a379f312cc823f5f1929053d0eb7eca9f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:52:35 +0200 Subject: [PATCH 07/27] copy product_product.image to product_product.image_variant --- .../product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt | 5 ++--- addons/product/migrations/8.0.1.1/post-migration.py | 3 +-- addons/product/migrations/8.0.1.1/pre-migration.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index 6138a5e97003..0058b626411e 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -43,14 +43,13 @@ product / product.product / attribute_value_ids (many2many): NEW r product / product.supplierinfo / product_id (many2one) : DEL relation: product.template, required: required product / product.supplierinfo / product_tmpl_id (many2one) : NEW relation: product.template, required: required # OK seller_ids moved from product.product to product.template -# need to move seller_ids from product.product to product.template product / product.template / active (boolean) : NEW # OK: copy product / product.template / color (integer) : NEW product / product.product / color (integer) : DEL -## color moved up in template +## OK color moved up in template product / product.template / cost_method (selection) : module is now 'stock_account' ('product') product / product.template / cost_method (selection) : now a function @@ -59,7 +58,7 @@ product / product.template / cost_method (selection) : select product / product.template / image (binary) : NEW product / product.product / image (binary) : now afunction -# need to move up to template +# OK need to move up to template product / product.product / image_variant (binary) : NEW # nothing to do diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 3000202dcd43..3f61e80adcd2 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -17,11 +17,10 @@ def move_fields(cr, pool): SET color=(SELECT pp1.%s FROM product_product as pp1 WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), - image=(SELECT pp2.%s + image=(SELECT pp2.image_variant FROM product_product as pp2 WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1) """ % (openupgrade.get_legacy_name('color'), - openupgrade.get_legacy_name('image') ), ] for sql in queries: diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index f9d98880ab14..09bc8ae80a56 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -8,7 +8,7 @@ 'product_product': [ ('color', None), - ('image', None), + ('image', 'image_variant'), ], 'product_template':[ ('produce_delay', None), # need to handle in mrp migration From 2e9f1a6e66b66a7d42a15c776ec1aae1c10092d1 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 16:56:39 +0200 Subject: [PATCH 08/27] updated work analysis --- .../migrations/8.0.1.1/openupgrade_analysis_WORK.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index 0058b626411e..b9b9f21c2548 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -45,7 +45,7 @@ product / product.supplierinfo / product_tmpl_id (many2one) : NEW re # OK seller_ids moved from product.product to product.template product / product.template / active (boolean) : NEW -# OK: copy +# OK: set to True if at least one variant is active product / product.template / color (integer) : NEW product / product.product / color (integer) : DEL @@ -54,7 +54,7 @@ product / product.product / color (integer) : DEL product / product.template / cost_method (selection) : module is now 'stock_account' ('product') product / product.template / cost_method (selection) : now a function product / product.template / cost_method (selection) : selection_keys is now '['average', 'real', 'standard']' ('['average', 'standard']') -# TODO +# nothing to do ? product / product.template / image (binary) : NEW product / product.product / image (binary) : now afunction @@ -66,7 +66,7 @@ product / product.product / image_variant (binary) : NEW product / product.template / message_ids (one2many) : NEW relation: mail.message product / product.template / message_last_post (datetime) : NEW # now product.template derives from mail template -# TODO : move up messages +# TODO : move up messages -> they will still be on the product so why bother product / product.product / message_last_post (datetime) : NEW From 978684c28ea18989d21c51f13f0e7657f869edfd Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 17:47:02 +0200 Subject: [PATCH 09/27] migration of product.packaging and product.ul --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 4 ++-- .../product/migrations/8.0.1.1/post-migration.py | 16 ++++++++++++++++ .../product/migrations/8.0.1.1/pre-migration.py | 15 ++++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index b9b9f21c2548..9dc246e0372b 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -25,8 +25,8 @@ product / product.packaging / weight_ul (float) : DEL product / product.ul / weight (float) : NEW product / product.packaging / width (float) : DEL product / product.ul / width (float) : NEW -## new relation ul_container, and the dimensions are moved there -## TODO later because rarely used feature +## OK new relation ul_container handled by migration +## OK the dimensions are weight must be moved to the related UL (through the ul field) product / product.price.history / company_id (many2one) : NEW relation: res.company, required: required, req_default: function diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 3f61e80adcd2..fce32a75497e 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -37,10 +37,26 @@ def copy_fields(cr, pool): for variant in template.product_variant_ids) }) +def migrate_packaging(cr, pool): + """create 1 product UL for each different product packaging dimension + and link it to the packagings + """ + packaging_obj = pool['product.packaging'] + ul_obj = pool['product.ul'] + packaging_ids = packaging_obj.search(cr, SUPERUSER_ID, []) + for packaging in packaging_obj.browse(cr, SUPERUSER_ID, packaging_ids): + ul = packaging.ul + ul.write({'height': height, + 'width': width, + 'length': length, + 'weight_ul': weight, + }) + @openupgrade.migrate() def migrate(cr, version): pool = pooler.get_pool(cr.dbname) move_fields(cr, pool) copy_fields(cr, pool) + migrate_packaging(cr, pool) load_data(cr) diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index 09bc8ae80a56..0530e8074b93 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -5,21 +5,22 @@ 'product_supplierinfo': [ ('product_id', None), ], - 'product_product': - [ + 'product_product': [ ('color', None), ('image', 'image_variant'), ], - 'product_template':[ + 'product_template': [ ('produce_delay', None), # need to handle in mrp migration + ], + 'product_packaging': [ + ('height', None), + ('length', None), + ('weight_ul', None), + ('width', None), ] } -def migrate_packaging(cr): - pass # XXX @openupgrade.migrate() def migrate(cr, version): openupgrade.rename_columns(cr, column_renames) - migrate_packaging(cr) - From c6845124d0b94c136efcf2d96f3780641ba95b00 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 2 Jun 2014 17:57:58 +0200 Subject: [PATCH 10/27] migration of product_template.cost_method, moved in stock_account --- addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt | 2 +- addons/product/migrations/8.0.1.1/pre-migration.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index 9dc246e0372b..50cda025c18e 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -54,7 +54,7 @@ product / product.product / color (integer) : DEL product / product.template / cost_method (selection) : module is now 'stock_account' ('product') product / product.template / cost_method (selection) : now a function product / product.template / cost_method (selection) : selection_keys is now '['average', 'real', 'standard']' ('['average', 'standard']') -# nothing to do ? +# moved in stock_account, now a fields.property product / product.template / image (binary) : NEW product / product.product / image (binary) : now afunction diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index 0530e8074b93..fb6208e1748e 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -11,6 +11,7 @@ ], 'product_template': [ ('produce_delay', None), # need to handle in mrp migration + ('cost_method', None), # need to handle in stock_account migration ], 'product_packaging': [ ('height', None), From 08fd7aab26349efe79bbd5a51c9ae8cad1d2e487 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 18:22:00 +0200 Subject: [PATCH 11/27] reinstall data from product moved to mrp --- addons/mrp/migrations/8.0.1.1/post-migrate.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 addons/mrp/migrations/8.0.1.1/post-migrate.py diff --git a/addons/mrp/migrations/8.0.1.1/post-migrate.py b/addons/mrp/migrations/8.0.1.1/post-migrate.py new file mode 100644 index 000000000000..d8e1cd22b2c4 --- /dev/null +++ b/addons/mrp/migrations/8.0.1.1/post-migrate.py @@ -0,0 +1,18 @@ +from openerp.openupgrade import openupgrade +from openerp import pooler, SUPERUSER_ID + +def move_fields(cr, pool): + execute = openupgrade.logged_query + queries = [ """ + UPDATE product_product + SET produce_delay=(SELECT pt.%s + FROM product_template + WHERE product_template.id=product_product.product_tmpl_id) + """ % openupgrade.get_legacy_name('produce_delay'), + + +@openupgrade.migrate() +def migrate(cr, version): + pool = pooler.get_pool(cr.dbname) + move_fields(cr, pool) + From 81da4ed74b03d6e092ebe5b68d9e73968e973ddd Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 18:37:27 +0200 Subject: [PATCH 12/27] add migration for product.packaging to template --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 4 +- .../migrations/8.0.1.1/post-migration.py | 39 +++++++++++-------- .../migrations/8.0.1.1/pre-migration.py | 1 + 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index 9dc246e0372b..17a098dd3b62 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -71,10 +71,10 @@ product / product.product / message_last_post (datetime) : NEW product / product.template / packaging (one2many) : NEW relation: product.packaging -# TODO later once issue #291 is solved +# OK moved from product.product product / product.template / produce_delay (float) : DEL -# moved in mrp, defined on product.product +# OK moved in mrp, defined on product.product product / product.template / product_variant_ids (one2many): NEW relation: product.product, required: required # nothing to do? diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index fce32a75497e..a25023b9ab63 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -6,23 +6,28 @@ def load_data(cr): def move_fields(cr, pool): execute = openupgrade.logged_query - queries = [ """ - UPDATE product_supplierinfo - SET product_tmpl_id=(SELECT product_tmpl_id - FROM product_product - WHERE product_product.id=product_supplierinfo.%s) - """ % openupgrade.get_legacy_name('product_id'), - """ - UPDATE product_template as pt - SET color=(SELECT pp1.%s - FROM product_product as pp1 - WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), - image=(SELECT pp2.image_variant - FROM product_product as pp2 - WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1) - """ % (openupgrade.get_legacy_name('color'), - ), - ] + queries = ["UPDATE product_supplierinfo " + "SET product_tmpl_id=(SELECT product_tmpl_id " + " FROM product_product " + " WHERE product_product.id=product_supplierinfo.%s) " \ + % openupgrade.get_legacy_name('product_id'), + # + "UPDATE product_template as pt " + "SET color=(SELECT pp1.%s " + " FROM product_product as pp1 " + " WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), " + " image=(SELECT pp2.image_variant " + " FROM product_product as pp2 " + " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" + " packaging=(SELECT pp3.%s " + " FROM product_product as pp3 " + " WHERE pp3.product_tmpl_id=pt.id ORDER BY pp3.id LIMIT 1)" \ + % (openupgrade.get_legacy_name('color'), + openupgrade.get_legacy_name('packaging'), + ) + # + + ] for sql in queries: execute(cr, sql) diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index 0530e8074b93..f5a934d22ed9 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -8,6 +8,7 @@ 'product_product': [ ('color', None), ('image', 'image_variant'), + ('packaging', None), ], 'product_template': [ ('produce_delay', None), # need to handle in mrp migration From dd941af6c6c5ad1fae3029b1ca8750a128c90979 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 2 Jun 2014 18:38:49 +0200 Subject: [PATCH 13/27] fix error in previous refactoring --- .../migrations/8.0.1.1/post-migration.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index a25023b9ab63..fca7ed440f6d 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -12,13 +12,13 @@ def move_fields(cr, pool): " WHERE product_product.id=product_supplierinfo.%s) " \ % openupgrade.get_legacy_name('product_id'), # - "UPDATE product_template as pt " + "UPDATE product_template as pt " "SET color=(SELECT pp1.%s " " FROM product_product as pp1 " " WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), " " image=(SELECT pp2.image_variant " " FROM product_product as pp2 " - " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" + " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" " packaging=(SELECT pp3.%s " " FROM product_product as pp3 " " WHERE pp3.product_tmpl_id=pt.id ORDER BY pp3.id LIMIT 1)" \ @@ -26,7 +26,7 @@ def move_fields(cr, pool): openupgrade.get_legacy_name('packaging'), ) # - + ] for sql in queries: execute(cr, sql) @@ -51,12 +51,12 @@ def migrate_packaging(cr, pool): packaging_ids = packaging_obj.search(cr, SUPERUSER_ID, []) for packaging in packaging_obj.browse(cr, SUPERUSER_ID, packaging_ids): ul = packaging.ul - ul.write({'height': height, - 'width': width, - 'length': length, - 'weight_ul': weight, + ul.write({'height': packaging.height, + 'width': packaging.width, + 'length': packaging.length, + 'weight_ul': packaging.weight, }) - + @openupgrade.migrate() def migrate(cr, version): pool = pooler.get_pool(cr.dbname) @@ -64,4 +64,4 @@ def migrate(cr, version): copy_fields(cr, pool) migrate_packaging(cr, pool) load_data(cr) - + From 2a7bebaa5e328cb89c29d0c9b2fac0a86f84ceda Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 09:40:23 +0200 Subject: [PATCH 14/27] Migrate product_template.standard_price. Now a fields.property so the prices are moved to properties. Also, entries for the prices will be created in product_price_history. --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 2 +- .../migrations/8.0.1.1/post-migration.py | 21 ++++++++++++++++++- .../migrations/8.0.1.1/pre-migration.py | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index 50cda025c18e..ec76d74e4131 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -80,7 +80,7 @@ product / product.template / product_variant_ids (one2many): NEW re # nothing to do? product / product.template / standard_price (float) : now a function -# nothing to do +# OK. Now a fields.property, properties needs to be created product / product.product / incoming_qty (float) : module is now 'stock' ('product') # function field nothing to do diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index fce32a75497e..2ef644cba75a 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -51,12 +51,31 @@ def migrate_packaging(cr, pool): 'length': length, 'weight_ul': weight, }) - + +def create_properties(cr, pool): + """ Fields moved to properties (standard_price). + + Write using the ORM so the prices will be written as properties. + """ + template_obj = pool['product.template'] + company_obj = pool['res.company'] + company_ids = company_obj.search(cr, SUPERUSER_ID, []) + sql = ("SELECT id, %s FROM product_template" % + openupgrade.get_legacy_name('standard_price')) + cr.execute(sql) + for template_id, std_price in cr.fetchall(): + for company_id in company_ids: + ctx = {'force_company': company_id} + template_obj.write(cr, SUPERUSER_ID, [template_id], + {'standard_price': std_price}, + context=ctx) + @openupgrade.migrate() def migrate(cr, version): pool = pooler.get_pool(cr.dbname) move_fields(cr, pool) copy_fields(cr, pool) migrate_packaging(cr, pool) + create_properties(cr, pool) load_data(cr) diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index fb6208e1748e..b6e1de39a757 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -12,6 +12,7 @@ 'product_template': [ ('produce_delay', None), # need to handle in mrp migration ('cost_method', None), # need to handle in stock_account migration + ('standard_price', None), ], 'product_packaging': [ ('height', None), From 7dff6b23d8aa63814d56fc5c541b6cb4e5c86e01 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 10:36:48 +0200 Subject: [PATCH 15/27] Updated openupgrade_analysis_WORK.txt with comments --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index ec76d74e4131..b49591103967 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -83,14 +83,23 @@ product / product.template / standard_price (float) : now a # OK. Now a fields.property, properties needs to be created product / product.product / incoming_qty (float) : module is now 'stock' ('product') -# function field nothing to do - product / product.product / outgoing_qty (float) : module is now 'stock' ('product') +# function fields nothing to do + product / product.product / price_extra (float) : now a function +# moved to 'product.attribute.price', needs to create attributes + product / product.product / price_margin (float) : DEL +# no longer exists! + product / product.product / qty_available (float) : module is now 'stock' ('product') +# function field nothing to do + product / product.product / variants (char) : DEL +# moved to 'product.attribute.value', needs to create attributes + product / product.product / virtual_available (float) : module is now 'stock' ('product') +# function field nothing to do From be0576e3fc51d68a2f2dcbb72223dd2450c0f5a4 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 3 Jun 2014 11:18:08 +0200 Subject: [PATCH 16/27] packaging field is o2m -> no colum renaming required --- addons/product/migrations/8.0.1.1/post-migration.py | 4 ---- addons/product/migrations/8.0.1.1/pre-migration.py | 1 - 2 files changed, 5 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index fca7ed440f6d..54d7be6f50ba 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -19,11 +19,7 @@ def move_fields(cr, pool): " image=(SELECT pp2.image_variant " " FROM product_product as pp2 " " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" - " packaging=(SELECT pp3.%s " - " FROM product_product as pp3 " - " WHERE pp3.product_tmpl_id=pt.id ORDER BY pp3.id LIMIT 1)" \ % (openupgrade.get_legacy_name('color'), - openupgrade.get_legacy_name('packaging'), ) # diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index 3b92afeae619..fb6208e1748e 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -8,7 +8,6 @@ 'product_product': [ ('color', None), ('image', 'image_variant'), - ('packaging', None), ], 'product_template': [ ('produce_delay', None), # need to handle in mrp migration From c6e21ee3b9cbc7897bfb2b80c57de4a4f973c178 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 3 Jun 2014 11:32:15 +0200 Subject: [PATCH 17/27] fix packaging/ul migration --- .../migrations/8.0.1.1/post-migration.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 54d7be6f50ba..842d498275fa 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -44,14 +44,19 @@ def migrate_packaging(cr, pool): """ packaging_obj = pool['product.packaging'] ul_obj = pool['product.ul'] - packaging_ids = packaging_obj.search(cr, SUPERUSER_ID, []) - for packaging in packaging_obj.browse(cr, SUPERUSER_ID, packaging_ids): - ul = packaging.ul - ul.write({'height': packaging.height, - 'width': packaging.width, - 'length': packaging.length, - 'weight_ul': packaging.weight, - }) + execute = openupgrade.logged_query + legacy_columns = dict((key, openupgrade.get_legacy_name(key)) + for key in ('height', 'width', + 'length', 'weight_ul')) + execute(cr, + 'select ul, %(height)s, %(width)s, %(length)s, %(weight_ul)s ' + 'from product_packaging' % legacy_columns) + for ul_id, height, width, length, weight in cr.fetchall(): + ul_obj.write(cr, SUPERUSER_ID, [ul_id], + {'height': height, + 'width': width, + 'length': weight, + }) @openupgrade.migrate() def migrate(cr, version): From 6afa1a61dc0d6da6d6132fa12afc66768f99117d Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 3 Jun 2014 11:38:35 +0200 Subject: [PATCH 18/27] re-add the change on product consultant --- addons/product/migrations/8.0.1.1/modified_data.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/modified_data.xml b/addons/product/migrations/8.0.1.1/modified_data.xml index 93c05c245d06..144955bcda48 100644 --- a/addons/product/migrations/8.0.1.1/modified_data.xml +++ b/addons/product/migrations/8.0.1.1/modified_data.xml @@ -17,9 +17,8 @@ ['|',('company_id','=',user.company_id.id),('company_id','=',False)] - - + + From 2f10573a29d754615e7870fc83320a6d36039198 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 3 Jun 2014 11:39:01 +0200 Subject: [PATCH 19/27] added AGPL header --- .../migrations/8.0.1.1/post-migration.py | 21 +++++++++++++++++++ .../migrations/8.0.1.1/pre-migration.py | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 842d498275fa..8fccf7e51c99 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + from openerp.openupgrade import openupgrade from openerp import pooler, SUPERUSER_ID diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index fb6208e1748e..f9ed9a211ded 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Alexandre Fayolle +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + from openerp.openupgrade import openupgrade column_renames = { From 0bbfeb698dd9a841ee7da6ce21772c776c0155c3 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 3 Jun 2014 11:48:09 +0200 Subject: [PATCH 20/27] fix typo --- addons/product/migrations/8.0.1.1/post-migration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 8fccf7e51c99..78177737001e 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -76,7 +76,8 @@ def migrate_packaging(cr, pool): ul_obj.write(cr, SUPERUSER_ID, [ul_id], {'height': height, 'width': width, - 'length': weight, + 'length': length, + 'weight': weight, }) @openupgrade.migrate() From b944b0b5a9544244be283000dc6acf34f7f243dd Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 12:44:55 +0200 Subject: [PATCH 21/27] openerp namespace is missing in the import --- addons/email_template/migrations/8.0.1.1/pre-migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/email_template/migrations/8.0.1.1/pre-migration.py b/addons/email_template/migrations/8.0.1.1/pre-migration.py index c94a8c996f88..01b3664af690 100644 --- a/addons/email_template/migrations/8.0.1.1/pre-migration.py +++ b/addons/email_template/migrations/8.0.1.1/pre-migration.py @@ -19,7 +19,7 @@ # ############################################################################## -from openupgrade import openupgrade +from openerp.openupgrade import openupgrade column_renames = { 'email_template': [ From 92414d46db57e59e6942817c6723f8c7ce97e307 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 12:45:55 +0200 Subject: [PATCH 22/27] Wrong API call (PR submitted upstream) --- addons/product/product.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/product/product.py b/addons/product/product.py index 2369db49d436..ebf6181290c1 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -344,6 +344,8 @@ def _get_price_extra(self, cr, uid, ids, name, args, context=None): return result def _set_price_extra(self, cr, uid, id, name, value, args, context=None): + if context is None: + context = {} if 'active_id' not in context: return None p_obj = self.pool['product.attribute.price'] @@ -351,7 +353,7 @@ def _set_price_extra(self, cr, uid, id, name, value, args, context=None): if p_ids: p_obj.write(cr, uid, p_ids, {'price_extra': value}, context=context) else: - p_obj.create(cr, uid, p_ids, { + p_obj.create(cr, uid, { 'product_tmpl_id': context['active_id'], 'value_id': id, 'price_extra': value, From f44b8e4cfd80e334d792f2d6d3fa47cade0da3f5 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 12:47:30 +0200 Subject: [PATCH 23/27] Migrate 'variants' and 'price_extra' using the new attribute models --- .../8.0.1.1/openupgrade_analysis_WORK.txt | 4 +- .../migrations/8.0.1.1/post-migration.py | 45 +++++++++++++++++++ .../migrations/8.0.1.1/pre-migration.py | 2 + 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt index b49591103967..062fbff75aae 100644 --- a/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt +++ b/addons/product/migrations/8.0.1.1/openupgrade_analysis_WORK.txt @@ -87,7 +87,7 @@ product / product.product / outgoing_qty (float) : module # function fields nothing to do product / product.product / price_extra (float) : now a function -# moved to 'product.attribute.price', needs to create attributes +# OK moved to 'product.attribute.price', needs to create attributes product / product.product / price_margin (float) : DEL # no longer exists! @@ -96,7 +96,7 @@ product / product.product / qty_available (float) : module # function field nothing to do product / product.product / variants (char) : DEL -# moved to 'product.attribute.value', needs to create attributes +# OK moved to 'product.attribute.value', needs to create attributes product / product.product / virtual_available (float) : module is now 'stock' ('product') # function field nothing to do diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 2ef644cba75a..d6ce3f944604 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -1,6 +1,9 @@ +from itertools import groupby +from operator import itemgetter from openerp.openupgrade import openupgrade from openerp import pooler, SUPERUSER_ID + def load_data(cr): openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') @@ -70,6 +73,47 @@ def create_properties(cr, pool): {'standard_price': std_price}, context=ctx) +def migrate_variants(cr, pool): + template_obj = pool['product.template'] + attribute_obj = pool['product.attribute'] + attribute_value_obj = pool['product.attribute.value'] + attribute_line_obj = pool['product.attribute.line'] + fields = {'variant': openupgrade.get_legacy_name('variants'), + 'price': openupgrade.get_legacy_name('price_extra')} + sql = ("SELECT id, %(variant)s, %(price)s, product_tmpl_id " + "FROM product_product " + "WHERE %(variant)s IS NOT NULL " + "OR %(price)s IS NOT NULL AND %(price)s <> 0" + "ORDER BY product_tmpl_id, id" % fields) + cr.execute(sql) + rows = cr.dictfetchall() + for tmpl_id, variants in groupby(rows, key=itemgetter('product_tmpl_id')): + # create an attribute shared by all the variants + template = template_obj.browse(cr, SUPERUSER_ID, tmpl_id) + attr_id = attribute_obj.create(cr, SUPERUSER_ID, + {'name': template.name}) + for variant in variants: + # create an attribute value for this variant + price_extra = variant[fields['price']] or 0 + name = variant[fields['variant']] + # active_id needed to create the 'product.attribute.price' + ctx = {'active_id': tmpl_id} + values = { + 'name': name or '%.2f' % price_extra, + 'attribute_id': attr_id, + 'product_ids': [(6, 0, [variant['id']])], + # a 'product.attribute.price' is created when we write + # a price_extra on an attribute value + 'price_extra': price_extra, + } + value_id = attribute_value_obj.create(cr, SUPERUSER_ID, values, + context=ctx) + values = {'product_tmpl_id': tmpl_id, + 'attribute_id': attr_id, + 'value_ids': [(6, 0, [value_id])]} + attribute_line_obj.create(cr, SUPERUSER_ID, values) + + @openupgrade.migrate() def migrate(cr, version): pool = pooler.get_pool(cr.dbname) @@ -77,5 +121,6 @@ def migrate(cr, version): copy_fields(cr, pool) migrate_packaging(cr, pool) create_properties(cr, pool) + migrate_variants(cr, pool) load_data(cr) diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index b6e1de39a757..e20023a931b2 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -8,6 +8,8 @@ 'product_product': [ ('color', None), ('image', 'image_variant'), + ('variants', None), + ('price_extra', None), ], 'product_template': [ ('produce_delay', None), # need to handle in mrp migration From c01afcba89427a1f881e9ad2b64765d38de5bcfe Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 12:59:19 +0200 Subject: [PATCH 24/27] pep8, unused models --- .../migrations/8.0.1.1/post-migration.py | 21 +++++++++++-------- .../migrations/8.0.1.1/pre-migration.py | 12 +++++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 197c72da9be9..83cd64ebfe0a 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -25,15 +25,18 @@ def load_data(cr): - openupgrade.load_data(cr, 'product', 'migrations/8.0.1.1/modified_data.xml', mode='init') + openupgrade.load_data(cr, 'product', + 'migrations/8.0.1.1/modified_data.xml', + mode='init') + def move_fields(cr, pool): execute = openupgrade.logged_query queries = ["UPDATE product_supplierinfo " "SET product_tmpl_id=(SELECT product_tmpl_id " " FROM product_product " - " WHERE product_product.id=product_supplierinfo.%s) " \ - % openupgrade.get_legacy_name('product_id'), + " WHERE product_product.id=product_supplierinfo.%s) " % + openupgrade.get_legacy_name('product_id'), # "UPDATE product_template as pt " "SET color=(SELECT pp1.%s " @@ -41,18 +44,17 @@ def move_fields(cr, pool): " WHERE pp1.product_tmpl_id=pt.id ORDER BY pp1.id LIMIT 1), " " image=(SELECT pp2.image_variant " " FROM product_product as pp2 " - " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" - % (openupgrade.get_legacy_name('color'), - ) + " WHERE pp2.product_tmpl_id=pt.id ORDER BY pp2.id LIMIT 1)" % + openupgrade.get_legacy_name('color') # ] for sql in queries: execute(cr, sql) + def copy_fields(cr, pool): product_tmpl= pool['product.template'] - product_obj= pool['product.product'] # copy the active field from product to template ctx = {'active_test': False} tmpl_ids = product_tmpl.search(cr, SUPERUSER_ID, [], context=ctx) @@ -61,11 +63,11 @@ def copy_fields(cr, pool): for variant in template.product_variant_ids) }) + def migrate_packaging(cr, pool): """create 1 product UL for each different product packaging dimension and link it to the packagings """ - packaging_obj = pool['product.packaging'] ul_obj = pool['product.ul'] execute = openupgrade.logged_query legacy_columns = dict((key, openupgrade.get_legacy_name(key)) @@ -82,6 +84,7 @@ def migrate_packaging(cr, pool): 'weight': weight, }) + def create_properties(cr, pool): """ Fields moved to properties (standard_price). @@ -100,6 +103,7 @@ def create_properties(cr, pool): {'standard_price': std_price}, context=ctx) + def migrate_variants(cr, pool): template_obj = pool['product.template'] attribute_obj = pool['product.attribute'] @@ -150,4 +154,3 @@ def migrate(cr, version): create_properties(cr, pool) migrate_variants(cr, pool) load_data(cr) - diff --git a/addons/product/migrations/8.0.1.1/pre-migration.py b/addons/product/migrations/8.0.1.1/pre-migration.py index fc29e07e17eb..b064f977114a 100644 --- a/addons/product/migrations/8.0.1.1/pre-migration.py +++ b/addons/product/migrations/8.0.1.1/pre-migration.py @@ -25,25 +25,25 @@ # Using magic None value to trigger call to get_legacy_name() 'product_supplierinfo': [ ('product_id', None), - ], + ], 'product_product': [ ('color', None), ('image', 'image_variant'), ('variants', None), ('price_extra', None), - ], + ], 'product_template': [ - ('produce_delay', None), # need to handle in mrp migration + ('produce_delay', None), # need to handle in mrp migration ('cost_method', None), # need to handle in stock_account migration ('standard_price', None), - ], + ], 'product_packaging': [ ('height', None), ('length', None), ('weight_ul', None), ('width', None), - ] - } + ] +} @openupgrade.migrate() From 2effbb85ae79d46363a132387879128d03ffc0b0 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 16:35:48 +0200 Subject: [PATCH 25/27] Write a 'Unix time zero' on the product price history entries so product have a standard price for the past, not only from now --- addons/product/migrations/8.0.1.1/post-migration.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 83cd64ebfe0a..6552d544be6a 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -102,6 +102,12 @@ def create_properties(cr, pool): template_obj.write(cr, SUPERUSER_ID, [template_id], {'standard_price': std_price}, context=ctx) + # product.price.history entries have been generated with a value for + # today, we want a value for the past as well, write a bogus date to + # be sure that we have an historic value whenever we want + cr.execute("UPDATE product_price_history SET " + # calling a field 'datetime' is not really a good idea + "datetime = '1970-01-01 00:00:00+00'") def migrate_variants(cr, pool): From 71f17b2ec39b7d4a0d3e7878755af200996a93b2 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 17:09:25 +0200 Subject: [PATCH 26/27] pep8: missing whitespace around operator --- addons/product/migrations/8.0.1.1/post-migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/migrations/8.0.1.1/post-migration.py b/addons/product/migrations/8.0.1.1/post-migration.py index 6552d544be6a..434eee5aace7 100644 --- a/addons/product/migrations/8.0.1.1/post-migration.py +++ b/addons/product/migrations/8.0.1.1/post-migration.py @@ -54,7 +54,7 @@ def move_fields(cr, pool): def copy_fields(cr, pool): - product_tmpl= pool['product.template'] + product_tmpl = pool['product.template'] # copy the active field from product to template ctx = {'active_test': False} tmpl_ids = product_tmpl.search(cr, SUPERUSER_ID, [], context=ctx) From ee91d78412ce57d35fbba3bbe13f646c90756027 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 3 Jun 2014 17:45:03 +0200 Subject: [PATCH 27/27] Migrate product_template.cost_method to property (in stock_account) --- .../migrations/8.0.1.1/post-migrate.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 addons/stock_account/migrations/8.0.1.1/post-migrate.py diff --git a/addons/stock_account/migrations/8.0.1.1/post-migrate.py b/addons/stock_account/migrations/8.0.1.1/post-migrate.py new file mode 100644 index 000000000000..3d64f97ae899 --- /dev/null +++ b/addons/stock_account/migrations/8.0.1.1/post-migrate.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.openupgrade import openupgrade +from openerp import pooler, SUPERUSER_ID + + +def create_properties(cr, pool): + """ Fields moved to properties (cost_method). + + Write using the ORM so the cost_method will be written as properties. + """ + template_obj = pool['product.template'] + company_obj = pool['res.company'] + company_ids = company_obj.search(cr, SUPERUSER_ID, []) + sql = ("SELECT id, %s FROM product_template" % + openupgrade.get_legacy_name('cost_method')) + cr.execute(sql) + for template_id, cost_method in cr.fetchall(): + for company_id in company_ids: + ctx = {'force_company': company_id} + template_obj.write(cr, SUPERUSER_ID, [template_id], + {'cost_method': cost_method}, + context=ctx) + + +@openupgrade.migrate() +def migrate(cr, version): + pool = pooler.get_pool(cr.dbname) + create_properties(cr, pool)