Commits

Sergi Almacellas Abellana committed b3d8325

Separate tryton modules into two submodules

account_es contains full chart of accounts (with groups 8 and 9)
account_es_pyme contains abbreviated chart of accounts (without groups 8 and 9)

  • Participants
  • Parent commits 294d416

Comments (0)

Files changed (1)

File OpenERP_XML_2_Tryton.py

 oerp_addons_path = '../openerp-server6/bin/addons/'
 tryton_modules_path = '../trytond/trytond/modules/'
 account_module = 'account_es'
+account_pyme_module = 'account_es_pyme'
 #End configuration
 
 from lxml import etree
 
 def search_and_get_tax_group(file_name=False, oerp_record=False, oerp_field=False):
     if 'pymes' in file_name:
-        xml = etree.parse(tryton_modules_path+account_module+'/tax_data_pymes.xml')
+        xml = etree.parse(tryton_modules_path+account_pyme_module+'/tax_data_pymes.xml')
     else:
         xml = etree.parse(tryton_modules_path+account_module+'/tax_data.xml')
     root = xml.getroot()
 }
 
 if __name__ == "__main__":
-    tryton_account_module = '%s%s' % (tryton_modules_path, account_module)
-    if not os.path.exists(tryton_account_module):
-        os.makedirs(tryton_account_module)
-    archives = [
-#        (tryton_modules_path+'account_es/account_tax_group.xml',
-#         tryton_modules_path+'account_es/account_tax_group.xml'),
-        (oerp_addons_path+'l10n_es_account_balance_report/data/balance_normal.xml',
-         tryton_modules_path+'account_es/balance.xml'),
-        (oerp_addons_path+'l10n_es_account_balance_report/data/pyg_normal.xml',
-         tryton_modules_path+'account_es/pyg.xml'),
-        (oerp_addons_path+'l10n_es_account_balance_report/data/estado_ingresos_gastos_normal.xml',
-         tryton_modules_path+'account_es/estado_ingresos_gastos_normal.xml'),
-        (oerp_addons_path+'l10n_es/account_chart.xml',
-         tryton_modules_path+'account_es/account_es.xml'),
-        (oerp_addons_path+'l10n_es/taxes_data.xml',
-         tryton_modules_path+'account_es/tax_data.xml'),
-        (oerp_addons_path+'l10n_es/fiscal_templates.xml',
-         tryton_modules_path+'account_es/tax_rule_templates.xml'),
-        (oerp_addons_path+'l10n_es_account_balance_report/data/balance_pymes.xml',
-         tryton_modules_path+'account_es/balance_pymes.xml'),
-        (oerp_addons_path+'l10n_es_account_balance_report/data/pyg_pymes.xml',
-         tryton_modules_path+'account_es/pyg_pymes.xml'),
-        (oerp_addons_path+'l10n_es/account_chart_pymes.xml',
-         tryton_modules_path+'account_es/account_es_pymes.xml'),
-        (oerp_addons_path+'l10n_es/taxes_data_pymes.xml',
-         tryton_modules_path+'account_es/tax_data_pymes.xml'),
-        (oerp_addons_path+'l10n_es/fiscal_templates_pymes.xml',
-         tryton_modules_path+'account_es/tax_rule_templates_pymes.xml'),
-    ]
-    for oerp_file_name, tryton_file_name in archives:
-        main(oerp_file_name, tryton_file_name)
+    #Archives mapping:
+    #   key -> tryton module.
+    #   value -> list of mappings between modules
+    archives = {
+     account_module : [
+#        (tryton_modules_path+account_module+'/account_tax_group.xml',
+#         tryton_modules_path+account_module+'/account_tax_group.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/balance_normal.xml',
+             tryton_modules_path+account_module+'/balance.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/pyg_normal.xml',
+             tryton_modules_path+account_module+'/pyg.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/estado_ingresos_gastos_normal.xml',
+             tryton_modules_path+account_module+'/estado_ingresos_gastos_normal.xml'),
+            (oerp_addons_path+'l10n_es/account_chart.xml',
+             tryton_modules_path+account_module+'/account_es.xml'),
+            (oerp_addons_path+'l10n_es/taxes_data.xml',
+             tryton_modules_path+account_module+'/tax_data.xml'),
+            (oerp_addons_path+'l10n_es/fiscal_templates.xml',
+             tryton_modules_path+account_module+'/tax_rule_templates.xml'),
+        ],
+     account_pyme_module : [
+#        (tryton_modules_path+account_pyme_module+'/account_tax_group.xml',
+#         tryton_modules_path+account_pyme_module+'/account_tax_group.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/estado_ingresos_gastos_normal.xml',
+             tryton_modules_path+account_pyme_module+'/estado_ingresos_gastos_normal.xml'),
+            (oerp_addons_path+'l10n_es/taxes_data.xml',
+             tryton_modules_path+account_pyme_module+'/tax_data.xml'),
+            (oerp_addons_path+'l10n_es/fiscal_templates.xml',
+             tryton_modules_path+account_pyme_module+'/tax_rule_templates.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/balance_pymes.xml',
+             tryton_modules_path+account_pyme_module+'/balance_pymes.xml'),
+            (oerp_addons_path+'l10n_es_account_balance_report/data/pyg_pymes.xml',
+             tryton_modules_path+account_pyme_module+'/pyg_pymes.xml'),
+            (oerp_addons_path+'l10n_es/account_chart_pymes.xml',
+             tryton_modules_path+account_pyme_module+'/account_es_pymes.xml'),
+            (oerp_addons_path+'l10n_es/taxes_data_pymes.xml',
+             tryton_modules_path+account_pyme_module+'/tax_data_pymes.xml'),
+            (oerp_addons_path+'l10n_es/fiscal_templates_pymes.xml',
+             tryton_modules_path+account_pyme_module+'/tax_rule_templates_pymes.xml'),
+        ],
+    }
+    for module_name in [account_module,account_pyme_module]:
+        print "Working on %s" % module_name
+        tryton_account_module = '%s%s' % (tryton_modules_path, module_name)
+        if not os.path.exists(tryton_account_module):
+            os.makedirs(tryton_account_module)
+        for oerp_file_name, tryton_file_name in archives[module_name]:
+            print "Migrating %s to %s "  % (oerp_file_name, tryton_file_name)
+            main(oerp_file_name, tryton_file_name)
 
