diff --git a/addons/account/account.py b/addons/account/account.py index 0229297c2de..02f79a6dfc5 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -641,7 +641,7 @@ class account_period(osv.osv): #CHECKME: shouldn't we check the state of the period? ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)]) if not ids: - raise osv.except_osv(_('Error !'), _('No period defined for this date !\nPlease create a fiscal year.')) + raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create a fiscal year.')%dt) return ids def action_draft(self, cr, uid, ids, *args): @@ -1049,11 +1049,11 @@ class account_move(osv.osv): 'state': 'draft' }, context, check=False) ok = False - if ok: - list_ids = [] - for tmp in move.line_id: - list_ids.append(tmp.id) - self.pool.get('account.move.line').create_analytic_lines(cr, uid, list_ids, context) + if ok: + list_ids = [] + for tmp in move.line_id: + list_ids.append(tmp.id) + self.pool.get('account.move.line').create_analytic_lines(cr, uid, list_ids, context) return ok account_move() @@ -1814,11 +1814,13 @@ class account_account_template(osv.osv): 'parent_id': fields.many2one('account.account.template','Parent Account Template', ondelete='cascade'), '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."), } _defaults = { 'reconcile': lambda *a: False, 'type' : lambda *a :'view', + 'nocreate': lambda *a: False, } def _check_recursion(self, cr, uid, ids): @@ -1850,6 +1852,67 @@ class account_account_template(osv.osv): account_account_template() +class account_add_tmpl_wizard(osv.osv_memory): + """Add one more account from the template. + + With the 'nocreate' option, some accounts may not be created. Use this to add them later.""" + _name = 'account.addtmpl.wizard' + + def _get_def_cparent(self, cr, uid, context): + acc_obj=self.pool.get('account.account') + tmpl_obj=self.pool.get('account.account.template') + #print "Searching for ",context + tids=tmpl_obj.read(cr, uid, [context['tmpl_ids']],['parent_id']) + if not tids or not tids[0]['parent_id']: + return False + ptids = tmpl_obj.read(cr, uid, [tids[0]['parent_id'][0]],['code']) + if not ptids or not ptids[0]['code']: + raise osv.except_osv(_('Error !'), _('Cannot locate parent code for template account!')) + res = acc_obj.search(cr,uid,[('code','=',ptids[0]['code'])]) + if res: + return res[0] + else: + return False + + _columns = { + 'cparent_id':fields.many2one('account.account', 'Parent target', help="Create an account with the selected template under this existing parent.", required=True), + } + _defaults = { + 'cparent_id': _get_def_cparent, + } + + def action_create(self,cr,uid,ids,context=None): + acc_obj=self.pool.get('account.account') + tmpl_obj=self.pool.get('account.account.template') + data= self.read(cr,uid,ids) + company_id = acc_obj.read(cr,uid,[data[0]['cparent_id']],['company_id'])[0]['company_id'][0] + account_template = tmpl_obj.browse(cr,uid,context['tmpl_ids']) + #tax_ids = [] + #for tax in account_template.tax_ids: + # tax_ids.append(tax_template_ref[tax.id]) + vals={ + 'name': 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, + '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': data[0]['cparent_id'], + # 'tax_ids': [(6,0,tax_ids)], todo!! + 'company_id': company_id, + } + # print "Creating:", vals + new_account = acc_obj.create(cr,uid,vals) + return {'type':'state', 'state': 'end' } + + def action_cancel(self,cr,uid,ids,context=None): + return { 'type': 'state', 'state': 'end' } + +account_add_tmpl_wizard() + class account_tax_code_template(osv.osv): _name = 'account.tax.code.template' @@ -2145,7 +2208,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #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])]) + 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): tax_ids = [] diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 5f13160dfd9..3e3266044b4 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -97,9 +97,11 @@ class account_analytic_line(osv.osv): def view_header_get(self, cr, user, view_id, view_type, context): if context.get('account_id', False): + # account_id in context may also be pointing to an account.account.id cr.execute('select name from account_analytic_account where id=%s', (context['account_id'],)) res = cr.fetchone() - res = _('Entries: ')+ (res[0] or '') + if res: + res = _('Entries: ')+ (res[0] or '') return res return False diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index d728eed9ffc..f5beac34601 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -63,6 +63,7 @@ + @@ -288,7 +289,7 @@ - + diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index f472b73f198..1fa6df738c5 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -792,9 +792,9 @@ - - - account.move.line.select + + + Entry Lines account.move.line search @@ -1479,8 +1479,28 @@ + + Account Add wizard + account.addtmpl.wizard + form + +
+ + + +