← Back to team overview

credativ team mailing list archive

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

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence into lp:openupgrade-addons/6.1.

Requested reviews:
  OpenUpgrade Committers (openupgrade-committers)
Related bugs:
  Bug #1168936 in OpenUpgrade Addons: "[6.1, account] Tax report in random order because of missing tax code sequences"
  https://bugs.launchpad.net/openupgrade-addons/+bug/1168936

For more details, see:
https://code.launchpad.net/~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence/+merge/158803
-- 
https://code.launchpad.net/~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence/+merge/158803
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~therp-nl/openupgrade-addons/6.1-lp1168936-tax_code_sequence into lp:openupgrade-addons/6.1.
=== modified file 'account/migrations/6.1.1.1/post-migration.py'
--- account/migrations/6.1.1.1/post-migration.py	2012-06-22 07:15:08 +0000
+++ account/migrations/6.1.1.1/post-migration.py	2013-04-14 18:33:28 +0000
@@ -19,14 +19,10 @@
 #
 ##############################################################################
 
-from osv import osv
-import pooler, logging
+import pooler
 from openerp import SUPERUSER_ID
 from openerp.openupgrade import openupgrade
 
-logger = logging.getLogger('OpenUpgrade')
-me = __file__
-
 def write_account_report_type(cr):
     pool = pooler.get_pool(cr.dbname)
     type_obj = pool.get('account.account.type')
@@ -39,15 +35,35 @@
     openupgrade.drop_columns(
         cr, [('account_account_type', 'report_type_tmp')])
 
+def assign_tax_code_sequence(cr):
+    """
+    Tax codes in the tax report (on the same level in the hierarchy)
+    are now sorted by 'sequence'. Previously, the tax report was sorted
+    by tax code's 'code'. The sequence in new installations is derived
+    from tax code templates, so existing tax codes cannot be updated by
+    XML ID. Therefore, assign a sequence based on the tax code's code.
+    """
+    cr.execute("""
+        UPDATE account_tax_code AS atc
+        SET sequence = (
+            SELECT 5 * COUNT(*)
+            FROM account_tax_code
+            WHERE code < atc.code);
+        """)
+
+@openupgrade.migrate()
 def migrate(cr, version):
-    try:
-        logger.info("%s called", me)
-        openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/data_account_type.xml')
-        openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/account_financial_report_data.xml')
-        openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/invoice_action_data.xml')
-        openupgrade.load_data(cr, 'account', 'migrations/6.1.1.1/data/null_values.xml')
-        write_account_report_type(cr)
-
-    except Exception, e:
-        raise osv.except_osv("BREAK", "OpenUpgrade", '%s: %s' % (me, e))
-        raise osv.except_osv("OpenUpgrade", '%s: %s' % (me, e))
+    openupgrade.load_data(
+        cr, 'account',
+        'migrations/6.1.1.1/data/data_account_type.xml')
+    openupgrade.load_data(
+        cr, 'account',
+        'migrations/6.1.1.1/data/account_financial_report_data.xml')
+    openupgrade.load_data(
+        cr, 'account',
+        'migrations/6.1.1.1/data/invoice_action_data.xml')
+    openupgrade.load_data(
+        cr, 'account',
+        'migrations/6.1.1.1/data/null_values.xml')
+    write_account_report_type(cr)
+    assign_tax_code_sequence(cr)


Follow ups