diff --git a/account_statement_cancel_line/__openerp__.py b/account_statement_cancel_line/__openerp__.py index 15b49f17..d3541a31 100644 --- a/account_statement_cancel_line/__openerp__.py +++ b/account_statement_cancel_line/__openerp__.py @@ -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': [ diff --git a/account_statement_cancel_line/statement.py b/account_statement_cancel_line/statement.py index c01daf3b..5d0aeec4 100644 --- a/account_statement_cancel_line/statement.py +++ b/account_statement_cancel_line/statement.py @@ -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'], { diff --git a/account_statement_cancel_line/statement_line.py b/account_statement_cancel_line/statement_line.py index ec3de506..486ccab9 100644 --- a/account_statement_cancel_line/statement_line.py +++ b/account_statement_cancel_line/statement_line.py @@ -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,15 +106,27 @@ class StatementLine(orm.Model): for move in st_line.move_ids: for move_line in move.line_id: if move_line.reconcile: - # ask confirmation, we have some reconciliation already - return { - 'type': 'ir.actions.act_window', - 'res_model': 'wizard.cancel.line', - 'view_type': 'form', - 'view_mode': 'form', - 'target': 'new', - 'context': context, - } + # 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.statement.line', + 'view_type': 'form', + 'view_mode': 'form', + 'target': 'new', + 'context': context, + } # no reconciliation to worry about: we cancel our lines directly then return self.cancel(cr, uid, ids, context=context) diff --git a/account_statement_cancel_line/wizard/__init__.py b/account_statement_cancel_line/wizard/__init__.py index 32945b30..49b74d3f 100644 --- a/account_statement_cancel_line/wizard/__init__.py +++ b/account_statement_cancel_line/wizard/__init__.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # # # ############################################################################### -"""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 diff --git a/account_statement_cancel_line/wizard/cancel_line.py b/account_statement_cancel_line/wizard/cancel_statement_line.py similarity index 93% rename from account_statement_cancel_line/wizard/cancel_line.py rename to account_statement_cancel_line/wizard/cancel_statement_line.py index 3ba9bea1..c5e20af4 100644 --- a/account_statement_cancel_line/wizard/cancel_line.py +++ b/account_statement_cancel_line/wizard/cancel_statement_line.py @@ -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 = { } diff --git a/account_statement_cancel_line/wizard/cancel_line_view.xml b/account_statement_cancel_line/wizard/cancel_statement_line_view.xml similarity index 75% rename from account_statement_cancel_line/wizard/cancel_line_view.xml rename to account_statement_cancel_line/wizard/cancel_statement_line_view.xml index d450054a..522bd0ae 100644 --- a/account_statement_cancel_line/wizard/cancel_line_view.xml +++ b/account_statement_cancel_line/wizard/cancel_statement_line_view.xml @@ -2,9 +2,9 @@ - - view.wizard.cancel.line.form - wizard.cancel.line + + view.wizard.cancel.statement.line.form + wizard.cancel.statement.line