diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index e5298fa2f9d..b817f00e89b 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -28,14 +28,14 @@ from tools.translate import _ import decimal_precision as dp class account_cashbox_line(osv.osv): - + """ Cash Box Details """ - + _name = 'account.cashbox.line' _description = 'CashBox Line' def _sub_total(self, cr, uid, ids, name, arg, context=None): - + """ Calculates Sub total @param name: Names of fields. @param arg: User defined arguments @@ -51,7 +51,7 @@ class account_cashbox_line(osv.osv): """ Calculates Sub total on change of number @param pieces: Names of fields. @param number: - """ + """ sub=pieces*number return {'value':{'subtotal': sub or 0.0}} @@ -65,9 +65,9 @@ class account_cashbox_line(osv.osv): account_cashbox_line() class account_cash_statement(osv.osv): - + _inherit = 'account.bank.statement' - + def _get_starting_balance(self, cr, uid, ids, context=None): """ Find starting balance @@ -78,23 +78,23 @@ class account_cash_statement(osv.osv): res ={} for statement in self.browse(cr, uid, ids): amount_total=0.0 - + if statement.journal_id.type not in('cash'): continue - + for line in statement.starting_details_ids: amount_total+= line.pieces * line.number res[statement.id] = { 'balance_start':amount_total } return res - + def _balance_end_cash(self, cr, uid, ids, name, arg, context=None): """ Find ending balance " @param name: Names of fields. @param arg: User defined arguments @return: Dictionary of values. - """ + """ res ={} for statement in self.browse(cr, uid, ids): amount_total=0.0 @@ -102,7 +102,7 @@ class account_cash_statement(osv.osv): amount_total+= line.pieces * line.number res[statement.id]=amount_total return res - + def _get_sum_entry_encoding(self, cr, uid, ids, name, arg, context=None): """ Find encoding total of statements " @@ -120,9 +120,9 @@ class account_cash_statement(osv.osv): # def _default_journal_id(self, cr, uid, context={}): -# """ To get default journal for the object" +# """ To get default journal for the object" # @param name: Names of fields. -# @return: journal +# @return: journal # """ # company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id # journal = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)]) @@ -130,7 +130,7 @@ class account_cash_statement(osv.osv): # return journal[0] # else: # return False - + def _end_balance(self, cursor, user, ids, name, attr, context=None): res_currency_obj = self.pool.get('res.currency') res_users_obj = self.pool.get('res.users') @@ -163,7 +163,7 @@ class account_cash_statement(osv.osv): for r in res: res[r] = round(res[r], 2) return res - + def _get_company(self, cr, uid, ids, context={}): user_pool = self.pool.get('res.users') company_pool = self.pool.get('res.company') @@ -171,7 +171,7 @@ class account_cash_statement(osv.osv): company_id = user.company_id and user.company_id.id if not company_id: company_id = company_pool.search(cr, uid, [])[0] - + return company_id def _get_cash_open_box_lines(self, cr, uid, ids, context={}): @@ -195,14 +195,14 @@ class account_cash_statement(osv.osv): } res.append((0, 0, dct)) return res - + _columns = { 'company_id':fields.many2one('res.company', 'Company', required=False), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'cash')]), 'balance_end_real': fields.float('Closing Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"), 'state': fields.selection( [('draft', 'Draft'), - ('confirm', 'Confirm'), + ('confirm', 'Confirmed'), ('open','Open')], 'State', required=True, states={'confirm': [('readonly', True)]}, readonly="1"), 'total_entry_encoding':fields.function(_get_sum_entry_encoding, method=True, store=True, string="Cash Transaction", help="Total cash transactions"), 'closing_date':fields.datetime("Closed On"), @@ -226,8 +226,8 @@ class account_cash_statement(osv.osv): company_id = vals and vals.get('company_id',False) if company_id: sql = [ - ('company_id', '=', vals['company_id']), - ('journal_id', '=', vals['journal_id']), + ('company_id', '=', vals['company_id']), + ('journal_id', '=', vals['journal_id']), ('state', '=', 'open') ] open_jrnl = self.search(cr, uid, sql) @@ -247,85 +247,85 @@ class account_cash_statement(osv.osv): res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) self.write(cr, uid, [res_id], {}) return res_id - + def write(self, cr, uid, ids, vals, context=None): """ Update redord(s) comes in {ids}, with new value comes as {vals} return True on success, False otherwise - + @param cr: cursor to database @param user: id of current user @param ids: list of record ids to be update @param vals: dict of new values to be set @param context: context arguments, like lang, time zone - + @return: True on success, False otherwise """ - + super(account_cash_statement, self).write(cr, uid, ids, vals) res = self._get_starting_balance(cr, uid, ids) for rs in res: super(account_cash_statement, self).write(cr, uid, rs, res.get(rs)) return True - + def onchange_journal_id(self, cr, uid, statement_id, journal_id, context={}): - """ Changes balance start and starting details if journal_id changes" + """ Changes balance start and starting details if journal_id changes" @param statement_id: Changed statement_id @param journal_id: Changed journal_id @return: Dictionary of changed values """ - + cash_pool = self.pool.get('account.cashbox.line') statement_pool = self.pool.get('account.bank.statement') res = {} balance_start = 0.0 - + if not journal_id: res.update({ 'balance_start': balance_start }) return res - - + + res = super(account_cash_statement, self).onchange_journal_id(cr, uid, statement_id, journal_id, context) return res - + def _equal_balance(self, cr, uid, ids, statement, context={}): if statement.balance_end != statement.balance_end_cash: return False else: return True - + def _user_allow(self, cr, uid, ids, statement, context={}): return True - + def button_open(self, cr, uid, ids, context=None): - + """ Changes statement state to Running. - @return: True + @return: True """ cash_pool = self.pool.get('account.cashbox.line') statement_pool = self.pool.get('account.bank.statement') statement = statement_pool.browse(cr, uid, ids[0]) vals = {} - + if not self._user_allow(cr, uid, ids, statement, context={}): raise osv.except_osv(_('Error !'), _('User %s does not have rights to access %s journal !' % (statement.user_id.name, statement.journal_id.name))) - + if statement.name and statement.name == '/': number = self.pool.get('ir.sequence').get(cr, uid, 'account.cash.statement') vals.update({ 'name':number }) - + # 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 @@ -339,20 +339,20 @@ class account_cash_statement(osv.osv): # 'starting_id':ids[0] # } # cash_pool.copy(cr, uid, sid, default) -# +# vals.update({ - 'date':time.strftime("%Y-%m-%d %H:%M:%S"), + 'date':time.strftime("%Y-%m-%d %H:%M:%S"), 'state':'open', - + }) - + self.write(cr, uid, ids, vals) return True def button_confirm_cash(self, cr, uid, ids, context={}): - - """ Check the starting and ending detail of statement - @return: True + + """ Check the starting and ending detail of statement + @return: True """ done = [] res_currency_obj = self.pool.get('res.currency') @@ -360,20 +360,20 @@ class account_cash_statement(osv.osv): account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') - + company_currency_id = res_users_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id for st in self.browse(cr, uid, ids, context): - + self.write(cr, uid, [st.id], {'balance_end_real':st.balance_end}) st.balance_end_real = st.balance_end - + if not st.state == 'open': continue - + if not self._equal_balance(cr, uid, ids, st, context): raise osv.except_osv(_('Error !'), _('CashBox Balance is not matching with Calculated Balance !')) - + # if not (abs((st.balance_end or 0.0) - st.balance_end_real) < 0.0001): # raise osv.except_osv(_('Error !'), # _('The statement balance is incorrect !\n') + @@ -519,7 +519,7 @@ class account_cash_statement(osv.osv): if st.journal_id.entry_posted: account_move_obj.write(cr, uid, [move_id], {'state':'posted'}) done.append(st.id) - + vals = { 'state':'confirm', 'closing_date':time.strftime("%Y-%m-%d %H:%M:%S")