From eaa1e8605f9023a2966a56d83b255b7e93360d50 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 7 Mar 2014 14:59:48 +0100 Subject: [PATCH] [fix] when the last line in draft of the statement is confirmed, the statement should be confirmed only after passing the usual balance check, if the check is enabled in the profile. I add a test that shows the bug --- account_statement_cancel_line/__openerp__.py | 1 + account_statement_cancel_line/statement.py | 6 +++ .../test_confirm_last_line_balance_check.yml | 42 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 account_statement_cancel_line/test/test_confirm_last_line_balance_check.yml diff --git a/account_statement_cancel_line/__openerp__.py b/account_statement_cancel_line/__openerp__.py index d2c98141..893432cd 100644 --- a/account_statement_cancel_line/__openerp__.py +++ b/account_statement_cancel_line/__openerp__.py @@ -64,6 +64,7 @@ 'demo_xml': [], 'test': [ 'test/cancel_line.yml', + 'test/test_confirm_last_line_balance_check.yml', 'test/test_confirm_last_line_no_balance_check.yml', ], 'installable': True, diff --git a/account_statement_cancel_line/statement.py b/account_statement_cancel_line/statement.py index 131374cf..4092d2fd 100644 --- a/account_statement_cancel_line/statement.py +++ b/account_statement_cancel_line/statement.py @@ -95,4 +95,10 @@ class Statement(orm.Model): 'state': 'confirm' }, context=context) need_to_update_view = True + self.balance_check( + cr, + uid, + statement.id, + journal_type=statement.journal_id.type, + context=context) return need_to_update_view diff --git a/account_statement_cancel_line/test/test_confirm_last_line_balance_check.yml b/account_statement_cancel_line/test/test_confirm_last_line_balance_check.yml new file mode 100644 index 00000000..8afc5a81 --- /dev/null +++ b/account_statement_cancel_line/test/test_confirm_last_line_balance_check.yml @@ -0,0 +1,42 @@ +- + I want to check that the behaviour when I confirm the only line of a + statement that is draft. +- + I start with a profile +- + !record {model: account.statement.profile, id: profile_test3}: + name: Profile for automatic checks + balance_check: True + journal_id: account.bank_journal + commission_account_id: account.a_expense +- + Now I create a statement. +- + !record {model: account.bank.statement, id: statement_test3}: + name: My Statement + profile_id: profile_test3 + company_id: base.main_company + balance_start: 100.0 + balance_end_real: 150.0 +- + I create a statement line +- + !record {model: account.bank.statement.line, id: statement_line_3}: + name: line1 + statement_id: statement_test3 + ref: line1 + date: '2014-01-20' + amount: 10.0 +- + Now I confirm the statement line. That should not pass the balance check +- + !python {model: account.bank.statement.line}: | + # i.e. assertRaises + from openerp.osv.osv import except_osv + try: + self.confirm(cr, uid, [ref("statement_line_3")]) + except except_osv as exc: + print exc.args + assert u'The statement balance is incorrect' in exc.args[1], 'We got an error which is not what we expected' + else: + raise AssertionError('Balance check should have blocked this.')