[MERGE] account: remove duplicate code between cash/bank statements

bzr revid: odo@openerp.com-20110917005007-55khqnqrkqsir9st
This commit is contained in:
Vo Minh Thu (OpenERP) 2011-09-17 02:50:07 +02:00 committed by Olivier Dony
commit 373e5b6e4d
2 changed files with 12 additions and 49 deletions

View File

@ -83,7 +83,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:
@ -120,7 +121,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)]}),
@ -129,19 +130,21 @@ class account_bank_statement(osv.osv):
'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, string='Balance'),
states={'confirm': [('readonly', True)]}),
'balance_end': fields.function(_end_balance, store=True, # store=True for account_cash_statement
string="Balance", help='Balance as calculated based on Starting Balance and transaction lines'),
'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', 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.'),
'state': fields.selection([('draft', 'Draft'),
('open','Open'), # used by cash statements
('confirm', 'Closed')],
'State', required=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.'),
'currency': fields.function(_currency, 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.'),

View File

@ -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')
@ -218,18 +185,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, store=True, string="Cash Transaction", help="Total cash transactions"),
'closing_date': fields.datetime("Closed On"),
'balance_end': fields.function(_end_balance, store=True, string='Balance', help="Closing balance based on Starting Balance and Cash Transactions"),
'balance_end_cash': fields.function(_balance_end_cash, 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 = {