[MERGE] merged with main trunk
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Mon, 5 Dec 2011 15:08:19 +0000 (16:08 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Mon, 5 Dec 2011 15:08:19 +0000 (16:08 +0100)
bzr revid: qdp-launchpad@openerp.com-20111205150819-tuzcw6v25wp2aq9r

1  2 
addons/account/__openerp__.py
addons/account/account.py

@@@ -98,7 -98,6 +98,7 @@@ module named account_voucher
          'wizard/account_reconcile_view.xml',
          'wizard/account_reconcile_partner_process_view.xml',
          'wizard/account_automatic_reconcile_view.xml',
 +        'wizard/account_tax_generate_view.xml',
          'wizard/account_financial_report_view.xml',
          'project/wizard/project_account_analytic_line_view.xml',
          'account_end_fy.xml',
          'test/account_change_currency.yml',
          'test/chart_of_account.yml',
          'test/account_period_close.yml',
-         'test/account_fiscalyear_close_state.yml',
          'test/account_use_model.yml',
          'test/account_validate_account_move.yml',
          'test/account_fiscalyear_close.yml',
          'test/account_cash_statement.yml',
          'test/test_edi_invoice.yml',
          'test/account_report.yml',
+         'test/account_fiscalyear_close_state.yml', #last test, as it will definitively close the demo fiscalyear
      ],
      'installable': True,
      'active': False,
