[imp] cancel statement line: add reconciliation check also when cancelling all of the statement

This commit is contained in:
Leonardo Pistone
2014-01-27 15:31:43 +01:00
parent 2ead4da982
commit 9b7b54fceb
6 changed files with 62 additions and 22 deletions

View File

@@ -43,7 +43,7 @@
When the user confirms or cancels the whole statement, we keep the
previous functionality, and then we change the state in all statement
lines.
lines. We also add a warning if any lines are reconciled.
When the user confirms or cancels a statement line, we update the state
of the line, and if necessary we update the state of the whole
@@ -56,7 +56,8 @@
'init_xml': [],
'update_xml': [
'statement_view.xml',
'wizard/cancel_line_view.xml',
'wizard/cancel_statement_view.xml',
'wizard/cancel_statement_line_view.xml',
],
'demo_xml': [],
'test': [

View File

@@ -45,7 +45,33 @@ class Statement(orm.Model):
cr, uid, ids, context)
def button_cancel(self, cr, uid, ids, context=None):
"""Change the state on the statement lines. Return super."""
"""Check if there is any reconciliation. Return action."""
st_line_obj = self.pool['account.bank.statement.line']
for statement in self.browse(cr, uid, ids, context=context):
if st_line_obj.has_reconciliation(
cr,
uid,
[line.id for line in statement.line_ids],
context=context):
# ask confirmation, we have some reconciliation already
return {
'type': 'ir.actions.act_window',
'res_model': 'wizard.cancel.statement',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
'context': context,
}
self.do_cancel(cr, uid, ids, context=context)
def do_cancel(self, cr, uid, ids, context=None):
"""Change the state on the statement lines. Return super.
This method is called directly when there are no reconciliations, or
from the warning wizard, if there are reconciliations.
"""
st_line_obj = self.pool['account.bank.statement.line']
for st_data in self.read(cr, uid, ids, ['line_ids'], context=context):
st_line_obj.write(cr, uid, st_data['line_ids'], {

View File

@@ -97,8 +97,8 @@ class StatementLine(orm.Model):
return res
def button_cancel(self, cr, uid, ids, context=None):
"""Check if a line is reconciled, and cancel it. Return action."""
def has_reconciliation(self, cr, uid, ids, context=None):
"""Check if the line has some reconciliation. Return boolean."""
if context is None:
context = {}
@@ -106,10 +106,22 @@ class StatementLine(orm.Model):
for move in st_line.move_ids:
for move_line in move.line_id:
if move_line.reconcile:
# aha! we have some reconciliation!
return True
# no reconciliation to worry about
return False
def button_cancel(self, cr, uid, ids, context=None):
"""Check if a line is reconciled, and cancel it. Return action."""
if context is None:
context = {}
if self.has_reconciliation(cr, uid, ids, context=context):
# ask confirmation, we have some reconciliation already
return {
'type': 'ir.actions.act_window',
'res_model': 'wizard.cancel.line',
'res_model': 'wizard.cancel.statement.line',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',

View File

@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
"""Account Statement Cancel Line."""
"""Wizard for asking the confirmation when some move is reconciled."""
import cancel_line # noqa
import cancel_statement # noqa
import cancel_statement_line # noqa

View File

@@ -23,12 +23,12 @@
from openerp.osv import orm
class wizard_cancel_line(orm.TransientModel):
class wizard_cancel_statement_line(orm.TransientModel):
"""Wizard to Cancel a Statement Line."""
_name = "wizard.cancel.line"
_description = "Cancel Line"
_name = "wizard.cancel.statement.line"
_description = "Cancel Statement Line"
_columns = {
}

View File

@@ -2,9 +2,9 @@
<openerp>
<data>
<record id="view_wizard_cancel_line_form" model="ir.ui.view">
<field name="name">view.wizard.cancel.line.form</field>
<field name="model">wizard.cancel.line</field>
<record id="view_wizard_cancel_statement_line_form" model="ir.ui.view">
<field name="name">view.wizard.cancel.statement.line.form</field>
<field name="model">wizard.cancel.statement.line</field>
<field name="arch" type="xml">
<form string="Reconciled Entries" version="7.0">
<separator string="Unreconciliation"/>