diff --git a/addons/account/account.py b/addons/account/account.py index a771bed6144..1ced6bd88e8 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1563,65 +1563,64 @@ class account_config_fiscalyear(osv.osv_memory): account_config_fiscalyear() - -class account_config_journal_bank_accounts(osv.osv_memory): - _name='account.config.journal.bank.account' - _columns = { - 'name':fields.char('Journal Name', size=64), - 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), - } - - def action_cancel(self,cr,uid,ids,conect=None): - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - - def action_create(self, cr, uid, ids, context=None): - config_res=self.read(cr,uid,ids)[0] - res_obj = self.pool.get('account.journal') - line_obj=self.pool.get('account.config.journal.bank.account.line') - if 'lines_id' in config_res and config_res['lines_id']: - lines=line_obj.read(cr,uid,config_res['lines_id']) - for res in lines: - sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) - if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): - vals={ - 'name':res['name'], - 'type':'cash', - 'view_id':res['view_id'], - 'default_credit_account_id':res['bank_account_id'], - 'default_debit_account_id':res['bank_account_id'], - 'sequence_id':sequence_ids[0] - } - res_obj.create(cr, uid, vals, context=context) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - -account_config_journal_bank_accounts() - -class account_config_journal_bank_accounts_line(osv.osv_memory): - _name='account.config.journal.bank.account.line' - def _journal_view_get(self, cr, uid, context={}): - journal_obj = self.pool.get('account.journal.view') - ids = journal_obj.search(cr, uid, []) - res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) - return [(r['id'], r['name']) for r in res] - _columns = { - 'name':fields.char('Journal Name', size=64,required=True), - 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), - 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), - 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), - } -account_config_journal_bank_accounts_line() +#class account_config_journal_bank_accounts(osv.osv_memory): +# _name='account.config.journal.bank.account' +# _columns = { +# 'name':fields.char('Journal Name', size=64), +# 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), +# } +# +# def action_cancel(self,cr,uid,ids,conect=None): +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +# def action_create(self, cr, uid, ids, context=None): +# config_res=self.read(cr,uid,ids)[0] +# res_obj = self.pool.get('account.journal') +# line_obj=self.pool.get('account.config.journal.bank.account.line') +# if 'lines_id' in config_res and config_res['lines_id']: +# lines=line_obj.read(cr,uid,config_res['lines_id']) +# for res in lines: +# sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) +# if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): +# vals={ +# 'name':res['name'], +# 'type':'cash', +# 'view_id':res['view_id'], +# 'default_credit_account_id':res['bank_account_id'], +# 'default_debit_account_id':res['bank_account_id'], +# 'sequence_id':sequence_ids[0] +# } +# res_obj.create(cr, uid, vals, context=context) +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +#account_config_journal_bank_accounts() +# +#class account_config_journal_bank_accounts_line(osv.osv_memory): +# _name='account.config.journal.bank.account.line' +# def _journal_view_get(self, cr, uid, context={}): +# journal_obj = self.pool.get('account.journal.view') +# ids = journal_obj.search(cr, uid, []) +# res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) +# return [(r['id'], r['name']) for r in res] +# _columns = { +# 'name':fields.char('Journal Name', size=64,required=True), +# 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), +# 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), +# 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), +# } +#account_config_journal_bank_accounts_line() # ---------------------------------------------- # Account Templates : Account, Tax and charts. @@ -1867,6 +1866,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal = self.pool.get('account.journal') obj_acc_template = self.pool.get('account.account.template') + if obj_multi.code_digits<=5: + raise osv.except_osv(_('User Error'), _('Account code should be of more than 5 digits.')) + # 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 @@ -1889,7 +1891,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): '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_ref[tax_code_template.parent_id.id] or False, + '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, } @@ -1907,7 +1909,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type':tax.type, 'applicable_type': tax.applicable_type, 'domain':tax.domain, - 'parent_id': tax.parent_id and tax_template_ref[tax.parent_id.id] or False, + '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, @@ -1933,7 +1935,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): } tax_template_ref[tax.id] = new_tax - #deactivate the parent_store functionnality on account_account for rapidity purpose self.pool._init = True children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id])]) @@ -1942,17 +1943,22 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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=len(account_template.code) + code_acc=account_template.code + if code_main<=dig: + 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, #'sign': account_template.sign, 'currency_id': account_template.currency_id and account_template.currency_id.id or False, - 'code': account_template.code, + 'code': code_acc[:dig], 'type': account_template.type, 'user_type': account_template.user_type or False, 'reconcile': account_template.reconcile, 'shortcut': account_template.shortcut, 'note': account_template.note, - 'parent_id': account_template.parent_id and acc_template_ref[account_template.parent_id.id] or False, + '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, } @@ -2015,7 +2021,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #'sign': ref_acc_bank.sign, 'currency_id': line.currency_id and line.currency_id.id or False, 'code': ref_acc_bank.code+str(current_num), - 'type': 'cash', + 'type': 'other', 'user_type': account_template.user_type or False, 'reconcile': True, 'parent_id': acc_template_ref[ref_acc_bank.id] or False, diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 2fb7c30d4a5..20aaa5ba7ea 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1463,12 +1463,12 @@ open - +