Merge lp:~hbee/openupgrade-addons/6.1-l10n_be into lp:openupgrade-addons/6.1

Proposed by Paulius Sladkevičius @ hbee
Status: Merged
Merged at revision: 6618
Proposed branch: lp:~hbee/openupgrade-addons/6.1-l10n_be
Merge into: lp:openupgrade-addons/6.1
Diff against target: 61 lines (+57/-0)
1 file modified
l10n_be/migrations/6.1.1.1/pre-migration.py (+57/-0)
To merge this branch: bzr merge lp:~hbee/openupgrade-addons/6.1-l10n_be
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Stefan Rijnhart (Opener) Approve
Review via email: mp+168487@code.launchpad.net

Description of the change

Adds migration script for l10n_be

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! I read the code and compared it with the analysis file in l10n_be/migrations/6.1.1.1 directory. When I noticed one account type missing, I checked the module code in openobject-addons/6.0 and saw that 'user_type_tiers' was not used anywhere. Also verified that the obsolete sequence l10n_be.seq_controlref was not used anywhere anymore. Great job!

review: Approve
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'l10n_be/migrations/6.1.1.1/pre-migration.py'
2--- l10n_be/migrations/6.1.1.1/pre-migration.py 1970-01-01 00:00:00 +0000
3+++ l10n_be/migrations/6.1.1.1/pre-migration.py 2013-06-10 16:30:49 +0000
4@@ -0,0 +1,57 @@
5+# -*- coding: utf-8 -*-
6+##############################################################################
7+#
8+# OpenERP, Open Source Management Solution
9+# This module copyright (C) 2013 HacBee (<http://hbee.eu>).
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as
13+# published by the Free Software Foundation, either version 3 of the
14+# License, or (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+import pooler
27+from openerp.openupgrade import openupgrade
28+from openerp import SUPERUSER_ID
29+
30+ACCOUNT_TYPE_XMLID_MAP = [
31+ ('l10n_be.user_type_capitaux', 'account.data_account_type_liability'),
32+ ('l10n_be.user_type_immo', 'account.data_account_type_asset'),
33+ ('l10n_be.user_type_tiers_receiv', 'account.data_account_type_receivable'),
34+ ('l10n_be.user_type_tiers_payable', 'account.data_account_type_payable'),
35+ ('l10n_be.user_type_tax', 'account.data_account_type_receivable'),
36+ ('l10n_be.user_type_financiers', 'account.data_account_type_cash'),
37+ ('l10n_be.user_type_charge', 'account.data_account_type_expense'),
38+ ('l10n_be.user_type_produit', 'account.data_account_type_income'),
39+]
40+
41+def _get_id(cr, xml_id):
42+ pool = pooler.get_pool(cr.dbname)
43+ ir_model_data_obj = pool.get('ir.model.data')
44+ module, xml_id = xml_id.split('.')
45+ model, res_id = ir_model_data_obj.get_object_reference(cr, SUPERUSER_ID,
46+ module, xml_id)
47+ return res_id
48+
49+def map_account_types(cr):
50+ for oldxmlid, newxmlid in ACCOUNT_TYPE_XMLID_MAP:
51+ old_id = _get_id(cr, oldxmlid)
52+ new_id = _get_id(cr, newxmlid)
53+ cr.execute("""
54+ UPDATE account_account
55+ SET user_type = %s
56+ WHERE user_type = %s
57+ """, (new_id, old_id))
58+
59+@openupgrade.migrate()
60+def migrate(cr, version):
61+ map_account_types(cr)

Subscribers

People subscribed via source and target branches