Skip to content

Commit

Permalink
[IMP] account, account_cancel: added the possibility to cancel a sing…
Browse files Browse the repository at this point in the history
…le statement line when it has already been through the reconciliation process
  • Loading branch information
qdp-odoo committed Jul 4, 2014
1 parent 83dbbbc commit 9a4784f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
39 changes: 21 additions & 18 deletions addons/account/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,27 +330,13 @@ def button_confirm_bank(self, cr, uid, ids, context=None):
self.pool.get('account.move').post(cr, uid, move_ids, context=context)
self.message_post(cr, uid, [st.id], body=_('Statement %s confirmed, journal items were created.') % (st.name,), context=context)
self.link_bank_to_partner(cr, uid, ids, context=context)
return self.write(cr, uid, ids, {'state':'confirm'}, context=context)
return self.write(cr, uid, ids, {'state': 'confirm'}, context=context)

def button_cancel(self, cr, uid, ids, context=None):
account_move_obj = self.pool.get('account.move')
reconcile_pool = self.pool.get('account.move.reconcile')
move_line_pool = self.pool.get('account.move.line')
move_ids = []
bnk_st_line_ids = []
for st in self.browse(cr, uid, ids, context=context):
for line in st.line_ids:
if line.journal_entry_id:
move_ids.append(line.journal_entry_id.id)
for aml in line.journal_entry_id.line_id:
if aml.reconcile_id:
move_lines = [l.id for l in aml.reconcile_id.line_id]
move_lines.remove(aml.id)
reconcile_pool.unlink(cr, uid, [aml.reconcile_id.id], context=context)
if len(move_lines) >= 2:
move_line_pool.reconcile_partial(cr, uid, move_lines, 'auto', context=context)
if move_ids:
account_move_obj.button_cancel(cr, uid, move_ids, context=context)
account_move_obj.unlink(cr, uid, move_ids, context)
bnk_st_line_ids += [line.id for line in st.line_ids]
self.pool.get('account.bank.statement.line').cancel(cr, uid, bnk_st_line_ids, context=context)
return self.write(cr, uid, ids, {'state': 'draft'}, context=context)

def _compute_balance_end_real(self, cr, uid, journal_id, context=None):
Expand Down Expand Up @@ -444,6 +430,23 @@ def link_bank_to_partner(self, cr, uid, ids, context=None):

class account_bank_statement_line(osv.osv):

def cancel(self, cr, uid, ids, context=None):
account_move_obj = self.pool.get('account.move')
move_ids = []
for line in self.browse(cr, uid, ids, context=context):
if line.journal_entry_id:
move_ids.append(line.journal_entry_id.id)
for aml in line.journal_entry_id.line_id:
if aml.reconcile_id:
move_lines = [l.id for l in aml.reconcile_id.line_id]
move_lines.remove(aml.id)
self.pool.get('account.move.reconcile').unlink(cr, uid, [aml.reconcile_id.id], context=context)
if len(move_lines) >= 2:
self.pool.get('account.move.line').reconcile_partial(cr, uid, move_lines, 'auto', context=context)
if move_ids:
account_move_obj.button_cancel(cr, uid, move_ids, context=context)
account_move_obj.unlink(cr, uid, move_ids, context)

def get_data_for_reconciliations(self, cr, uid, ids, context=None):
""" Used to instanciate a batch of reconciliations in a single request """
# Build a list of reconciliations data
Expand Down
11 changes: 11 additions & 0 deletions addons/account_cancel/account_cancel_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@
</field>
</record>

<record id="bank_statement_cancel_form_inherit" model="ir.ui.view">
<field name="name">bank.statement.cancel.form.inherit</field>
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bank_account_id']" position="after">
<button name="cancel" attrs="{'invisible': [('journal_entry_id', '=', False)]}" string="Cancel" type="object" icon="gtk-undo"/>
</xpath>
</field>
</record>

</data>
</openerp>

0 comments on commit 9a4784f

Please sign in to comment.