From 3aa3051b4d76d25d392eb63f82d734dd53cd190a Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Mon, 26 Jul 2010 20:11:32 +0530 Subject: [PATCH] [IMP]: account module improvements for the bank and cash statements bzr revid: mga@tinyerp.com-20100726144132-43czgtm069okzshd --- addons/account/account.py | 2 +- addons/account/account_bank_statement.py | 26 +++++++++ addons/account/account_cash_statement.py | 73 +++++++++++++----------- addons/account/account_move_line.py | 2 +- addons/account/account_view.xml | 22 +++---- 5 files changed, 80 insertions(+), 45 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 1817d50901e..b01f659a70d 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1030,7 +1030,6 @@ class account_move(osv.osv): res.append((move.id, name)) return res - def _get_period(self, cr, uid, context): periods = self.pool.get('account.period').find(cr, uid) if periods: @@ -1117,6 +1116,7 @@ class account_move(osv.osv): 'You cannot create entries on different periods/journals in the same move', ['line_id']), ] + def post(self, cr, uid, ids, context=None): if self.validate(cr, uid, ids, context) and len(ids): for move in self.browse(cr, uid, ids): diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 261807fd036..e5581f3f05d 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -160,6 +160,32 @@ class account_bank_statement(osv.osv): 'period_id': _get_period, } + def onchange_date(self, cr, user, ids, date, context={}): + """ + Returns a dict that contains new values and context + @param cr: A database cursor + @param user: ID of the user currently logged in + @param date: latest value from user input for field date + @param args: other arguments + @param context: context arguments, like lang, time zone + @return: Returns a dict which contains new values, and context + """ + res = {} + period_pool = self.pool.get('account.period') + pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)]) + if pids: + res.update({ + 'period_id':pids[0] + }) + context.update({ + 'period_id':pids[0] + }) + + return { + 'value':res, + 'context':context, + } + def button_confirm_bank(self, cr, uid, ids, context={}): done = [] res_currency_obj = self.pool.get('res.currency') diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index b6c36dd3337..9cf14295be2 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -174,6 +174,17 @@ class account_cash_statement(osv.osv): return company_id + def _get_cash_box_lines(self, cr, uid, ids, context={}): + res = [] + curr = [1, 2, 5, 10, 20, 50, 100, 500] + for rs in curr: + dct = { + 'pieces':rs, + 'number':0 + } + res.append(dct) + return res + _columns = { 'company_id':fields.many2one('res.company', 'Company', required=False), 'journal_id': fields.many2one('account.journal', 'Journal', required=True), @@ -197,24 +208,23 @@ class account_cash_statement(osv.osv): 'date': lambda *a:time.strftime("%Y-%m-%d %H:%M:%S"), 'journal_id': _default_journal_id, 'user_id': lambda self, cr, uid, context=None: uid, - 'company_id': _get_company + 'company_id': _get_company, + 'starting_details_ids':_get_cash_box_lines, + 'ending_details_ids':_get_cash_box_lines } def create(self, cr, uid, vals, context=None): company_id = vals and vals.get('company_id',False) if company_id: - open_jrnl = self.search(cr, uid, [('company_id', '=', vals['company_id']), ('journal_id', '=', vals['journal_id']), ('state', '=', 'open')]) + sql = [ + ('company_id', '=', vals['company_id']), + ('journal_id', '=', vals['journal_id']), + ('state', '=', 'open') + ] + open_jrnl = self.search(cr, uid, sql) if open_jrnl: - raise osv.except_osv('Error', u'Une caisse de type espèce est déjà ouverte') - if 'starting_details_ids' in vals: - vals['starting_details_ids'] = starting_details_ids = map(list, vals['starting_details_ids']) - for i in starting_details_ids: - if i and i[0] and i[1]: - i[0], i[1] = 0, 0 + raise osv.except_osv('Error', _('You can not have two open register for the same journal')) res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) - res = self._get_starting_balance(cr, uid, [res_id]) - for rs in res: - super(account_cash_statement, self).write(cr, uid, rs, res.get(rs)) return res_id def write(self, cr, uid, ids, vals, context=None): @@ -284,27 +294,26 @@ class account_cash_statement(osv.osv): number = self.pool.get('ir.sequence').get(cr, uid, statement.journal_id.sequence_id.code) - if len(statement.starting_details_ids) > 0: - sid = [] - for line in statement.starting_details_ids: - sid.append(line.id) - - cash_pool.unlink(cr, uid, sid) - - cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) - rs = cr.fetchone() - rs = rs and rs[0] or None - if rs: - statement = statement_pool.browse(cr, uid, rs) - balance_start = statement.balance_end_real or 0.0 - open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) - for sid in open_ids: - default = { - 'ending_id': False, - 'starting_id':ids[0] - } - cash_pool.copy(cr, uid, sid, default) - +# if len(statement.starting_details_ids) > 0: +# sid = [] +# for line in statement.starting_details_ids: +# sid.append(line.id) +# cash_pool.unlink(cr, uid, sid) +# +# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) +# rs = cr.fetchone() +# rs = rs and rs[0] or None +# if rs: +# statement = statement_pool.browse(cr, uid, rs) +# balance_start = statement.balance_end_real or 0.0 +# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) +# for sid in open_ids: +# default = { +# 'ending_id': False, +# 'starting_id':ids[0] +# } +# cash_pool.copy(cr, uid, sid, default) +# vals = { 'date':time.strftime("%Y-%m-%d %H:%M:%S"), 'state':'open', diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 40f3f113306..192b4dc7ff2 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -819,7 +819,7 @@ class account_move_line(osv.osv): fld = [] fields = {} flds = [] - title = self.view_header_get(cr, uid, view_id, view_type, context) + title = "Accounting Entries" #self.view_header_get(cr, uid, view_id, view_type, context) xml = '''\n\n\t''' % (title) journal_pool = self.pool.get('account.journal') diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 61384a84f9f..77267fb18cc 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -477,9 +477,9 @@ + - @@ -498,7 +498,7 @@
- + @@ -578,12 +578,12 @@ - - New Statement - account.bank.statement - form - form,tree - + + + + + + account.bank.statement.reconcile.form @@ -2420,7 +2420,7 @@ - + @@ -2434,7 +2434,7 @@ - + @@ -2455,7 +2455,7 @@ - +