[FIX]: fix a problem for the unreconcile of voucher

[IMP]: improve the bank statement and cash statement

bzr revid: mga@tinyerp.com-20100709091212-7unqfc73bs62isrv
This commit is contained in:
Mantavya Gajjar 2010-07-09 14:42:12 +05:30
parent 5de014638c
commit 988067423d
4 changed files with 81 additions and 33 deletions

View File

@ -67,19 +67,25 @@ class account_cash_statement(osv.osv):
_inherit = 'account.bank.statement'
def _get_starting_balance(self, cr, uid, ids, name, arg, context=None):
def _get_starting_balance(self, cr, uid, ids, context=None):
""" Find starting balance "
""" Find starting 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
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]=amount_total
res[statement.id] = {
'balance_start':amount_total
}
return res
def _balance_end_cash(self, cr, uid, ids, name, arg, context=None):
@ -116,7 +122,7 @@ class account_cash_statement(osv.osv):
""" To get default journal for the object"
@param name: Names of fields.
@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)])
if journal:
@ -166,11 +172,10 @@ class account_cash_statement(osv.osv):
company_id = company_pool.search(cr, uid, [])[0]
return company_id
_columns = {
'company_id':fields.many2one('res.company', 'Company', required=False),
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'balance_start': fields.function(_get_starting_balance, store=True, method=True, string='Opening Balance', type='float',digits=(16,2), help="Opening balance based on cashBox"),
'balance_end_real': fields.float('Closing Balance', digits=(16,2), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"),
'state': fields.selection(
[('draft', 'Draft'),
@ -205,8 +210,31 @@ class account_cash_statement(osv.osv):
for i in starting_details_ids:
if i and i[0] and i[1]:
i[0], i[1] = 0, 0
res = super(account_cash_statement, self).create(cr, uid, vals, context=context)
return res
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):
"""
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"
@ -300,16 +328,20 @@ class account_cash_statement(osv.osv):
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 !'), _('Cash balance is not matching with closing 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') +
_('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end))
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') +
# _('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end))
if (not st.journal_id.default_credit_account_id) \
or (not st.journal_id.default_debit_account_id):
raise osv.except_osv(_('Configuration Error !'),
@ -435,7 +467,7 @@ class account_cash_statement(osv.osv):
if move.reconcile_id and move.reconcile_id.line_ids:
torec += map(lambda x: x.id, move.reconcile_id.line_ids)
#try:
if abs(move.reconcile_amount-move.amount)<0.0001:
writeoff_acc_id = False
@ -447,13 +479,16 @@ class account_cash_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)
#except:
# raise osv.except_osv(_('Error !'), _('Unable to reconcile entry "%s": %.2f') % (move.name, move.amount))
if st.journal_id.entry_posted:
account_move_obj.write(cr, uid, [move_id], {'state':'posted'})
done.append(st.id)
self.write(cr, uid, done, {'state':'confirm'}, context=context)
vals = {
'state':'confirm',
'closing_date':time.strftime("%Y-%m-%d %H:%M:%S")
}
self.write(cr, uid, done, vals, context=context)
return True
def button_cancel(self, cr, uid, ids, context={}):

View File

@ -465,7 +465,7 @@
<field name="journal_id" on_change="onchange_journal_id(journal_id)" select="1"/>
<field name="period_id"/>
<field name="balance_start"/>
<field name="balance_end_real"/>
<field name="balance_end_real"/>
</group>
<notebook colspan="4">
<page string="Transaction">
@ -518,6 +518,18 @@
<field name="view_mode">tree,form</field>
<field name="domain">[('journal_id.type', '=', 'bank')]</field>
</record>
<record model="ir.actions.act_window.view" id="action_bank_statement_tree_bank">
<field name="sequence" eval="1"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_bank_statement_tree"/>
<field name="act_window_id" ref="action_bank_statement_tree"/>
</record>
<record model="ir.actions.act_window.view" id="action_bank_statement_form_bank">
<field name="sequence" eval="1"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_bank_statement_form"/>
<field name="act_window_id" ref="action_bank_statement_tree"/>
</record>
<menuitem string="Bank Statements" action="action_bank_statement_tree" id="menu_bank_statement_tree" parent="menu_finance_bank_and_cash" sequence="7"/>
<record id="action_bank_statement_draft_tree" model="ir.actions.act_window">
@ -2285,7 +2297,7 @@
<field name="journal_id" on_change="onchange_journal_id(journal_id)" domain="[('type','=','cash')]" select="1" />
<field name="user_id" select="1" readonly="1"/>
<field name="period_id" select="1"/>
<field name="balance_end_real"/>
<!-- <field name="balance_end_real"/>-->
</group>
<notebook colspan="4">
@ -2318,7 +2330,7 @@
</form>
</field>
</page>
<page string="Cash Box">
<page string="CashBox">
<group col="2" colspan="2" expand="1">
<field name="starting_details_ids" nolabel="1" colspan="2" attrs="{'readonly':[('state','=','draft')]}">
<tree string = "Opening Balance" editable="bottom">
@ -2349,7 +2361,7 @@
</group>
</page>
<page string="Accounting Entries" attrs="{'invisible': [('state','!=','confirm')]}">
<field colspan="4" name="move_line_ids" nolabel="1"/>
<field colspan="4" name="move_line_ids" nolabel="1" string="Accounting Entries"/>
</page>
</notebook>
<group col="6" colspan="4">
@ -2360,13 +2372,13 @@
</group>
<group col="2" colspan="2">
<separator string="Opening Balance" colspan="4"/>
<field name="balance_start"/>
<field name="balance_start" readonly="1"/>
<field name="total_entry_encoding"/>
</group>
<group col="2" colspan="2">
<separator string="Closing Balance" colspan="4"/>
<field name="balance_end" string="Approx"/>
<field name="balance_end_cash" string="Cash Balance"/>
<field name="balance_end" string="Calculated Balance"/>
<field name="balance_end_cash" string="CashBox Balance"/>
</group>
</group>
<group col="8" colspan="4">

View File

@ -1,16 +1,17 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_account_journal_form_inherit" model="ir.ui.view">
<record id="view_account_journal_form_inherit" model="ir.ui.view">
<field name="name">account.journal.form</field>
<field name="model">account.journal</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="/form/notebook/page[@string='General Information']/group/group/field[@name='centralisation']" position="after">
<field name="entry_posted" position="after">
<!-- <xpath expr="/form/notebook/page[@string='General Information']/group/group/field[@name='centralisation']" position="after">-->
<field name="update_posted"/>
</xpath>
</field>
</field>
</record>
</data>
</openerp>
</record>
</data>
</openerp>

View File

@ -49,7 +49,7 @@ class account_voucher_unreconcile(osv.osv_memory):
recs = [line.reconcile_id.id]
for rec in recs:
obj_reconcile.unlink(cr, uid, rec)
reconcile_pool.unlink(cr, uid, rec)
if res.remove:
wf_service = netsvc.LocalService("workflow")