From 60117ad9e05159dc0d61e89642ab440dfc8b7394 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Tue, 16 May 2017 10:55:18 +0200 Subject: [PATCH 01/11] [MIG] Rename account_operation_template to account_reconcile_model. --- .../migrations/10.0.1.1/pre-migration.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 addons/account/migrations/10.0.1.1/pre-migration.py diff --git a/addons/account/migrations/10.0.1.1/pre-migration.py b/addons/account/migrations/10.0.1.1/pre-migration.py new file mode 100644 index 000000000000..4edd04f4c392 --- /dev/null +++ b/addons/account/migrations/10.0.1.1/pre-migration.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + cr = env.cr + # copy columns good practice in pre-mig script format of colum_spec should + # be: { Table_name_in_db : [( old_column_name , new_column_name, type)] + # defaults of new columname are fetchable via method get_legacy_name + openupgrade.rename_tables( + cr, + [ + ('account_operation_template', 'account_reconcile_model'), + ] + ) From 4fc51dc4bb0f756a30debbade1b03e40f72372d4 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Tue, 16 May 2017 12:30:20 +0200 Subject: [PATCH 02/11] [MIG] Prefill account_reconcile_model_template. --- .../10.0.1.1/openupgrade_analysis_work.txt | 4 +-- .../migrations/10.0.1.1/post-migration.py | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 addons/account/migrations/10.0.1.1/post-migration.py diff --git a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt index 83e0e2970e5e..c390bd2ab73f 100644 --- a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -56,8 +56,8 @@ account / account.reconcile.model / second_tax_id (many2one) : NEW re account / account.reconcile.model / second_analytic_account_id (many2one): NEW relation: account.analytic.account account / account.reconcile.model / second_journal_id (many2one) : NEW relation: account.journal -## NEW MODEL ACCOUNT.RECONCILE.MODEL ## -# TODO: pre-migration: precreate records from the account.operation.template, +## NEW MODEL ACCOUNT.RECONCILE.MODEL.TEMPLATE ## +# TODO: post-migration: precreate records from the account.reconcile.model, # selecting the ones that are distinct regardless of the company account / account.reconcile.model.template / name (char) : NEW required: required account / account.reconcile.model.template / sequence (integer) : NEW required: required, req_default: function diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py new file mode 100644 index 000000000000..3ccabd35d0de --- /dev/null +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + cr = env.cr + # Insert appropiate enties in account_reconcile_model_template + cr.execute( + '''INSERT INTO account_reconcile_model_template + (create_uid, create_date, write_uid, write_date, + name, sequence, has_second_line, + account_id, label, tax_id, amount_type, amount, + second_account_id, second_label, second_tax_id, second_amount_type, + second_amount) + SELECT + MIN(create_uid), MIN(create_date), MAX(write_uid), MAX(write_date), + name, sequence, has_second_line, + account_id, label, tax_id, amount_type, amount, + second_account_id, second_label, second_tax_id, second_amount_type, + second_amount + FROM account_reconcile_model + GROUP BY + name, sequence, has_second_line, + account_id, label, tax_id, amount_type, amount, + second_account_id, second_label, second_tax_id, second_amount_type, + second_amount + ''') From 0fb3ca3aca06fed14721878cde3bbc6397fafb07 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Tue, 16 May 2017 16:09:19 +0200 Subject: [PATCH 03/11] [MIG] Fill payment move_name from move, through line. --- .../10.0.1.1/openupgrade_analysis_work.txt | 2 +- addons/account/migrations/10.0.1.1/post-migration.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt index c390bd2ab73f..aef877b06d0a 100644 --- a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -81,7 +81,7 @@ account / account.tax.template / tax_adjustment (boolean) : NEW # NOTHING TO DO account / account.tax.template / tax_group_id (many2one) : NEW relation: account.tax.group -# ??? MORE ANALYSIS REQUIRED +# NOTHING TO DO (If not set on template, default tax group will be used) account / res.company / paypal_account (char) : DEL # NOTHING TO DO diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py index 3ccabd35d0de..4cc21a43e422 100644 --- a/addons/account/migrations/10.0.1.1/post-migration.py +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -26,3 +26,15 @@ def migrate(env, version): second_account_id, second_label, second_tax_id, second_amount_type, second_amount ''') + # Update move_name in account_payment from account_move + cr.execute( + '''UPDATE account_payment + SET move_name = subquery.name + FROM (SELECT DISTINCT ON (aml.payment_id) am.name, aml.payment_id + FROM account_move am + JOIN account_move_line aml ON am.id = aml.move_id + WHERE NOT aml.payment_id IS NULL + ORDER BY aml.payment_id, am.name + ) AS subquery + WHERE account_payment.id = subquery.payment_id + ''') From c51a277a10a439832faad441226ded114008561f Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Mon, 29 May 2017 12:18:08 +0200 Subject: [PATCH 04/11] [WIP ste stuff done. --- .../migrations/10.0.1.1/openupgrade_analysis_work.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt index aef877b06d0a..2600a9aaa816 100644 --- a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -31,11 +31,11 @@ account / account.move.line / analytic_tag_ids (many2many) : NEW re # NOTHING TO DO account / account.payment / move_name (char) : NEW -# TODO: Calculate during post-migration using the move name associated to the +# DONE: Calculate during post-migration using the move name associated to the # the move lines that have that payment. ## NEW MODEL ACCOUNT.RECONCILE.MODEL ## -# TODO: pre-migration: rename table account.operation.template to +# DONE: pre-migration: rename table account.operation.template to # account.reconcile.model account / account.reconcile.model / name (char) : NEW required: required account / account.reconcile.model / sequence (integer) : NEW required: required, req_default: function @@ -57,7 +57,7 @@ account / account.reconcile.model / second_analytic_account_id (many2one): account / account.reconcile.model / second_journal_id (many2one) : NEW relation: account.journal ## NEW MODEL ACCOUNT.RECONCILE.MODEL.TEMPLATE ## -# TODO: post-migration: precreate records from the account.reconcile.model, +# DONE: post-migration: precreate records from the account.reconcile.model, # selecting the ones that are distinct regardless of the company account / account.reconcile.model.template / name (char) : NEW required: required account / account.reconcile.model.template / sequence (integer) : NEW required: required, req_default: function From 88a9b20b9b59976f15d072bd0a858cbce5e7330d Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Mon, 29 May 2017 17:04:48 +0200 Subject: [PATCH 05/11] [FIX] Migrate data in rate_diff_partial_rec_id field of account.move. --- .../10.0.1.1/openupgrade_analysis_work.txt | 8 +++----- .../account/migrations/10.0.1.1/post-migration.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt index 2600a9aaa816..1a72f8b41e5f 100644 --- a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -12,9 +12,8 @@ account / account.bank.statement.line / move_name (char) : NEW account / account.full.reconcile / exchange_move_id (many2one) : NEW relation: account.move account / account.full.reconcile / exchange_partial_rec_id (many2one): NEW relation: account.partial.reconcile -# TODO: Can we determine what were the move lines created as part of the -# reconciliation when the exchange rate was different? If we can obtain, then -# update. Otherwise leave blank. +# DONE: Moves for exchange rate differences where in field +# rate_diff_partial_rec_id of account_move. account / account.invoice / refund_invoice_id (many2one) : NEW relation: account.invoice account / account.invoice / website_message_ids (one2many): DEL relation: mail.message @@ -24,8 +23,7 @@ account / account.invoice.line / analytic_tag_ids (many2many) : NEW re # NOTHING TO DO account / account.move / rate_diff_partial_rec_id (many2one): DEL relation: account.partial.reconcile -# TODO: Perhaps it is related to account.full.reconcile -# exchange_partial_rec_id. To be analyzed. +# DONE: The data is now on account.full.reconcile, in the field exchange_partial_rec_id. account / account.move.line / analytic_tag_ids (many2many) : NEW relation: account.analytic.tag # NOTHING TO DO diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py index 4cc21a43e422..c9ebb6f26165 100644 --- a/addons/account/migrations/10.0.1.1/post-migration.py +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -38,3 +38,16 @@ def migrate(env, version): ) AS subquery WHERE account_payment.id = subquery.payment_id ''') + # Move old rate_diff_partial_rec_id in account_move to + # exchange_partial_rec_id in account_full_reconcile: + cr.execute( + '''UPDATE account_full_reconcile + SET exchange_partial_rec_id = subquery.rate_diff_partial_rec_id + FROM ( + SELECT apr.full_reconcile_id, am.rate_diff_partial_rec_id + FROM account_partial_reconcile apr + JOIN account_move am + ON apr.id = am.rate_diff_partial_rec_id + ) AS subquery + WHERE account_full_reconcile.id = subquery.full_reconcile_id + ''') From a2a7f0a80e4ea2f21a922e7d451d71a19e74a110 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Mon, 29 May 2017 17:35:41 +0200 Subject: [PATCH 06/11] [FIX] pip/flake errors. --- addons/account/migrations/10.0.1.1/post-migration.py | 2 ++ addons/account/migrations/10.0.1.1/pre-migration.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py index c9ebb6f26165..06b3f425c133 100644 --- a/addons/account/migrations/10.0.1.1/post-migration.py +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # © 2017 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + @openupgrade.migrate(use_env=True) def migrate(env, version): diff --git a/addons/account/migrations/10.0.1.1/pre-migration.py b/addons/account/migrations/10.0.1.1/pre-migration.py index 4edd04f4c392..aa53f4ac8911 100644 --- a/addons/account/migrations/10.0.1.1/pre-migration.py +++ b/addons/account/migrations/10.0.1.1/pre-migration.py @@ -3,12 +3,13 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from openupgradelib import openupgrade + @openupgrade.migrate(use_env=True) def migrate(env, version): cr = env.cr # copy columns good practice in pre-mig script format of colum_spec should # be: { Table_name_in_db : [( old_column_name , new_column_name, type)] - # defaults of new columname are fetchable via method get_legacy_name + # defaults of new columname are fetchable via method get_legacy_name openupgrade.rename_tables( cr, [ From 8117cf9751f4f0cbbf9a195acb59f175db5264c2 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Fri, 9 Jun 2017 12:40:32 +0200 Subject: [PATCH 07/11] [MGR] Also fill exchange_move_id on account_full_reconcile. --- addons/account/migrations/10.0.1.1/post-migration.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py index 06b3f425c133..dcefa9e76f8b 100644 --- a/addons/account/migrations/10.0.1.1/post-migration.py +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -45,8 +45,12 @@ def migrate(env, version): cr.execute( '''UPDATE account_full_reconcile SET exchange_partial_rec_id = subquery.rate_diff_partial_rec_id + , exchange_move_id = subquery.move_id FROM ( - SELECT apr.full_reconcile_id, am.rate_diff_partial_rec_id + SELECT + apr.full_reconcile_id, + am.rate_diff_partial_rec_id, + am.id as move_id FROM account_partial_reconcile apr JOIN account_move am ON apr.id = am.rate_diff_partial_rec_id From a2a8986cca94beda37205361a923300936bb18ef Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Fri, 9 Jun 2017 13:09:45 +0200 Subject: [PATCH 08/11] [MGR] Fill move_name in account_bank_statement_line. --- .../10.0.1.1/openupgrade_analysis_work.txt | 2 +- addons/account/migrations/10.0.1.1/post-migration.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt index 1a72f8b41e5f..e7716c8ca887 100644 --- a/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/account/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -7,7 +7,7 @@ account / account.bank.statement / website_message_ids (one2many): DEL re # NOTHING TO DO account / account.bank.statement.line / move_name (char) : NEW -# TODO: Calculate during post-migration using the move name associated to the +# DONE: Calculate during post-migration using the move name associated to the # the move lines that have that statement_id account / account.full.reconcile / exchange_move_id (many2one) : NEW relation: account.move diff --git a/addons/account/migrations/10.0.1.1/post-migration.py b/addons/account/migrations/10.0.1.1/post-migration.py index dcefa9e76f8b..60947a4ccaaa 100644 --- a/addons/account/migrations/10.0.1.1/post-migration.py +++ b/addons/account/migrations/10.0.1.1/post-migration.py @@ -57,3 +57,15 @@ def migrate(env, version): ) AS subquery WHERE account_full_reconcile.id = subquery.full_reconcile_id ''') + # Update move_name on account_bank_statement_line: + cr.execute( + '''UPDATE account_bank_statement_line + SET move_name = subquery.name + FROM ( + SELECT + am.name, + am.statement_line_id + FROM account_move am + ) AS subquery + WHERE account_bank_statement_line.id = subquery.statement_line_id + ''') From dcf4767c8ae5dd50e1ea2084b56abd56ccce8c58 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Fri, 9 Jun 2017 16:34:38 +0200 Subject: [PATCH 09/11] [MIG] Patch demo data to enable travis testing. --- addons/account/__manifest__.py | 1 + addons/account/demo/account_invoice_demo.yml | 8 ++++ .../account/demo/openupgrade_account_demo.xml | 39 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 addons/account/demo/openupgrade_account_demo.xml diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index f3699bff5858..f2651884e9bc 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -67,6 +67,7 @@ ], 'demo': [ 'demo/account_demo.xml', + 'demo/openupgrade_account_demo.xml', ], 'qweb': [ "static/src/xml/account_reconciliation.xml", diff --git a/addons/account/demo/account_invoice_demo.yml b/addons/account/demo/account_invoice_demo.yml index 669bb7892fc0..0454b293b263 100644 --- a/addons/account/demo/account_invoice_demo.yml +++ b/addons/account/demo/account_invoice_demo.yml @@ -12,9 +12,11 @@ - product_id: product.consu_delivery_02 price_unit: 642.0 quantity: 5 + account_id: account.openupgrade_demo_sales_account - product_id: product.consu_delivery_03 price_unit: 280.0 quantity: 5.0 + account_id: account.openupgrade_demo_sales_account - !python {model: account.invoice, id: demo_invoice_1}: self.action_invoice_open() @@ -27,9 +29,11 @@ - product_id: product.consu_delivery_03 price_unit: 50.0 quantity: 3 + account_id: account.openupgrade_demo_sales_account - product_id: product.consu_delivery_01 price_unit: 25 quantity: 20 + account_id: account.openupgrade_demo_sales_account - !python {model: account.invoice, id: demo_invoice_2}: self.action_invoice_open() @@ -42,9 +46,11 @@ - product_id: product.consu_delivery_01 price_unit: 90.0 quantity: 5 + account_id: account.openupgrade_demo_sales_account - product_id: product.consu_delivery_03 price_unit: 15.0 quantity: 5.0 + account_id: account.openupgrade_demo_sales_account - !python {model: account.invoice, id: demo_invoice_3}: self.action_invoice_open() @@ -66,10 +72,12 @@ quantity: 1.0 product_id: product.product_delivery_01 uom_id: product.product_uom_unit + account_id: account.openupgrade_demo_purchase_account - price_unit: 4.0 quantity: 1.0 product_id: product.product_order_01 uom_id: product.product_uom_unit + account_id: account.openupgrade_demo_purchase_account - !record {model: account.invoice, id: demo_invoice_january_wages}: partner_id: base.res_partner_12 diff --git a/addons/account/demo/openupgrade_account_demo.xml b/addons/account/demo/openupgrade_account_demo.xml new file mode 100644 index 000000000000..1a92958ee73d --- /dev/null +++ b/addons/account/demo/openupgrade_account_demo.xml @@ -0,0 +1,39 @@ + + + + + + + sales + Sales + other + + + + + + purchase + Purchase + other + + + + From d69cf9e3340a3d0817e818afd12b4c3764faa04d Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Fri, 9 Jun 2017 17:00:21 +0200 Subject: [PATCH 10/11] [MIG] Retry with updated travis comment. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e4f20e684c78..997f110bd34b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,6 +53,7 @@ script: - pip install -q -r requirements.txt # this crashes if there is no test data - if [ -s ../test_data90.yml ]; then ./openerp-server --database=$DB --test-file=`readlink -f ../test_data90.yml` --test-commit --stop-after-init; fi + # Line below may fail occasionaly due to Travis bug: - git reset -q --hard $TRAVIS_COMMIT # Install Python requirements of target release - pip install -q -r requirements.txt From 26320663e86bc3a27671647214355924ea037a2a Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Fri, 9 Jun 2017 17:32:39 +0200 Subject: [PATCH 11/11] [MIG] Invoice lines need name too. --- addons/account/demo/account_invoice_demo.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/account/demo/account_invoice_demo.yml b/addons/account/demo/account_invoice_demo.yml index 0454b293b263..2aca48803584 100644 --- a/addons/account/demo/account_invoice_demo.yml +++ b/addons/account/demo/account_invoice_demo.yml @@ -13,10 +13,12 @@ price_unit: 642.0 quantity: 5 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_02' - product_id: product.consu_delivery_03 price_unit: 280.0 quantity: 5.0 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_03' - !python {model: account.invoice, id: demo_invoice_1}: self.action_invoice_open() @@ -30,10 +32,12 @@ price_unit: 50.0 quantity: 3 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_03' - product_id: product.consu_delivery_01 price_unit: 25 quantity: 20 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_01' - !python {model: account.invoice, id: demo_invoice_2}: self.action_invoice_open() @@ -47,10 +51,12 @@ price_unit: 90.0 quantity: 5 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_01' - product_id: product.consu_delivery_03 price_unit: 15.0 quantity: 5.0 account_id: account.openupgrade_demo_sales_account + name: 'consu_delivery_03' - !python {model: account.invoice, id: demo_invoice_3}: self.action_invoice_open() @@ -73,11 +79,13 @@ product_id: product.product_delivery_01 uom_id: product.product_uom_unit account_id: account.openupgrade_demo_purchase_account + name: 'product_delivery_01' - price_unit: 4.0 quantity: 1.0 product_id: product.product_order_01 uom_id: product.product_uom_unit account_id: account.openupgrade_demo_purchase_account + name: 'product_order_01' - !record {model: account.invoice, id: demo_invoice_january_wages}: partner_id: base.res_partner_12