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 eefe815bf97..f132c933821 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): diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 270384a1d9f..32403f658fc 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -201,6 +201,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 +223,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 +236,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 +278,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 +300,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 +399,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 +423,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 +642,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 +702,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_invoice_view.xml b/addons/account/account_invoice_view.xml index 41d0344de92..db70d5e0e5a 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -500,7 +500,7 @@ - + diff --git a/addons/account/account_menuitem.xml b/addons/account/account_menuitem.xml index 3cb21315350..24f4bb795a2 100644 --- a/addons/account/account_menuitem.xml +++ b/addons/account/account_menuitem.xml @@ -3,8 +3,8 @@ - - + + diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index bab05321f4d..c6e24e07842 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -104,7 +104,7 @@ -