@@@ -760,7 -760,6 +760,7 @@@ class account_journal(osv.osv)
  
          seq = {
              'name': vals['name'],
 +            'company_id': vals['company_id'],
              'implementation':'no_gap',
              'prefix': prefix + "/%(year)s/",
              'padding': 4,
@@@ -881,7 -880,7 +881,7 @@@ class account_fiscalyear(osv.osv)
          for fy in self.browse(cr, uid, ids, context=context):
              ds = datetime.strptime(fy.date_start, '%Y-%m-%d')
              period_obj.create(cr, uid, {
-                     'name': _('Opening Period'),
+                     'name':  "%s %s" % (_('Opening Period'), ds.strftime('%Y')),
                      'code': ds.strftime('00/%Y'),
                      'date_start': ds,
                      'date_stop': ds,
@@@ -2428,7 -2427,6 +2428,7 @@@ class account_account_template(osv.osv)
          'child_parent_ids':fields.one2many('account.account.template', 'parent_id', 'Children'),
          'tax_ids': fields.many2many('account.tax.template', 'account_account_template_tax_rel', 'account_id', 'tax_id', 'Default Taxes'),
          'nocreate': fields.boolean('Optional create', help="If checked, the new chart of accounts will not contain this by default."),
 +        'chart_template_id': fields.many2one('account.chart.template', 'Chart Template'),
      }
  
      _defaults = {
              res.append((record['id'],name ))
          return res
  
 +    def generate_account(self, cr, uid, template_id, tax_template_ref, code_digits, company_id, context=None):
 +        """
 +        This method for generating accounts from templates.
 +        @param cr: A database cursor.
 +        @param uid: ID of the user currently logged in.
 +        @param account_root_id: Root account id getting from current template.
 +        @param tax_template_ref: Taxes templates reference for write taxes_id in account_account.
 +        @param code_digits: Digit getting from wizard.multi.charts.accounts.,this is use for account code.
 +        @param company_id: company_id selected from wizard.multi.charts.accounts.
 +        @return : return acc_template_ref for reference purpose.
 +        
 +        """
 +        if context is None:
 +            context = {}
 +        obj_acc = self.pool.get('account.account')
 +        company_name = self.pool.get('res.company').browse(cr, uid, company_id, context=context).name
 +        template = self.pool.get('account.chart.template').browse(cr, uid, template_id, context=context)
 +        acc_template_ref = {}
 +        #deactivate the parent_store functionnality on account_account for rapidity purpose
 +        ctx = context.copy()
 +        ctx.update({'defer_parent_store_computation': True})
 +        children_acc_template = self.search(cr, uid, [('parent_id','child_of', [template.account_root_id.id]),'|', ('chart_template_id','=', [template_id]),('chart_template_id','=', False), ('nocreate','!=',True)], order='id')
 +        for account_template in self.browse(cr, uid, children_acc_template, context=context):
 +            tax_ids = []
 +            for tax in account_template.tax_ids:
 +                tax_ids.append(tax_template_ref[tax.id])
 +
 +            code_main = account_template.code and len(account_template.code) or 0
 +            code_acc = account_template.code or ''
 +            if code_main > 0 and code_main <= code_digits and account_template.type != 'view':
 +                code_acc = str(code_acc) + (str('0'*(code_digits-code_main)))
 +            vals={
 +                'name': (template.account_root_id.id == account_template.id) and company_name or account_template.name,
 +                'currency_id': account_template.currency_id and account_template.currency_id.id or False,
 +                'code': code_acc,
 +                'type': account_template.type,
 +                'user_type': account_template.user_type and account_template.user_type.id or False,
 +                'reconcile': account_template.reconcile,
 +                'shortcut': account_template.shortcut,
 +                'note': account_template.note,
 +                'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False,
 +                'tax_ids': [(6,0,tax_ids)],
 +                'company_id': company_id,
 +            }
 +            new_account = obj_acc.create(cr, uid, vals, context=ctx)
 +            acc_template_ref[account_template.id] = new_account
 +
 +        #reactivate the parent_store functionnality on account_account
 +        obj_acc._parent_store_compute(cr)
 +        return acc_template_ref
 +
  account_account_template()
  
  class account_add_tmpl_wizard(osv.osv_memory):
@@@ -2616,28 -2563,19 +2616,28 @@@ class account_chart_template(osv.osv)
  
      _columns={
          'name': fields.char('Name', size=64, required=True),
 -        'account_root_id': fields.many2one('account.account.template','Root Account',required=True,domain=[('parent_id','=',False)]),
 -        'tax_code_root_id': fields.many2one('account.tax.code.template','Root Tax Code',required=True,domain=[('parent_id','=',False)]),
 +        'parent_id': fields.many2one('account.chart.template', 'Parent Chart Template'),
 +        'code_digits': fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"), 
 +        'visible': fields.boolean('Can be Visible?', help="Set this to False if you don't want this template to be used actively in the wizard that generate Chart of Accounts from templates, this is useful when you want to generate accounts of this template only when loading its child template."),
 +        'set_tax_complete': fields.boolean('Complete Set of Tax', help="Check this if you want to create new default Sales and Purchase taxes from selected rate instead of choosing it from list of taxes."),
 +        'account_root_id': fields.many2one('account.account.template', 'Root Account', domain=[('parent_id','=',False)]),
 +        'tax_code_root_id': fields.many2one('account.tax.code.template', 'Root Tax Code', domain=[('parent_id','=',False)]),
          'tax_template_ids': fields.one2many('account.tax.template', 'chart_template_id', 'Tax Template List', help='List of all the taxes that have to be installed by the wizard'),
 -        'bank_account_view_id': fields.many2one('account.account.template','Bank Account',required=True),
 -        'property_account_receivable': fields.many2one('account.account.template','Receivable Account'),
 -        'property_account_payable': fields.many2one('account.account.template','Payable Account'),
 -        'property_account_expense_categ': fields.many2one('account.account.template','Expense Category Account'),
 -        'property_account_income_categ': fields.many2one('account.account.template','Income Category Account'),
 -        'property_account_expense': fields.many2one('account.account.template','Expense Account on Product Template'),
 -        'property_account_income': fields.many2one('account.account.template','Income Account on Product Template'),
 +        'bank_account_view_id': fields.many2one('account.account.template', 'Bank Account'),
 +        'property_account_receivable': fields.many2one('account.account.template', 'Receivable Account'),
 +        'property_account_payable': fields.many2one('account.account.template', 'Payable Account'),
 +        'property_account_expense_categ': fields.many2one('account.account.template', 'Expense Category Account'),
 +        'property_account_income_categ': fields.many2one('account.account.template', 'Income Category Account'),
 +        'property_account_expense': fields.many2one('account.account.template', 'Expense Account on Product Template'),
 +        'property_account_income': fields.many2one('account.account.template', 'Income Account on Product Template'),
          'property_reserve_and_surplus_account': fields.many2one('account.account.template', 'Reserve and Profit/Loss Account', domain=[('type', '=', 'payable')], help='This Account is used for transferring Profit/Loss(If It is Profit: Amount will be added, Loss: Amount will be deducted.), Which is calculated from Profilt & Loss Report'),
 -        'property_account_income_opening': fields.many2one('account.account.template','Opening Entries Income Account'),
 -        'property_account_expense_opening': fields.many2one('account.account.template','Opening Entries Expense Account'),
 +        'property_account_income_opening': fields.many2one('account.account.template', 'Opening Entries Income Account'),
 +        'property_account_expense_opening': fields.many2one('account.account.template', 'Opening Entries Expense Account'),
 +    }
 +
 +    _defaults = {
 +        'visible': True,
 +        'code_digits': 6
      }
  
  account_chart_template()
@@@ -2681,7 -2619,6 +2681,7 @@@ class account_tax_template(osv.osv)
          'description': fields.char('Internal Name', size=32),
          'type_tax_use': fields.selection([('sale','Sale'),('purchase','Purchase'),('all','All')], 'Tax Use In', required=True,),
          'price_include': fields.boolean('Tax Included in Price', help="Check this if the price you use on the product and invoices includes this tax."),
 +        'installable': fields.boolean('Should be Installed', help="Set this to False if you do not want to create real tax object from this template.")
      }
  
      def name_get(self, cr, uid, ids, context=None):
          'include_base_amount': False,
          'type_tax_use': 'all',
          'price_include': 0,
 +        'installable': True
      }
      _order = 'sequence'
  
 +    def generate_tax(self, cr, uid, tax_templates, tax_code_template_ref, company_id, context=None):
 +        """
 +        This method generate taxes from templates.
 +        @param cr: A database cursor.
 +        @param uid: ID of the user currently logged in.
 +        @param tax_templates: Tax templates.
 +        @param tax_code_template_ref: Taxcode templates reference.
 +        @param company_id: if tax generated from account multi wizard at that time company_id is wizard company_id field
 +        or logged user company_id.
 +        @param Return: 
 +        {'taxes_id': New generated taxes ids, 
 +         'account_dict': Used this reference value for Account Tax, 
 +         'tax_template_ref': Used this reference value for Fiscal Position
 +        }
 +        """
 +        if context is None:
 +            context = {}
 +        res = {}
 +        todo_dict = {}
 +        tax_template_ref = {}
 +        tax_template_to_tax = {}
 +        for tax in tax_templates:
 +            vals_tax = {
 +                'name':tax.name,
 +                'sequence': tax.sequence,
 +                'amount': tax.amount,
 +                'type': tax.type,
 +                'applicable_type': tax.applicable_type,
 +                'domain': tax.domain,
 +                'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False,
 +                'child_depend': tax.child_depend,
 +                'python_compute': tax.python_compute,
 +                'python_compute_inv': tax.python_compute_inv,
 +                'python_applicable': tax.python_applicable,
 +                'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False,
 +                'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False,
 +                'base_sign': tax.base_sign,
 +                'tax_sign': tax.tax_sign,
 +                'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False,
 +                'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False,
 +                'ref_base_sign': tax.ref_base_sign,
 +                'ref_tax_sign': tax.ref_tax_sign,
 +                'include_base_amount': tax.include_base_amount,
 +                'description': tax.description,
 +                'company_id': company_id,
 +                'type_tax_use': tax.type_tax_use,
 +                'price_include': tax.price_include
 +            }
 +            new_tax = self.pool.get('account.tax').create(cr, uid, vals_tax)
 +            tax_template_to_tax[tax.id] = new_tax
 +            #as the accounts have not been created yet, we have to wait before filling these fields
 +            todo_dict[new_tax] = {
 +                'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
 +                'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False,
 +            }
 +            tax_template_ref[tax.id] = new_tax
 +        res.update({'taxes_id': tax_template_to_tax, 'account_dict': todo_dict, 'tax_template_ref': tax_template_ref})
 +        return res
 +
  account_tax_template()
  
  # Fiscal Position Templates
@@@ -2792,38 -2669,6 +2792,38 @@@ class account_fiscal_position_template(
          'note': fields.text('Notes', translate=True),
      }
  
 +    def generate_fiscal_position(self, cr, uid, chart_temp_id, tax_template_ref, acc_template_ref, company_id, context=None):
 +        """
 +        This method generate Fiscal Position , Fiscal Position Accounts and Fiscal Position Taxes from templates.
 +        @param cr: A database cursor.
 +        @param uid: ID of the user currently logged in.
 +        @param chart_temp_id: Chart Template Id.
 +        @param taxes_ids: Taxes templates reference for generating account.fiscal.position.tax.
 +        @param acc_template_ref: Account templates reference for generating account.fiscal.position.account.
 +        @param company_id: company_id selected from wizard.multi.charts.accounts.
 +        """
 +        if context is None:
 +            context = {}
 +        obj_tax_fp = self.pool.get('account.fiscal.position.tax')
 +        obj_ac_fp = self.pool.get('account.fiscal.position.account')
 +        obj_fiscal_position = self.pool.get('account.fiscal.position')
 +        fp_ids = self.search(cr, uid, [('chart_template_id', '=', chart_temp_id)])
 +        for position in self.browse(cr, uid, fp_ids, context=context):
 +            new_fp = obj_fiscal_position.create(cr, uid, {'company_id': company_id, 'name': position.name})
 +            for tax in position.tax_ids:
 +                obj_tax_fp.create(cr, uid, {
 +                    'tax_src_id': tax_template_ref[tax.tax_src_id.id],
 +                    'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
 +                    'position_id': new_fp
 +                })
 +            for acc in position.account_ids:
 +                obj_ac_fp.create(cr, uid, {
 +                    'account_src_id': acc_template_ref[acc.account_src_id.id],
 +                    'account_dest_id': acc_template_ref[acc.account_dest_id.id],
 +                    'position_id': new_fp
 +                })
 +        return {}
 +
  account_fiscal_position_template()
  
  class account_fiscal_position_tax_template(osv.osv):
@@@ -2956,66 -2801,68 +2956,66 @@@ class wizard_multi_charts_accounts(osv.
          'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True),
          'code_digits':fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"),
          'seq_journal':fields.boolean('Separated Journal Sequences', help="Check this box if you want to use a different sequence for each created journal. Otherwise, all will use the same sequence."),
 -        "sale_tax": fields.many2one("account.tax.template", "Default Sale Tax"),
 +        "sale_tax": fields.many2one("account.tax.template", "Default Sales Tax"),
          "purchase_tax": fields.many2one("account.tax.template", "Default Purchase Tax"),
 +        'sale_tax_rate': fields.float('Sales Tax(%)'),
 +        'purchase_tax_rate': fields.float('Purchase Tax(%)'),
 +        'complete_tax': fields.boolean('Complete Tax'),
      }
      def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None):
          res = {}
 -        res['value'] = {}
 -        res['value']["sale_tax"] = False
 -        res['value']["purchase_tax"] = False
 +        tax_templ_obj = self.pool.get('account.tax.template')
 +        res['value'] = {'complete_tax': False, 'sale_tax': False, 'purchase_tax': False, 'code_digits': 0}
          if chart_template_id:
 -            # default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while installing the generic chart of accounts
 -            sale_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
 -                                          , "=", chart_template_id), ('type_tax_use', 'in', ('sale','all'))], order="sequence, id desc")
 -            purchase_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
 -                                          , "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all'))], order="sequence, id desc")
 -
 -            res['value']["sale_tax"] = sale_tax_ids and sale_tax_ids[0] or False
 -            res['value']["purchase_tax"] = purchase_tax_ids and purchase_tax_ids[0] or False
 +            data = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
 +            complete_tax = data.set_tax_complete
 +            if complete_tax:
 +            # default tax is given by the lowesst sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account
 +                sale_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id"
 +                                              , "=", chart_template_id), ('type_tax_use', 'in', ('sale','all')), ('installable', '=', True)], order="sequence, id desc")
 +                purchase_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id"
 +                                              , "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all')), ('installable', '=', True)], order="sequence, id desc")
 +                res['value'].update({'sale_tax': sale_tax_ids and sale_tax_ids[0] or False, 'purchase_tax': purchase_tax_ids and purchase_tax_ids[0] or False})
 +            res['value'].update({'complete_tax': complete_tax, 'code_digits': data.code_digits})
          return res
  
 -    def _get_purchase_tax(self, cr, uid, context=None):
 -        ids = self.pool.get('account.chart.template').search(cr, uid, [], context=context)
 -        if ids:
 -            chart_template_id = ids[0]
 -            purchase_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
 -                                          , "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all'))], order="sequence")
 -            return purchase_tax_ids and purchase_tax_ids[0] or False
 -        return False
  
 -    def _get_sale_tax(self, cr, uid, context=None):
 -        ids = self.pool.get('account.chart.template').search(cr, uid, [], context=context)
 -        if ids:
 -            chart_template_id = ids[0]
 -            sale_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
 -                                          , "=", chart_template_id), ('type_tax_use', 'in', ('sale','all'))], order="sequence")
 -            return sale_tax_ids and sale_tax_ids[0] or False
 -        return False
 +    def default_get(self, cr, uid, fields, context=None):
 +        res = super(wizard_multi_charts_accounts, self).default_get(cr, uid, fields, context=context) 
 +        tax_templ_obj = self.pool.get('account.tax.template')
  
 -    def _get_chart(self, cr, uid, context=None):
 -        ids = self.pool.get('account.chart.template').search(cr, uid, [], context=context)
 -        if ids:
 -            return ids[0]
 -        return False
 +        if 'bank_accounts_id' in fields:
 +            res.update({'bank_accounts_id': [{'acc_name': _('Current'), 'account_type': 'bank'},
 +                    {'acc_name': _('Deposit'), 'account_type': 'bank'},
 +                    {'acc_name': _('Cash'), 'account_type': 'cash'}]})
 +        if 'company_id' in fields:
 +            res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})
 +        if 'seq_journal' in fields:
 +            res.update({'seq_journal': True})
  
 -    def _get_default_accounts(self, cr, uid, context=None):
 -        return [
 -            {'acc_name': _('Cash'),'account_type':'cash'}
 -        ]
 +        ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context)
 +        if ids:
 +            if 'chart_template_id' in fields:
 +                res.update({'chart_template_id': ids[0]})
 +            if 'sale_tax' in fields:
 +                sale_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id"
 +                                              , "=", ids[0]), ('type_tax_use', 'in', ('sale','all')), ('installable', '=', True)], order="sequence")
 +                res.update({'sale_tax': sale_tax_ids and sale_tax_ids[0] or False})
 +            if 'purchase_tax' in fields:
 +                purchase_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id"
 +                                          , "=", ids[0]), ('type_tax_use', 'in', ('purchase','all')), ('installable', '=', True)], order="sequence")
 +                res.update({'purchase_tax': purchase_tax_ids and purchase_tax_ids[0] or False})
  
 -    _defaults = {
 -        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, [uid], c)[0].company_id.id,
 -        'chart_template_id': _get_chart,
 -        'bank_accounts_id': _get_default_accounts,
 -        'sale_tax': _get_sale_tax,
 -        'purchase_tax': _get_purchase_tax,
 -        'code_digits': 6,
 -        'seq_journal': True
 -    }
 +        return res
  
      def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
          res = super(wizard_multi_charts_accounts, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
          cmp_select = []
 -        company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)
 +        acc_template_obj = self.pool.get('account.chart.template')
 +        company_obj = self.pool.get('res.company')
 +        
 +        template_ids = acc_template_obj.search(cr, uid, [('visible', '=', True)], context=context)
 +        company_ids = company_obj.search(cr, uid, [], context=context)
          #display in the widget selection of companies, only the companies that haven't been configured yet (but don't care about the demo chart of accounts)
          cr.execute("SELECT company_id FROM account_account WHERE active = 't' AND account_account.parent_id IS NULL AND name != %s", ("Chart For Automated Tests",))
          configured_cmp = [r[0] for r in cr.fetchall()]
                  res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
                  res['fields'][field]['selection'] = [('', '')]
                  if unconfigured_cmp:
 -                    cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
 +                    cmp_select = [(line.id, line.name) for line in company_obj.browse(cr, uid, unconfigured_cmp)]
                      res['fields'][field]['selection'] = cmp_select
 +            if field == 'chart_template_id':
 +                res['fields'][field]['selection'] = [('', '')]
 +                if template_ids:
 +                    template_select = [(template.id, template.name) for template in acc_template_obj.browse(cr, uid, template_ids)]
 +                    res['fields'][field]['selection'] = template_select
          return res
  
 -    def execute(self, cr, uid, ids, context=None):
 -        obj_multi = self.browse(cr, uid, ids[0])
 -        obj_acc = self.pool.get('account.account')
 -        obj_acc_tax = self.pool.get('account.tax')
 +    def check_created_journals(self, cr, uid, vals_journal, company_id, context=None):
 +        """
 +        This method used for checking journals already created or not. If not then create new journal.
 +        """
          obj_journal = self.pool.get('account.journal')
 -        obj_acc_template = self.pool.get('account.account.template')
 -        obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
 -        obj_fiscal_position = self.pool.get('account.fiscal.position')
 +        rec_list = obj_journal.search(cr, uid, [('name','=', vals_journal['name']),('company_id', '=', company_id)], context=context)
 +        if not rec_list:
 +            obj_journal.create(cr, uid, vals_journal, context=context)
 +        return True
 +
 +    def generate_journals(self, cr, uid, chart_template_id, acc_template_ref, company_id, code_digits, context=None):
 +        """
 +        This method used for creating journals.
 +        @param cr: A database cursor.
 +        @param uid: ID of the user currently logged in.
 +        @param chart_temp_id: Chart Template Id.
 +        @param acc_template_ref: Account templates reference.
 +        @param company_id: company_id selected from wizard.multi.charts.accounts.
 +        """
 +        
          obj_data = self.pool.get('ir.model.data')
          analytic_journal_obj = self.pool.get('account.analytic.journal')
 -        obj_tax_code = self.pool.get('account.tax.code')
 -        obj_tax_code_template = self.pool.get('account.tax.code.template')
 -        ir_values_obj = self.pool.get('ir.values')
 -        # Creating Account
 -        obj_acc_root = obj_multi.chart_template_id.account_root_id
 -        tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id
 -        company_id = obj_multi.company_id.id
 -
 -        #new code
 -        acc_template_ref = {}
 -        tax_template_ref = {}
 -        tax_code_template_ref = {}
 -        todo_dict = {}
 -
 -        #create all the tax code
 -        children_tax_code_template = obj_tax_code_template.search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
 -        children_tax_code_template.sort()
 -        for tax_code_template in obj_tax_code_template.browse(cr, uid, children_tax_code_template, context=context):
 -            vals = {
 -                'name': (tax_code_root_id == tax_code_template.id) and obj_multi.company_id.name or tax_code_template.name,
 -                'code': tax_code_template.code,
 -                'info': tax_code_template.info,
 -                'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False,
 -                'company_id': company_id,
 -                'sign': tax_code_template.sign,
 -            }
 -            new_tax_code = obj_tax_code.create(cr, uid, vals)
 -            #recording the new tax code to do the mapping
 -            tax_code_template_ref[tax_code_template.id] = new_tax_code
 -
 -        #create all the tax
 -        tax_template_to_tax = {}
 -        for tax in obj_multi.chart_template_id.tax_template_ids:
 -            #create it
 -            vals_tax = {
 -                'name':tax.name,
 -                'sequence': tax.sequence,
 -                'amount':tax.amount,
 -                'type':tax.type,
 -                'applicable_type': tax.applicable_type,
 -                'domain':tax.domain,
 -                'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False,
 -                'child_depend': tax.child_depend,
 -                'python_compute': tax.python_compute,
 -                'python_compute_inv': tax.python_compute_inv,
 -                'python_applicable': tax.python_applicable,
 -                'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False,
 -                'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False,
 -                'base_sign': tax.base_sign,
 -                'tax_sign': tax.tax_sign,
 -                'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False,
 -                'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False,
 -                'ref_base_sign': tax.ref_base_sign,
 -                'ref_tax_sign': tax.ref_tax_sign,
 -                'include_base_amount': tax.include_base_amount,
 -                'description':tax.description,
 -                'company_id': company_id,
 -                'type_tax_use': tax.type_tax_use,
 -                'price_include': tax.price_include
 -            }
 -            new_tax = obj_acc_tax.create(cr, uid, vals_tax)
 -            tax_template_to_tax[tax.id] = new_tax
 -            #as the accounts have not been created yet, we have to wait before filling these fields
 -            todo_dict[new_tax] = {
 -                'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
 -                'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False,
 -            }
 -            tax_template_ref[tax.id] = new_tax
 -        #deactivate the parent_store functionnality on account_account for rapidity purpose
 -        ctx = context and context.copy() or {}
 -        ctx['defer_parent_store_computation'] = True
 -
 -        children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id]),('nocreate','!=',True)])
 -        children_acc_template.sort()
 -        for account_template in obj_acc_template.browse(cr, uid, children_acc_template, context=context):
 -            tax_ids = []
 -            for tax in account_template.tax_ids:
 -                tax_ids.append(tax_template_ref[tax.id])
 -            #create the account_account
 -
 -            dig = obj_multi.code_digits
 -            code_main = account_template.code and len(account_template.code) or 0
 -            code_acc = account_template.code or ''
 -            if code_main>0 and code_main<=dig and account_template.type != 'view':
 -                code_acc=str(code_acc) + (str('0'*(dig-code_main)))
 -            vals={
 -                'name': (obj_acc_root.id == account_template.id) and obj_multi.company_id.name or account_template.name,
 -                'currency_id': account_template.currency_id and account_template.currency_id.id or False,
 -                'code': code_acc,
 -                'type': account_template.type,
 -                'user_type': account_template.user_type and account_template.user_type.id or False,
 -                'reconcile': account_template.reconcile,
 -                'shortcut': account_template.shortcut,
 -                'note': account_template.note,
 -                'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False,
 -                'tax_ids': [(6,0,tax_ids)],
 -                'company_id': company_id,
 -            }
 -            new_account = obj_acc.create(cr, uid, vals, context=ctx)
 -            acc_template_ref[account_template.id] = new_account
 -
 -
 -        #reactivate the parent_store functionnality on account_account
 -        obj_acc._parent_store_compute(cr)
 -
 -        for key,value in todo_dict.items():
 -            if value['account_collected_id'] or value['account_paid_id']:
 -                obj_acc_tax.write(cr, uid, [key], {
 -                    'account_collected_id': acc_template_ref.get(value['account_collected_id'], False),
 -                    'account_paid_id': acc_template_ref.get(value['account_paid_id'], False),
 -                })
 +        obj_journal = self.pool.get('account.journal')
 +        obj_acc = self.pool.get('account.account')
 +        template = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
  
 -        # Creating Journals
 -        data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
 -        data = obj_data.browse(cr, uid, data_id[0], context=context)
 -        view_id = data.res_id
 +        data = obj_data.get_object_reference(cr, uid, 'account', 'account_sp_journal_view') 
 +        view_id = data and data[1] or False
  
 +        income_acc_id = acc_template_ref.get(template.property_account_income_categ.id)
 +        expense_acc_id = acc_template_ref.get(template.property_account_expense_categ.id)
 +        credit_acc_id = acc_template_ref.get(template.property_account_income_opening.id)
 +        debit_acc_id = acc_template_ref.get(template.property_account_expense_opening.id)
 +                
          #Sales Journal
 -        analytical_sale_ids = analytic_journal_obj.search(cr,uid,[('type','=','sale')])
 +        analytical_sale_ids = analytic_journal_obj.search(cr, uid, [('type','=','sale')], context=context)
          analytical_journal_sale = analytical_sale_ids and analytical_sale_ids[0] or False
 -
          vals_journal = {
              'name': _('Sales Journal'),
              'type': 'sale',
              'analytic_journal_id': analytical_journal_sale,
          }
  
 -        if obj_multi.chart_template_id.property_account_receivable:
 -            vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
 -            vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
 -
 -        obj_journal.create(cr,uid,vals_journal)
 +        if template.property_account_receivable:
 +            vals_journal.update({
 +                            'default_credit_account_id': income_acc_id,
 +                            'default_debit_account_id': income_acc_id
 +                               })
 +        self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
          # Purchase Journal
 -        analytical_purchase_ids = analytic_journal_obj.search(cr,uid,[('type','=','purchase')])
 +        analytical_purchase_ids = analytic_journal_obj.search(cr,uid,[('type','=','purchase')], context=context)
          analytical_journal_purchase = analytical_purchase_ids and analytical_purchase_ids[0] or False
  
          vals_journal = {
              'type': 'purchase',
              'code': _('EXJ'),
              'view_id': view_id,
 -            'company_id':  company_id,
 +            'company_id': company_id,
              'analytic_journal_id': analytical_journal_purchase,
          }
  
 -        if obj_multi.chart_template_id.property_account_payable:
 -            vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
 -            vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
 -        obj_journal.create(cr,uid,vals_journal)
 +        if template.property_account_payable:
 +            vals_journal.update({
 +                            'default_credit_account_id': expense_acc_id,
 +                            'default_debit_account_id': expense_acc_id
 +                               })
 +        self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
          # Creating Journals Sales Refund and Purchase Refund
 -        data_id = obj_data.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_refund_journal_view')], context=context)
 -        data = obj_data.browse(cr, uid, data_id[0], context=context)
 -        view_id = data.res_id
 +        data = obj_data.get_object_reference(cr, uid, 'account', 'account_sp_refund_journal_view') 
 +        view_id = data and data[1] or False
  
          #Sales Refund Journal
          vals_journal = {
              'analytic_journal_id': analytical_journal_sale,
              'company_id': company_id
          }
 -
 -        if obj_multi.chart_template_id.property_account_receivable:
 -            vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
 -            vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
 -
 -        obj_journal.create(cr, uid, vals_journal, context=context)
 +        if template.property_account_receivable:
 +            vals_journal.update({
 +                            'default_credit_account_id': income_acc_id,
 +                            'default_debit_account_id': income_acc_id
 +                               })
 +        self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
          # Purchase Refund Journal
          vals_journal = {
              'analytic_journal_id': analytical_journal_purchase,
              'company_id': company_id
          }
 -
 -        if obj_multi.chart_template_id.property_account_payable:
 -            vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
 -            vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
 -
 -        obj_journal.create(cr, uid, vals_journal, context=context)
 +        if template.property_account_payable:
 +            vals_journal.update({
 +                            'default_credit_account_id': expense_acc_id,
 +                            'default_debit_account_id': expense_acc_id
 +                               })
 +        self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
          # Miscellaneous Journal
 -        data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_view')])
 -        data = obj_data.browse(cr, uid, data_id[0], context=context)
 -        view_id = data.res_id
 +        data = obj_data.get_object_reference(cr, uid, 'account', 'account_journal_view') 
 +        view_id = data and data[1] or False
  
          analytical_miscellaneous_ids = analytic_journal_obj.search(cr, uid, [('type', '=', 'situation')], context=context)
 -        analytical_journal_miscellaneous = analytical_miscellaneous_ids and analytical_miscellaneous_ids[0] or False
  
          vals_journal = {
              'name': _('Miscellaneous Journal'),
              'type': 'general',
              'code': _('MISC'),
              'view_id': view_id,
 -            'analytic_journal_id': analytical_journal_miscellaneous,
 +            'analytic_journal_id': analytical_miscellaneous_ids and analytical_miscellaneous_ids[0] or False,
              'company_id': company_id
          }
 -
 -        obj_journal.create(cr, uid, vals_journal, context=context)
 +        self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
          # Opening Entries Journal
 -        if obj_multi.chart_template_id.property_account_income_opening and obj_multi.chart_template_id.property_account_expense_opening:
 +        if template.property_account_income_opening and template.property_account_expense_opening:
              vals_journal = {
                  'name': _('Opening Entries Journal'),
                  'type': 'situation',
                  'view_id': view_id,
                  'company_id': company_id,
                  'centralisation': True,
 -                'default_credit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_income_opening.id],
 -                'default_debit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_expense_opening.id]
 +                'default_credit_account_id': credit_acc_id,
 +                'default_debit_account_id': debit_acc_id
                  }
 -            obj_journal.create(cr, uid, vals_journal, context=context)
 +            self.check_created_journals(cr, uid, vals_journal, company_id, context=context)
  
 -        # Bank Journals
 -        data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')])
 -        data = obj_data.browse(cr, uid, data_id[0], context=context)
 -        view_id_cash = data.res_id
 +        data = obj_data.get_object_reference(cr, uid, 'account', 'account_journal_bank_view_multi') 
 +        view_id_cur = data and data[1] or False
  
 -        data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view_multi')])
 -        data = obj_data.browse(cr, uid, data_id[0], context=context)
 -        view_id_cur = data.res_id
 +        data = obj_data.get_object_reference(cr, uid, 'account', 'account_journal_bank_view') 
 +        view_id_cash = data and data[1] or False
 +            
 +        return True
 +
 +    def generate_properties(self, cr, uid, chart_template_id, acc_template_ref, company_id, context=None):
 +        """
 +        This method used for creating properties.
 +        @param cr: A database cursor.
 +        @param uid: ID of the user currently logged in.
 +        @param chart_temp_id: Chart Template Id.
 +        @param acc_template_ref: Account templates reference.
 +        @param company_id: company_id selected from wizard.multi.charts.accounts.
 +        """
 +        
 +        property_obj = self.pool.get('ir.property')
 +        field_obj = self.pool.get('ir.model.fields')
 +        todo_list = [
 +            ('property_account_receivable','res.partner','account.account'),
 +            ('property_account_payable','res.partner','account.account'),
 +            ('property_account_expense_categ','product.category','account.account'),
 +            ('property_account_income_categ','product.category','account.account'),
 +            ('property_account_expense','product.template','account.account'),
 +            ('property_account_income','product.template','account.account'),
 +            ('property_reserve_and_surplus_account','res.company','account.account')
 +        ]
 +        template_id = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
 +        for record in todo_list:
 +            rec_list = []
 +            rec_list = property_obj.search(cr, uid, [('name','=', record[0]),('company_id', '=', company_id)], context=context)
 +            account = getattr(template_id, record[0])
 +            field = field_obj.search(cr, uid, [('name', '=', record[0]),('model', '=', record[1]),('relation', '=', record[2])], context=context)
 +            vals = {
 +                'name': record[0],
 +                'company_id': company_id,
 +                'fields_id': field[0],
 +                'value': account and 'account.account,' + str(acc_template_ref[account.id]) or False,
 +            }
 +
 +            if rec_list:
 +                #the property exist: modify it
 +                property_obj.write(cr, uid, rec_list, vals, context=context)
 +            else:
 +                #create the property
 +                property_obj.create(cr, uid, vals, context=context)
 +        
 +        return True
 +
 +    def _install_template(self, cr, uid, template_id, company_id, code_digits=None ,tax_data={}, context=None):
 +        template = self.pool.get('account.chart.template').browse(cr, uid, template_id, context=context)
 +        if template.parent_id:
 +            self._install_template(cr, uid, template.parent_id.id, company_id, code_digits=code_digits, context=context)
 +        return self._load_template(cr, uid, template_id, company_id, code_digits=code_digits, tax_data=tax_data,context=context)
 +
 +    def _load_template(self, cr, uid, template_id, company_id, code_digits=None, tax_data={}, context=None):
 +        template = self.pool.get('account.chart.template').browse(cr, uid, template_id, context=context)
 +        obj_tax_code_template = self.pool.get('account.tax.code.template')
 +        obj_acc_tax = self.pool.get('account.tax')
 +        obj_tax_code = self.pool.get('account.tax.code')
 +        obj_tax_temp = self.pool.get('account.tax.template')
 +        obj_acc_template = self.pool.get('account.account.template')
 +        obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
 +        ir_values_obj = self.pool.get('ir.values')
 +
 +        # create tax templates and real taxes from purchase_tax_rate,sale_tax_rate fields
 +        if not template.set_tax_complete and tax_data:
 +            tax_dict = {'sale': tax_data['sale'], 'purchase': tax_data['purchase']}
 +            for tax_type, value in tax_dict.items():
 +                tax_name = tax_type == 'sale' and 'TAX Received' or 'TAX Paid'
 +                if value > 0.0:
 +                    tax_string = _('TAX %s %s%%') % (tax_type, value)
 +                    new_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': tax_string, 'code': tax_string}, context=context)
 +                    new_paid_tax_code_temp = obj_tax_code_template.create(cr, uid, {'name': _('%s %s%%') % (tax_name, value), 'code': _('%s %s%%') % (tax_name, value)}, context=context)
 +                    sales_tax_temp = obj_tax_temp.create(cr, uid, {
 +                                            'name': tax_string,
 +                                            'description': tax_string,
 +                                            'amount': value/100,
 +                                            'base_code_id': new_tax_code_temp,
 +                                            'tax_code_id': new_paid_tax_code_temp,
 +                                            'ref_base_code_id': new_tax_code_temp,
 +                                            'ref_tax_code_id': new_paid_tax_code_temp,
 +                                            'type_tax_use': tax_type,
 +                                            'installable': True,
 +                                            'type': 'percent',
 +                                            'sequence': 0,
 +                                            'chart_template_id': template_id or False,
 +                                }, context=context)
 +
 +
 +        # create all the tax code.
 +        tax_code_template_ref = {}
 +        tax_code_root_id = template.tax_code_root_id.id
 +        children_tax_code_template = obj_tax_code_template.search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
 +        company_name = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
 +        for tax_code_template in obj_tax_code_template.browse(cr, uid, children_tax_code_template, context=context):
 +            vals = {
 +                'name': (tax_code_root_id == tax_code_template.id) and company_name.name or tax_code_template.name,
 +                'code': tax_code_template.code,
 +                'info': tax_code_template.info,
 +                'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False,
 +                'company_id': company_id,
 +                'sign': tax_code_template.sign,
 +            }
 +            rec_list = obj_tax_code.search(cr, uid, [('name', '=', vals['name']),('company_id', '=', vals['company_id'])], context=context)
 +            if not rec_list:
 +                new_tax_code = obj_tax_code.create(cr, uid, vals)
 +                #recording the new tax code to do the mapping
 +                tax_code_template_ref[tax_code_template.id] = new_tax_code
 +
 +        # Generate taxes from templates.
 +        tax_template_to_tax = {}
 +        tax_templates = [x for x in template.tax_template_ids if x.installable]
 +        taxes_ref = obj_tax_temp.generate_tax(cr, uid, tax_templates, tax_code_template_ref, company_id, context=context)
 +
 +        # Generating Accounts from templates.
 +        acc_template_ref = obj_acc_template.generate_account(cr, uid, template_id, taxes_ref['tax_template_ref'], code_digits, company_id, context=context)
 +
 +        # writing account values on tax after creation of accounts
 +        for key,value in taxes_ref['account_dict'].items():
 +            if value['account_collected_id'] or value['account_paid_id']:
 +                obj_acc_tax.write(cr, uid, [key], {
 +                    'account_collected_id': acc_template_ref.get(value['account_collected_id'], False),
 +                    'account_paid_id': acc_template_ref.get(value['account_paid_id'], False),
 +                })
 +        
 +        # Create Jourals
 +        self.generate_journals(cr, uid, template_id, acc_template_ref, company_id, code_digits, context)
 +
 +        # generate properties function
 +        self.generate_properties(cr, uid, template_id, acc_template_ref, company_id, context=context)
 +
 +        # Generate Fiscal Position , Fiscal Position Accounts and Fiscal Position Taxes from templates
 +        obj_fiscal_position_template.generate_fiscal_position(cr, uid, template_id, taxes_ref['tax_template_ref'], acc_template_ref, company_id, context=context)
 +
 +        # write values of default taxes for product
 +        if tax_data:
 +            if tax_data['sale_tax'] and taxes_ref['taxes_id']:
 +                ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=company_id,
 +                                models =[('product.product',False)], value=[taxes_ref['taxes_id'][tax_data['sale_tax']]])
 +            if tax_data['purchase_tax'] and taxes_ref['taxes_id']:
 +                ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=company_id,
 +                                models =[('product.product',False)], value=[taxes_ref['taxes_id'][tax_data['purchase_tax']]])
 +        return acc_template_ref
 +
 +    def execute(self, cr, uid, ids, context=None):
 +        obj_acc = self.pool.get('account.account')
 +        obj_journal = self.pool.get('account.journal')
 +        
 +        obj_multi = self.browse(cr, uid, ids[0])
 +        company_id = obj_multi.company_id.id
 +
 +        code_digits = obj_multi.code_digits
          ref_acc_bank = obj_multi.chart_template_id.bank_account_view_id
  
 +        journal_data = []
 +        tax_data = {
 +                    'sale': obj_multi.sale_tax_rate, 
 +                    'purchase': obj_multi.purchase_tax_rate, 
 +                    'sale_tax': obj_multi.complete_tax and obj_multi.sale_tax.id or False, 
 +                    'purchase_tax': obj_multi.complete_tax and obj_multi.purchase_tax.id or False, 
 +                     }
 +
 +        acc_temp_ref = self._install_template(cr, uid, obj_multi.chart_template_id.id, company_id, code_digits=code_digits, tax_data=tax_data, context=context)                         
 +        if obj_multi.bank_accounts_id:
 +            for acc in obj_multi.bank_accounts_id:
 +                journal_data.append({
 +                            'acc_name': acc.acc_name,
 +                            'account_type': acc.account_type,
 +                            'currency_id': acc.currency_id.id,
 +                            })
 +        
 +        #Create Bank journals
          current_num = 1
          valid = True
 -        for line in obj_multi.bank_accounts_id:
 +        for line in journal_data:
              #create the account_account for this bank journal
              if not ref_acc_bank.code:
                  raise osv.except_osv(_('Configuration Error !'), _('The bank account defined on the selected chart of accounts hasn\'t a code.'))
              while True:
 -                new_code = str(ref_acc_bank.code.ljust(dig-len(str(current_num)), '0')) + str(current_num)
 +                new_code = str(ref_acc_bank.code.ljust(code_digits-len(str(current_num)), '0')) + str(current_num)
                  ids = obj_acc.search(cr, uid, [('code', '=', new_code), ('company_id', '=', company_id)])
                  if not ids:
                      break
                  else:
                      current_num += 1
 +            #TODO: create proper user_type for account creation.
 +            user_type = self.pool.get('account.account.type').search(cr, uid, [('name', '=', line['account_type'])], context=context)
              vals = {
 -                'name': tmp,
 -                'currency_id': line.currency_id and line.currency_id.id or False,
 +                'name': line['acc_name'],
 +                'currency_id': line['currency_id'],
                  'code': new_code,
                  'type': 'liquidity',
 -                'user_type': account_template.user_type and account_template.user_type.id or False,
 +                'user_type': 1,
                  'reconcile': True,
                  'parent_id': acc_template_ref[ref_acc_bank.id] or False,
                  'company_id': company_id,
              vals_journal = {
                  'name': vals['name'],
                  'code': _('BNK') + str(current_num),
 -                'type': line.account_type == 'cash' and 'cash' or 'bank',
 +                'type': line['account_type'] == 'cash' and 'cash' or 'bank',
                  'company_id': company_id,
                  'analytic_journal_id': False,
                  'currency_id': False,
              }
 -            if line.currency_id:
 +            if line['currency_id']:
                  vals_journal['view_id'] = view_id_cur
 -                vals_journal['currency'] = line.currency_id.id
 +                vals_journal['currency'] = line['currency_id']
              else:
                  vals_journal['view_id'] = view_id_cash
              vals_journal['default_credit_account_id'] = acc_cash_id
              obj_journal.create(cr, uid, vals_journal)
              current_num += 1
              valid = True
 +        return True
  
 -        #create the properties
 -        property_obj = self.pool.get('ir.property')
 -        fields_obj = self.pool.get('ir.model.fields')
 -
 -        todo_list = [
 -            ('property_account_receivable','res.partner','account.account'),
 -            ('property_account_payable','res.partner','account.account'),
 -            ('property_account_expense_categ','product.category','account.account'),
 -            ('property_account_income_categ','product.category','account.account'),
 -            ('property_account_expense','product.template','account.account'),
 -            ('property_account_income','product.template','account.account'),
 -            ('property_reserve_and_surplus_account','res.company','account.account')
 -        ]
 -        for record in todo_list:
 -            r = []
 -            r = property_obj.search(cr, uid, [('name','=', record[0] ),('company_id','=',company_id)])
 -            account = getattr(obj_multi.chart_template_id, record[0])
 -            field = fields_obj.search(cr, uid, [('name','=',record[0]),('model','=',record[1]),('relation','=',record[2])])
 -            vals = {
 -                'name': record[0],
 -                'company_id': company_id,
 -                'fields_id': field[0],
 -                'value': account and 'account.account,' + str(acc_template_ref[account.id]) or False,
 -            }
 -
 -            if r:
 -                #the property exist: modify it
 -                property_obj.write(cr, uid, r, vals)
 -            else:
 -                #create the property
 -                property_obj.create(cr, uid, vals)
 -
 -        fp_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.chart_template_id.id)])
 -
 -        if fp_ids:
 -            obj_tax_fp = self.pool.get('account.fiscal.position.tax')
 -            obj_ac_fp = self.pool.get('account.fiscal.position.account')
 -
 -            for position in obj_fiscal_position_template.browse(cr, uid, fp_ids, context=context):
 -
 -                vals_fp = {
 -                    'company_id': company_id,
 -                    'name': position.name,
 -                }
 -                new_fp = obj_fiscal_position.create(cr, uid, vals_fp)
 -
 -                for tax in position.tax_ids:
 -                    vals_tax = {
 -                        'tax_src_id': tax_template_ref[tax.tax_src_id.id],
 -                        'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
 -                        'position_id': new_fp,
 -                    }
 -                    obj_tax_fp.create(cr, uid, vals_tax)
 -
 -                for acc in position.account_ids:
 -                    vals_acc = {
 -                        'account_src_id': acc_template_ref[acc.account_src_id.id],
 -                        'account_dest_id': acc_template_ref[acc.account_dest_id.id],
 -                        'position_id': new_fp,
 -                    }
 -                    obj_ac_fp.create(cr, uid, vals_acc)
 -
 -        if obj_multi.sale_tax:
 -            ir_values_obj.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id,
 -                            models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]])
 -        if obj_multi.purchase_tax:
 -            ir_values_obj.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id,
 -                            models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]])
  
  wizard_multi_charts_accounts()