-        infile = open(tryton_file_name, 'r') # open file for reading
-        outfile = open(tryton_file_name+"2","w") # open file for writing
-        
-        regex1 = re.compile("<field")
-        regex2 = re.compile(r'( name=".*")')
-        
-        line = infile.readline()    # Invokes readline() method on file
-        while line:
-            found = regex1.search(line)
-            if found:
-                pos = found.end()
-                name_attr = regex2.findall(line)
-                line = regex2.sub("", line)
-                line = line[:pos]+name_attr[0]+line[pos:]
-            outfile.write(line),
-            line = infile.readline()
-        
-        infile.close()
-        outfile.close()
-        os.rename(tryton_file_name+"2", tryton_file_name)
+            infile = open(tryton_file_name, 'r') # open file for reading
+            outfile = open(tryton_file_name+"2","w") # open file for writing
+            
+            regex1 = re.compile("<field")
+            regex2 = re.compile(r'( name=".*")')
+            
+            line = infile.readline()    # Invokes readline() method on file
+            while line:
+                found = regex1.search(line)
+                if found:
+                    pos = found.end()
+                    name_attr = regex2.findall(line)
+                    line = regex2.sub("", line)
+                    line = line[:pos]+name_attr[0]+line[pos:]
+                outfile.write(line),
+                line = infile.readline()
+            
+            infile.close()
+            outfile.close()
+            os.rename(tryton_file_name+"2", tryton_file_name)