Merge lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence into lp:openupgrade-addons/6.1

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 6617
Proposed branch: lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence
Merge into: lp:openupgrade-addons/6.1
Diff against target: 66 lines (+32/-16)
1 file modified
account/migrations/6.1.1.1/post-migration.py (+32/-16)
To merge this branch: bzr merge lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Approve
Review via email: mp+158803@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/migrations/6.1.1.1/post-migration.py'
2--- account/migrations/6.1.1.1/post-migration.py 2012-06-22 07:15:08 +0000
3+++ account/migrations/6.1.1.1/post-migration.py 2013-04-14 18:33:28 +0000
4@@ -19,14 +19,10 @@
5 #
6 ##############################################################################
7
8-from osv import osv
9-import pooler, logging
10+import pooler
11 from openerp import SUPERUSER_ID
12 from openerp.openupgrade import openupgrade
13
14-logger = logging.getLogger('OpenUpgrade')
15-me = __file__
16-
17 def write_account_report_type(cr):
18 pool = pooler.get_pool(cr.dbname)
19 type_obj = pool.get('account.account.type')
20@@ -39,15 +35,35 @@
21 openupgrade.drop_columns(
22 cr, [('account_account_type', 'report_type_tmp')])
23
24+def assign_tax_code_sequence(cr):
25+ """
26+ Tax codes in the tax report (on the same level in the hierarchy)
27+ are now sorted by 'sequence'. Previously, the tax report was sorted
28+ by tax code's 'code'. The sequence in new installations is derived
29+ from tax code templates, so existing tax codes cannot be updated by
30+ XML ID. Therefore, assign a sequence based on the tax code's code.
31+ """
32+ cr.execute("""
33+ UPDATE account_tax_code AS atc
34+ SET sequence = (
35+ SELECT 5 * COUNT(*)
36+ FROM account_tax_code
37+ WHERE code < atc.code);
38+ """)
39+
40+@openupgrade.migrate()
41 def migrate(cr, version):
42- try:
43- logger.info("%s called", me)
44- openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/data_account_type.xml')
45- openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/account_financial_report_data.xml')
46- openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/invoice_action_data.xml')
47- openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/null_values.xml')
48- write_account_report_type(cr)
49-
50- except Exception, e:
51- raise osv.except_osv("BREAK", "OpenUpgrade", '%s: %s' % (me, e))
52- raise osv.except_osv("OpenUpgrade", '%s: %s' % (me, e))
53+ openupgrade.load_data(
54+ cr, 'account',
55+ 'migrations/6.1.1.1/data/data_account_type.xml')
56+ openupgrade.load_data(
57+ cr, 'account',
58+ 'migrations/6.1.1.1/data/account_financial_report_data.xml')
59+ openupgrade.load_data(
60+ cr, 'account',
61+ 'migrations/6.1.1.1/data/invoice_action_data.xml')
62+ openupgrade.load_data(
63+ cr, 'account',
64+ 'migrations/6.1.1.1/data/null_values.xml')
65+ write_account_report_type(cr)
66+ assign_tax_code_sequence(cr)

Subscribers

People subscribed via source and target branches