diff --git a/addons/account/account.py b/addons/account/account.py index 0229297c2de..6ae6968f364 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -320,7 +320,8 @@ class account_account(osv.osv): 'company_id': _default_company, 'active': lambda *a: True, 'check_history': lambda *a: True, - 'currency_mode': lambda *a: 'current' + 'currency_mode': lambda *a: 'current', + 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.account', c), } def _check_recursion(self, cr, uid, ids): @@ -641,7 +642,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): @@ -781,7 +782,7 @@ class account_move(osv.osv): ('journal_pur_voucher','Journal Purchase'), ('journal_voucher','Journal Voucher'), ],'Type', readonly=True, select=True, states={'draft':[('readonly',False)]}), - 'company_id': fields.many2one('res.company', 'Company', required=True), + 'company_id': fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company'), } _defaults = { 'name': lambda *a: '/', @@ -919,7 +920,10 @@ class account_move(osv.osv): amount+= (line.debit - line.credit) return amount - def _centralise(self, cr, uid, move, mode): + def _centralise(self, cr, uid, move, mode, context=None): + if context is None: + context = {} + if mode=='credit': account_id = move.journal_id.default_debit_account_id.id mode2 = 'debit' @@ -942,8 +946,9 @@ class account_move(osv.osv): if res: line_id = res[0] else: + context.update({'journal_id': move.journal_id.id, 'period_id': move.period_id.id}) line_id = self.pool.get('account.move.line').create(cr, uid, { - 'name': 'Centralisation '+mode, + 'name': _t(cr, None, 'selection', context.get('lang'), source=(mode.capitalize()+' Centralisation')) or (mode.capitalize()+' Centralisation'), 'centralisation': mode, 'account_id': account_id, 'move_id': move.id, @@ -952,7 +957,7 @@ class account_move(osv.osv): 'date': move.period_id.date_stop, 'debit': 0.0, 'credit': 0.0, - }, {'journal_id': move.journal_id.id, 'period_id': move.period_id.id}) + }, context) # find the first line of this move with the other mode # so that we can exclude it from our calculation @@ -1034,8 +1039,8 @@ class account_move(osv.osv): # continue if journal.centralisation: - self._centralise(cr, uid, move, 'debit') - self._centralise(cr, uid, move, 'credit') + self._centralise(cr, uid, move, 'debit', context=context) + self._centralise(cr, uid, move, 'credit', context=context) self.pool.get('account.move.line').write(cr, uid, line_draft_ids, { 'state': 'valid' }, context, check=False) @@ -1049,11 +1054,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 +1819,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 +1857,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 +2213,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_bank_statement.py b/addons/account/account_bank_statement.py index 7e289f695ea..393d424a585 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -144,6 +144,7 @@ class account_bank_statement(osv.osv): } def button_confirm(self, cr, uid, ids, context=None): + context = context or {} done = [] res_currency_obj = self.pool.get('res.currency') res_users_obj = self.pool.get('res.users') @@ -176,6 +177,8 @@ class account_bank_statement(osv.osv): # In line we get reconcile_id on bank.ste.rec. # in bank stat.rec we get line_new_ids on bank.stat.rec.line for move in st.line_ids: + context.update({'date':move.date}) + move_id = account_move_obj.create(cr, uid, { 'journal_id': st.journal_id.id, 'period_id': st.period_id.id, @@ -578,7 +581,7 @@ class account_bank_statement_line(osv.osv): 'account_id': fields.many2one('account.account','Account', required=True), 'statement_id': fields.many2one('account.bank.statement', 'Statement', - select=True, required=True), + select=True, required=True, ondelete='cascade'), 'reconcile_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile', states={'confirm':[('readonly',True)]}), 'move_ids': fields.many2many('account.move', diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index d728eed9ffc..aff83eaf918 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -52,7 +52,7 @@
- + @@ -63,6 +63,7 @@ + @@ -155,7 +156,7 @@ - + @@ -288,7 +289,7 @@ - + @@ -424,6 +425,20 @@ {'type':'out_refund'} + + + + tree + + + + + + form + + + + diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cc1f1fcd3b0..fcade623b76 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -103,9 +103,10 @@ class account_move_line(osv.osv): total_new=0.00 for i in context['lines']: - total_new +=(i[2]['debit'] or 0.00)- (i[2]['credit'] or 0.00) - for item in i[2]: - data[item]=i[2][item] + if i[2]: + total_new +=(i[2]['debit'] or 0.00)- (i[2]['credit'] or 0.00) + for item in i[2]: + data[item]=i[2][item] if context['journal']: journal_obj=self.pool.get('account.journal').browse(cr,uid,context['journal']) if journal_obj.type == 'purchase': @@ -388,7 +389,7 @@ class account_move_line(osv.osv): 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'), #TODO: remove this 'amount_taxed':fields.float("Taxed Amount",digits=(16,int(tools.config['price_accuracy']))), - 'company_id': fields.related('move_id','company_id',type='many2one',object='res.company',string='Company') + 'company_id': fields.related('account_id','company_id',type='many2one',object='res.company',string='Company') } diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 980912dd936..590a82a3ab1 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -75,7 +75,7 @@ - + @@ -340,7 +340,6 @@ - @@ -351,7 +350,6 @@ - @@ -792,9 +790,9 @@ - - - account.move.line.select + + + Entry Lines account.move.line search @@ -1413,7 +1411,7 @@ - account.move.line + Account Entry Lines account.move.line form tree,form @@ -1479,8 +1477,28 @@ + + Account Add wizard + account.addtmpl.wizard + form + +
+ + + +