From 7f86e4d2ed19208876444b67cdb0e23c3358397c Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Wed, 8 Jun 2011 14:20:20 +0200 Subject: [PATCH 1/2] [REF] account: removed duplicated _columns in account_cash_statement w.r.t. account_bank_statement: - duplicate code is bad by itself, - but it is a problem when trying to load the models in two passes in the server. bzr revid: vmt@openerp.com-20110608122020-355pf5nczahm5tmm --- addons/account/account_bank_statement.py | 14 +++++++------- addons/account/account_cash_statement.py | 7 ------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 54776e5c7e6..b53f3fec592 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -90,7 +90,8 @@ class account_bank_statement(osv.osv): res[statement.id] -= res_currency_obj.compute(cursor, user, company_currency_id, currency_id, line.credit, context=context) - if statement.state == 'draft': + + if statement.state in ('draft', 'open'): for line in statement.line_ids: res[statement.id] += line.amount for r in res: @@ -127,7 +128,7 @@ class account_bank_statement(osv.osv): _name = "account.bank.statement" _description = "Bank Statement" _columns = { - 'name': fields.char('Name', size=64, required=True, help='if you give the Name other then /, its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself', states={'confirm': [('readonly', True)]}), + 'name': fields.char('Name', size=64, required=True, states={'draft': [('readonly', False)]}, readonly=True, help='if you give the Name other then /, its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself'), # readonly for account_cash_statement 'date': fields.date('Date', required=True, states={'confirm': [('readonly', True)]}), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}), @@ -135,20 +136,19 @@ class account_bank_statement(osv.osv): states={'confirm':[('readonly', True)]}), 'balance_start': fields.float('Starting Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly',True)]}), - 'balance_end_real': fields.float('Ending Balance', digits_compute=dp.get_precision('Account'), - states={'confirm':[('readonly', True)]}), - 'balance_end': fields.function(_end_balance, method=True, string='Balance'), + '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"), + 'balance_end': fields.function(_end_balance, method=True, store=True, string='Balance'), 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'line_ids': fields.one2many('account.bank.statement.line', 'statement_id', 'Statement lines', states={'confirm':[('readonly', True)]}), 'move_line_ids': fields.one2many('account.move.line', 'statement_id', 'Entry lines', states={'confirm':[('readonly',True)]}), - 'state': fields.selection([('draft', 'Draft'),('confirm', 'Confirmed')], + 'state': fields.selection([('draft', 'Draft'),('confirm', 'Closed'),('open','Open')], 'State', required=True, states={'confirm': [('readonly', True)]}, readonly="1", help='When new statement is created the state will be \'Draft\'. \ - \n* And after getting confirmation from the bank it will be in \'Confirmed\' state.'), + \n* And after getting confirmation from the bank it will be in \'Confirmed\' state.'), # open for account_cash_statement 'currency': fields.function(_currency, method=True, string='Currency', type='many2one', relation='res.currency'), 'account_id': fields.related('journal_id', 'default_debit_account_id', type='many2one', relation='account.account', string='Account used in this journal', readonly=True, help='used in statement reconciliation domain, but shouldn\'t be used elswhere.'), diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 04e780ade30..515e92b35b3 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -218,18 +218,11 @@ class account_cash_statement(osv.osv): return res _columns = { - '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', 'Closed'), - ('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"), - 'balance_end': fields.function(_end_balance, method=True, store=True, string='Balance', help="Closing balance based on Starting Balance and Cash Transactions"), 'balance_end_cash': fields.function(_balance_end_cash, method=True, store=True, string='Balance', help="Closing balance based on cashBox"), 'starting_details_ids': fields.one2many('account.cashbox.line', 'starting_id', string='Opening Cashbox'), 'ending_details_ids': fields.one2many('account.cashbox.line', 'ending_id', string='Closing Cashbox'), - 'name': fields.char('Name', size=64, required=True, states={'draft': [('readonly', False)]}, readonly=True, help='if you give the Name other then /, its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself'), 'user_id': fields.many2one('res.users', 'Responsible', required=False), } _defaults = { From 922bcfebc13c1038dc94eb77869d8960f979b165 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Wed, 8 Jun 2011 16:26:53 +0200 Subject: [PATCH 2/2] [REF] account: removed now identical code, added comments for the previous change. bzr revid: vmt@openerp.com-20110608142653-rchn5lqt3wm1w5rx --- addons/account/account_bank_statement.py | 4 +-- addons/account/account_cash_statement.py | 33 ------------------------ 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index b53f3fec592..a0e0a1335a1 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -136,8 +136,8 @@ class account_bank_statement(osv.osv): states={'confirm':[('readonly', True)]}), 'balance_start': fields.float('Starting Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly',True)]}), - '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"), - 'balance_end': fields.function(_end_balance, method=True, store=True, string='Balance'), + '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"), # help for account_cash_statement + 'balance_end': fields.function(_end_balance, method=True, store=True, string='Balance'), # store=True for account_cash_statement 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'line_ids': fields.one2many('account.bank.statement.line', 'statement_id', 'Statement lines', diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 515e92b35b3..661883a86ab 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -119,39 +119,6 @@ class account_cash_statement(osv.osv): res2[statement.id] = encoding_total return res2 - 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') - res = {} - - company_currency_id = res_users_obj.browse(cursor, user, user, - context=context).company_id.currency_id.id - - statements = self.browse(cursor, user, ids, context=context) - for statement in statements: - res[statement.id] = statement.balance_start - currency_id = statement.currency.id - for line in statement.move_line_ids: - if line.debit > 0: - if line.account_id.id == \ - statement.journal_id.default_debit_account_id.id: - res[statement.id] += res_currency_obj.compute(cursor, - user, company_currency_id, currency_id, - line.debit, context=context) - else: - if line.account_id.id == \ - statement.journal_id.default_credit_account_id.id: - res[statement.id] -= res_currency_obj.compute(cursor, - user, company_currency_id, currency_id, - line.credit, context=context) - - if statement.state in ('draft', 'open'): - for line in statement.line_ids: - res[statement.id] += line.amount - for r in res: - res[r] = round(res[r], 2) - return res - def _get_company(self, cr, uid, context=None): user_pool = self.pool.get('res.users') company_pool = self.pool.get('res.company')