diff --git a/addons/account/account.py b/addons/account/account.py index b47b4c14bd9..94086e86742 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -33,7 +33,7 @@ from osv import fields, osv from tools.misc import currency from tools.translate import _ - +import pooler import mx.DateTime from mx.DateTime import RelativeDateTime, now, DateTime, localtime @@ -1476,18 +1476,29 @@ class account_subscription_line(osv.osv): account_subscription_line() -class account_config_fiscalyear(osv.osv_memory): - _name = 'account.config.fiscalyear' +class account_config_wizard(osv.osv_memory): + _name = 'account.config.wizard' + def _get_charts(self, cr, uid, context): + module_obj=self.pool.get('ir.module.module') + ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'), ('state', '<>', 'installed')]) + res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)] + res.append((-1, 'None')) + res.sort(lambda x,y: cmp(x[1],y[1])) + return res _columns = { - 'name':fields.char('Name', required=True,size=64), - 'code':fields.char('Code', required=True,size=64), + 'name':fields.char('Name', required=True, size=64, help="Name of the fiscal year as displayed on screens."), + 'code':fields.char('Code', required=True, size=64, help="Name of the fiscal year as displayed in reports."), 'date1': fields.date('Starting Date', required=True), 'date2': fields.date('Ending Date', required=True), + 'period':fields.selection([('month','Month'),('3months','3 Months')], 'Periods', required=True), + 'charts' : fields.selection(_get_charts, 'Charts of Account',required=True) } _defaults = { 'code': lambda *a: time.strftime('%Y'), + 'name': lambda *a: time.strftime('%Y'), 'date1': lambda *a: time.strftime('%Y-01-01'), 'date2': lambda *a: time.strftime('%Y-12-31'), + 'period':lambda *a:'month' } def action_cancel(self,cr,uid,ids,conect=None): return { @@ -1497,21 +1508,48 @@ class account_config_fiscalyear(osv.osv_memory): 'type': 'ir.actions.act_window', 'target':'new', } + + def install_account_chart(self, cr, uid,ids, context=None): + for res in self.read(cr,uid,ids): + id = res['charts'] + def install(id): + mod_obj = self.pool.get('ir.module.module') + mod_obj.write(cr , uid, [id] ,{'state' : 'to install'}) + mod_obj.download(cr, uid, [id], context=context) + cr.commit() + cr.execute("select m.id as id from ir_module_module_dependency d inner join ir_module_module m on (m.name=d.name) where d.module_id=%d and m.state='uninstalled'",(id,)) + ret = cr.fetchall() + if len(ret): + for r in ret: + install(r[0]) + else: + mod_obj.write(cr , uid, [id] ,{'state' : 'to install'}) + mod_obj.download(cr, uid, [id], context=context) + cr.commit() + if id>0: + install(id) + cr.commit() + db, pool = pooler.restart_pool(cr.dbname, update_module=True) + def action_create(self, cr, uid,ids, context=None): - res=self.read(cr,uid,ids)[0] - if 'date1' in res and 'date2' in res: - res_obj = self.pool.get('account.fiscalyear') - start_date=res['date1'] - end_date=res['date2'] - name=res['name']#DateTime.strptime(start_date, '%Y-%m-%d').strftime('%m.%Y') + '-' + DateTime.strptime(end_date, '%Y-%m-%d').strftime('%m.%Y') - vals={ - 'name':name, - 'code':name, - 'date_start':start_date, - 'date_stop':end_date, - } - new_id=res_obj.create(cr, uid, vals, context=context) - res_obj.create_period(cr,uid,[new_id]) + for res in self.read(cr,uid,ids): + if 'date1' in res and 'date2' in res: + res_obj = self.pool.get('account.fiscalyear') + start_date=res['date1'] + end_date=res['date2'] + name=res['name']#DateTime.strptime(start_date, '%Y-%m-%d').strftime('%m.%Y') + '-' + DateTime.strptime(end_date, '%Y-%m-%d').strftime('%m.%Y') + vals={ + 'name':name, + 'code':name, + 'date_start':start_date, + 'date_stop':end_date, + } + new_id=res_obj.create(cr, uid, vals, context=context) + if res['period']=='month': + res_obj.create_period(cr,uid,[new_id]) + elif res['period']=='3months': + res_obj.create_period3(cr,uid,[new_id]) + self.install_account_chart(cr,uid,ids) return { 'view_type': 'form', "view_mode": 'form', @@ -1520,7 +1558,10 @@ class account_config_fiscalyear(osv.osv_memory): 'target':'new', } -account_config_fiscalyear() + + +account_config_wizard() + # --------------------------------------------------------------- # Account Templates : Account, Tax, Tax Code and chart. + Wizard @@ -1761,6 +1802,11 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'code_digits':fields.integer('# of Digits',required=True,help="No. of Digits to use for account code"), } + _defaults = { + 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.id, + 'code_digits': lambda *a:6, + } + def action_create(self, cr, uid, ids, context=None): obj_multi = self.browse(cr,uid,ids[0]) obj_acc = self.pool.get('account.account') @@ -1886,9 +1932,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): vals_journal['sequence_id']=seq_id #Sales Journal - vals_journal['name'] = 'Sales Journal '+ str(seq_code) + vals_journal['name'] = _('Sales Journal') vals_journal['type'] = 'sale' - vals_journal['code'] = 'SAJ' + str(seq_code) + vals_journal['code'] = _('SAJ') 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_receivable.id] @@ -1897,9 +1943,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal.create(cr,uid,vals_journal) # Purchase Journal - vals_journal['name']='Purchase Journal '+ str(seq_code) + vals_journal['name']=_('Purchase Journal') vals_journal['type']='purchase' - vals_journal['code']='EXJ' + str(seq_code) + vals_journal['code']=_('EXJ') 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_payable.id] @@ -1912,19 +1958,15 @@ class wizard_multi_charts_accounts(osv.osv_memory): view_id_cur = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Multi-Currency Cash Journal View')])[0] ref_acc_bank = obj_multi.chart_template_id.bank_account_view_id - current_num = 0 + current_num = 1 for line in obj_multi.bank_accounts_id: #create the account_account for this bank journal tmp = self.pool.get('res.partner.bank').name_get(cr, uid, [line.acc_no.id])[0][1] dig = obj_multi.code_digits - code_main = len(ref_acc_bank.code+str(current_num)) - code_acc = ref_acc_bank.code+str(current_num) - if code_main<=dig: - code_acc=str(code_acc) + (str('0'*(dig-code_main))) vals={ 'name': line.acc_no.bank and line.acc_no.bank.name+' '+tmp or tmp, 'currency_id': line.currency_id and line.currency_id.id or False, - 'code': ref_acc_bank.code+str(current_num), + 'code': str(int(ref_acc_bank.code.ljust(dig,'0')) + current_num), 'type': 'other', 'user_type': account_template.user_type and account_template.user_type.id or False, 'reconcile': True, @@ -1934,8 +1976,8 @@ class wizard_multi_charts_accounts(osv.osv_memory): acc_cash_id = obj_acc.create(cr,uid,vals) #create the bank journal - vals_journal['name']='Bank Journal '+ str(current_num) - vals_journal['code']='BNK' + str(current_num) + vals_journal['name']= vals['name'] + vals_journal['code']= _('BNK') + str(current_num) vals_journal['sequence_id'] = seq_id vals_journal['type'] = 'cash' if line.currency_id: diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 68559fd48b1..c55d49a418f 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -89,6 +89,14 @@ class account_analytic_line(osv.osv): }} return {} + def view_header_get(self, cr, user, view_id, view_type, context): + if context.get('account_id', False): + cr.execute('select name from account_analytic_account where id=%d', (context['account_id'],)) + res = cr.fetchone() + res = _('Entries: ')+ (res[0] or '') + return res + return False + account_analytic_line() diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 638ba88f44a..62cb55b13e4 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1323,45 +1323,52 @@ - - Configure Fiscal Year - account.config.fiscalyear + + Account Configure wizard + account.config.wizard form -
- + + + + +