diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 96412077840..6f3675392e0 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -60,6 +60,7 @@ module named account_voucher. 'wizard/account_period_close_view.xml', 'wizard/account_fiscalyear_close_state.xml', 'wizard/account_chart_view.xml', + 'wizard/account_tax_chart_view.xml', 'wizard/account_move_journal_view.xml', 'wizard/account_move_line_reconcile_select_view.xml', 'wizard/account_open_closed_fiscalyear_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index f0884044fcf..28d6fa70e27 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -835,7 +835,7 @@ class account_period(osv.osv): 'company_id': fields.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True) } _defaults = { - 'state': lambda *a: 'draft', + 'state': 'draft', } _order = "date_start" @@ -883,13 +883,10 @@ class account_period(osv.osv): return ids def action_draft(self, cr, uid, ids, *args): - users_roles = self.pool.get('res.users').browse(cr, uid, uid).roles_id - for role in users_roles: - if role.name=='Period': - mode = 'draft' - for id in ids: - cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id)) - cr.execute('update account_period set state=%s where id=%s', (mode, id)) + mode = 'draft' + for id in ids: + cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id)) + cr.execute('update account_period set state=%s where id=%s', (mode, id)) return True def name_search(self, cr, user, name, args=None, operator='ilike', context={}, limit=80): @@ -1004,9 +1001,9 @@ class account_move(osv.osv): """ if not args: - args=[] + args = [] if not context: - context={} + context = {} ids = [] if name: ids += self.search(cr, user, [('name','ilike',name)]+args, limit=limit, context=context) @@ -1022,7 +1019,7 @@ class account_move(osv.osv): def name_get(self, cursor, user, ids, context=None): if not len(ids): return [] - res=[] + res = [] data_move = self.pool.get('account.move').browse(cursor,user,ids) for move in data_move: if move.state=='draft': @@ -1036,8 +1033,7 @@ class account_move(osv.osv): periods = self.pool.get('account.period').find(cr, uid) if periods: return periods[0] - else: - return False + return False def _amount_compute(self, cr, uid, ids, name, args, context, where =''): if not ids: return {} @@ -1051,21 +1047,25 @@ class account_move(osv.osv): return result def _search_amount(self, cr, uid, obj, name, args, context): - ids = [] - cr.execute('select move_id,sum(debit) from account_move_line group by move_id') - result = dict(cr.fetchall()) - - for item in args: - if item[1] == '>=': - res = [('id', 'in', [k for k,v in result.iteritems() if v >= item[2]])] + ids = set() + for cond in args: + amount = cond[2] + if isinstance(cond[2],(list,tuple)): + if cond[1] in ['in','not in']: + amount = tuple(cond[2]) + else: + continue else: - res = [('id', 'in', [k for k,v in result.iteritems() if v <= item[2]])] - ids += res - - if not ids: - return [('id', '>', '0')] - - return ids + if cond[1] in ['=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of']: + continue + + cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]) ,(amount,)) + res_ids = set(id[0] for id in cr.fetchall()) + ids = ids and (ids & res_ids) or res_ids + if ids: + return [('id','in',tuple(ids))] + else: + return [('id', '=', '0')] _columns = { 'name': fields.char('Number', size=64, required=True), @@ -1642,9 +1642,9 @@ class account_tax(osv.osv): @return: Returns a list of tupples containing id and name """ if not args: - args=[] + args = [] if not context: - context={} + context = {} ids = [] ids = self.search(cr, user, args, limit=limit, context=context) return self.name_get(cr, user, ids, context=context) @@ -1799,7 +1799,7 @@ class account_tax(osv.osv): tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner) for r in tin: totalex -= r['amount'] - totlex_qty=0.0 + totlex_qty = 0.0 try: totlex_qty=totalex/quantity except: @@ -2220,12 +2220,12 @@ class account_add_tmpl_wizard(osv.osv_memory): } 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) + 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']) - vals={ + vals = { 'name': account_template.name, 'currency_id': account_template.currency_id and account_template.currency_id.id or False, 'code': account_template.code, diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 270384a1d9f..6d5a6ac470b 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -104,8 +104,7 @@ class account_bank_statement(osv.osv): periods = self.pool.get('account.period').find(cr, uid) if periods: return periods[0] - else: - return False + return False def _currency(self, cursor, user, ids, name, args, context=None): res = {} @@ -201,6 +200,7 @@ class account_bank_statement(osv.osv): res_users_obj = self.pool.get('res.users') account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') + account_analytic_line_obj = self.pool.get('account.analytic.line') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') obj_seq = self.pool.get('ir.sequence') @@ -222,6 +222,11 @@ class account_bank_statement(osv.osv): raise osv.except_osv(_('Configuration Error !'), _('Please verify that an account is defined in the journal.')) + if not st.name == '/': + next_number = st.name + else: + next_number = obj_seq.get(cr, uid, 'account.bank.statement') + for line in st.move_line_ids: if line.state <> 'valid': raise osv.except_osv(_('Error !'), @@ -230,14 +235,18 @@ 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}) + if move.analytic_account_id: + if not st.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (st.journal_id.name,)) + + 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, 'date': move.date, }, context=context) account_bank_statement_line_obj.write(cr, uid, [move.id], { - 'move_ids': [(4,move_id, False)] + 'move_ids': [(4, move_id, False)] }) if not move.amount: continue @@ -268,6 +277,7 @@ class account_bank_statement(osv.osv): 'journal_id': st.journal_id.id, 'period_id': st.period_id.id, 'currency_id': st.currency.id, + 'analytic_account_id': move.analytic_account_id and move.analytic_account_id.id or False } amount = res_currency_obj.compute(cr, uid, st.currency.id, @@ -289,7 +299,28 @@ class account_bank_statement(osv.osv): account=acc_cur) val['amount_currency'] = amount_cur - torec.append(account_move_line_obj.create(cr, uid, val , context=context)) + move_line_id = account_move_line_obj.create(cr, uid, val , context=context) + torec.append(move_line_id) + + if move.analytic_account_id: + anal_val = {} + amt = (val['credit'] or 0.0) - (val['debit'] or 0.0) + anal_val = { + 'name': val['name'], + 'ref': val['ref'], + 'date': val['date'], + 'amount': amt, + 'account_id': val['analytic_account_id'], + 'currency_id': val['currency_id'], + 'general_account_id': val['account_id'], + 'journal_id': st.journal_id.analytic_journal_id.id, + 'period_id': val['period_id'], + 'user_id': uid, + 'move_id': move_line_id + } + if val.get('amount_currency', False): + anal_val['amount_currency'] = val['amount_currency'] + account_analytic_line_obj.create(cr, uid, anal_val, context=context) if move.reconcile_id and move.reconcile_id.line_new_ids: for newline in move.reconcile_id.line_new_ids: @@ -367,17 +398,11 @@ class account_bank_statement(osv.osv): account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context) else: account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context) - - if st.journal_id.entry_posted: - account_move_obj.write(cr, uid, [move_id], {'state': 'posted'}) + move_name = next_number + ' - ' + str(move.sequence) + account_move_obj.write(cr, uid, [move_id], {'name': move_name, 'state': 'posted'}) # Bank statements will not consider boolean on journal entry_posted self.log(cr, uid, st.id, 'Statement %s is confirmed and entries are created.' % st.name) done.append(st.id) - - next_number = obj_seq.get(cr, uid, 'account.bank.statement') - if not st.name == '/': - next_number = st.name + '/' + next_number[-1:] - account_move_obj.write(cr, uid, [move_id], {'state': 'posted', 'name': next_number}) self.write(cr, uid, [st.id], {'name': next_number}, context=context) self.write(cr, uid, done, {'state':'confirm'}, context=context) @@ -397,28 +422,15 @@ class account_bank_statement(osv.osv): return True def onchange_journal_id(self, cursor, user, statement_id, journal_id, context=None): - if not journal_id: - return {'value': {'currency': False}} - account_journal_obj = self.pool.get('account.journal') res_users_obj = self.pool.get('res.users') - res_currency_obj = self.pool.get('res.currency') - cursor.execute('SELECT balance_end_real \ FROM account_bank_statement \ - WHERE journal_id = %s \ - ORDER BY date DESC,id DESC LIMIT 1', (journal_id,)) + WHERE journal_id = %s AND NOT state = %s \ + ORDER BY date DESC,id DESC LIMIT 1', (journal_id, 'draft')) res = cursor.fetchone() balance_start = res and res[0] or 0.0 - - currency_id = account_journal_obj.browse(cursor, user, journal_id, - context=context).currency.id - if not currency_id: - currency_id = res_users_obj.browse(cursor, user, user, - context=context).company_id.currency_id.id - currency = res_currency_obj.name_get(cursor, user, [currency_id], - context=context)[0] - return {'value': {'balance_start': balance_start, 'currency': currency}} + return {'value': {'balance_start': balance_start}} def unlink(self, cr, uid, ids, context=None): stat = self.read(cr, uid, ids, ['state']) @@ -629,6 +641,26 @@ class account_bank_statement_line(osv.osv): else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id + + if not line or (line and not line[0].amount): + res_users_obj = self.pool.get('res.users') + res_currency_obj = self.pool.get('res.currency') + company_currency_id = res_users_obj.browse(cursor, user, user, + context=context).company_id.currency_id.id + if not currency_id: + currency_id = company_currency_id + + cursor.execute('SELECT sum(debit-credit) \ + FROM account_move_line \ + WHERE (reconcile_id is null) \ + AND partner_id = %s \ + AND account_id=%s', (partner_id, account_id)) + pgres = cursor.fetchone() + balance = pgres and pgres[0] or 0.0 + + balance = res_currency_obj.compute(cursor, user, company_currency_id, + currency_id, balance, context=context) + res['value']['amount'] = balance return res def _reconcile_amount(self, cursor, user, ids, name, args, context=None): @@ -669,6 +701,7 @@ class account_bank_statement_line(osv.osv): select=True, required=True, ondelete='cascade'), 'reconcile_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile'), + 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'), 'move_ids': fields.many2many('account.move', 'account_bank_statement_line_move_rel', 'move_id','statement_id', 'Moves'), diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index b0a0e8e059e..3e8be7dc2e6 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -125,16 +125,5 @@ always - - ir.actions.todo - account_installer_action_replace - tree - - - -