diff --git a/addons/analytic/migrations/10.0.1.1/openupgrade_analysis_work.txt b/addons/analytic/migrations/10.0.1.1/openupgrade_analysis_work.txt index c4f2dafab848..fd90723642e3 100644 --- a/addons/analytic/migrations/10.0.1.1/openupgrade_analysis_work.txt +++ b/addons/analytic/migrations/10.0.1.1/openupgrade_analysis_work.txt @@ -1,8 +1,9 @@ ---Fields in module 'analytic'--- analytic / account.analytic.account / account_type (selection) : DEL required: required, selection_keys: ['closed', 'normal'], req_default: normal -# TODO: pre-migraton: copy to new column analytic / account.analytic.account / active (boolean) : NEW -# TODO: post-migraton: if account_type = closed, then set to False +#copied old account type field in pre and mapped to the new boolean in post +#(both closed = False and normal=True , this last map is a redundant because +#default is true) ---XML records in module 'analytic'--- NEW ir.actions.act_window: analytic.account_analytic_tag_action DEL ir.actions.act_window: analytic.action_account_analytic_chart diff --git a/addons/analytic/migrations/10.0.1.1/post-migration.py b/addons/analytic/migrations/10.0.1.1/post-migration.py new file mode 100644 index 000000000000..11c7dcb15ee3 --- /dev/null +++ b/addons/analytic/migrations/10.0.1.1/post-migration.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +def deactivate_closed_accounts(cr): + # not using sql to restore account_type but map values + openupgrade.map_values( + cr, openupgrade.get_legacy_name('account_type'), + 'active', [('closed' , False) , ('normal', True)], + table='account_analytic_account', + write='sql' + ) + +@openupgrade.migrate(use_env=True) +def migrate(env, version): + cr = env.cr + deactivate_closed_accounts(cr) diff --git a/addons/analytic/migrations/10.0.1.1/pre-migration.py b/addons/analytic/migrations/10.0.1.1/pre-migration.py new file mode 100644 index 000000000000..78ffdf8adb7d --- /dev/null +++ b/addons/analytic/migrations/10.0.1.1/pre-migration.py @@ -0,0 +1,16 @@ +# -*- 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.copy_columns(cr, { + 'account_analytic_account' : [ + ('account_type', None, None), + ], + }) diff --git a/addons/analytic/migrations/10.0.1.1/tests/analytic_data_v10.yml b/addons/analytic/migrations/10.0.1.1/tests/analytic_data_v10.yml new file mode 100644 index 000000000000..fab0e3247f4e --- /dev/null +++ b/addons/analytic/migrations/10.0.1.1/tests/analytic_data_v10.yml @@ -0,0 +1,15 @@ +- +this file contains data for automated testing the migration on travis +- + +- + create some account_analytic_account that have type == 'closed', in casde the db does not have them in order to verify that the script works and that it will transform those in v10.0 bool ean field active = False +- + !record {model: account.analytic.account, id: analytic.ou_analytic_account_c1}: + name: 'OU Test closed' + type: 'closed' +- + !record {model: account.analytic.account, id: analytic.ou_analytic_account_n1}: + name: 'OU Test normal 2' + type: 'normal' +- diff --git a/addons/analytic/migrations/10.0.1.1/tests/test_analytic.py b/addons/analytic/migrations/10.0.1.1/tests/test_analytic.py new file mode 100644 index 000000000000..ee3f1d43c2ca --- /dev/null +++ b/addons/analytic/migrations/10.0.1.1/tests/test_analytic.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from openerp.tests.common import TransactionCase + + +class TestAnalytic(TransactionCase) + + def test_analytic(self): + self.assertTrue( + self.env.ref('analytic.ou_analytic_account_c1').active == False + ) + self.assertTrue( + self.env.ref('analytic.ou_analytic_account_n1').active == True + ) diff --git a/odoo/openupgrade/doc/source/modules90-100.rst b/odoo/openupgrade/doc/source/modules90-100.rst index 91ce5a35edc3..a50cb69155e4 100644 --- a/odoo/openupgrade/doc/source/modules90-100.rst +++ b/odoo/openupgrade/doc/source/modules90-100.rst @@ -49,7 +49,7 @@ Status : +-----------------------------------+-----------------------------------+ |account_voucher | | +-----------------------------------+-----------------------------------+ -|analytic | | +|analytic | Done +-----------------------------------+-----------------------------------+ |anonymization | | +-----------------------------------+-----------------------------------+