From 7044a2a7a8aa83b81d9baa89f09e179131d73409 Mon Sep 17 00:00:00 2001 From: David Dufresne Date: Wed, 11 Feb 2015 10:43:58 -0500 Subject: [PATCH] Fix refresh_record method so that only one reconcile line is created for each move line Signed-off-by: Sandy Carter --- .../account_banking_reconciliation.py | 3 +- .../tests/__init__.py | 28 ++++++ .../tests/test_bank_reconciliation.py | 97 +++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 account_banking_reconciliation/tests/__init__.py create mode 100644 account_banking_reconciliation/tests/test_bank_reconciliation.py diff --git a/account_banking_reconciliation/account_banking_reconciliation.py b/account_banking_reconciliation/account_banking_reconciliation.py index 01854b832..ded5310cb 100644 --- a/account_banking_reconciliation/account_banking_reconciliation.py +++ b/account_banking_reconciliation/account_banking_reconciliation.py @@ -396,7 +396,8 @@ class bank_acc_rec_statement(orm.Model): to_write['credit_move_line_ids'].append(res) else: to_write['debit_move_line_ids'].append(res) - obj.write(to_write) + + obj.write(to_write) return True diff --git a/account_banking_reconciliation/tests/__init__.py b/account_banking_reconciliation/tests/__init__.py new file mode 100644 index 000000000..457ff3a22 --- /dev/null +++ b/account_banking_reconciliation/tests/__init__.py @@ -0,0 +1,28 @@ +# coding: utf-8 +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2011 NovaPoint Group LLC () +# Copyright (C) 2004-2010 OpenERP SA () +# Copyright (C) 2015 Savoir-faire Linux () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_bank_reconciliation + +checks = [ + test_bank_reconciliation, +] diff --git a/account_banking_reconciliation/tests/test_bank_reconciliation.py b/account_banking_reconciliation/tests/test_bank_reconciliation.py new file mode 100644 index 000000000..6d068e6a5 --- /dev/null +++ b/account_banking_reconciliation/tests/test_bank_reconciliation.py @@ -0,0 +1,97 @@ +# coding: utf-8 +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2011 NovaPoint Group LLC () +# Copyright (C) 2004-2010 OpenERP SA () +# Copyright (C) 2015 Savoir-faire Linux () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests import common +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT + + +class test_bank_reconciliation(common.TransactionCase): + def setUp(self): + super(test_bank_reconciliation, self).setUp() + self.user_model = self.registry('res.users') + self.account_model = self.registry('account.account') + self.journal_model = self.registry('account.journal') + self.move_model = self.registry('account.move') + self.move_line_model = self.registry('account.move.line') + self.reconcile_model = self.registry('bank.acc.rec.statement') + + self.context = self.user_model.context_get(self.cr, self.uid) + cr, uid, context = self.cr, self.uid, self.context + + self.account_bank_id = self.account_model.search( + cr, uid, [('type', '=', 'liquidity')], context=context)[0] + + self.account_supplier_id = self.account_model.search( + cr, uid, [('type', '=', 'payable')], context=context)[0] + + self.journal_id = self.journal_model.search( + cr, uid, [('type', '=', 'bank')], context=context)[0] + + today = datetime.now().strftime(DEFAULT_SERVER_DATE_FORMAT) + + self.move_id = self.move_model.create( + cr, uid, { + 'journal_id': self.journal_id, + 'date': today, + 'line_id': [ + (0, 0, { + 'name': 'Test', + 'account_id': move_line[0], + 'debit': move_line[1], + 'credit': move_line[2], + }) + for move_line in [ + (self.account_bank_id, 0, 10), + (self.account_bank_id, 0, 20), + (self.account_bank_id, 0, 30), + (self.account_supplier_id, 60, 0), + ] + ] + }, context=context) + + account_move = self.move_model.browse( + cr, uid, self.move_id, context=context) + + account_move.button_validate() + + self.reconcile_id = self.reconcile_model.create( + cr, uid, { + 'account_id': self.account_bank_id, + 'name': 'Test', + 'ending_date': today, + 'ending_balance': 100, + 'starting_balance': 30, + }, context=context) + + self.reconcile = self.reconcile_model.browse( + cr, uid, self.reconcile_id, context=context) + + self.reconcile.refresh_record() + + self.reconcile.refresh() + + def test_one_reconcile_line_per_move_line(self): + """Test that one line of reconciliation is created for + each account move for the account""" + self.assertEqual(len(self.reconcile.credit_move_line_ids), 3)