From fb3589a96fdf2d79d1f6ac9a495236d073295fc0 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 23 Mar 2017 13:34:00 +0100 Subject: [PATCH] [ADD] tests --- .../__openerp__.py | 3 + ...k_statement_import_auto_reconcile_rule.xml | 9 +++ ...nt_bank_statement_import_auto_reconcile.py | 61 ++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml diff --git a/account_bank_statement_import_auto_reconcile/__openerp__.py b/account_bank_statement_import_auto_reconcile/__openerp__.py index e3ceef2..b556b05 100644 --- a/account_bank_statement_import_auto_reconcile/__openerp__.py +++ b/account_bank_statement_import_auto_reconcile/__openerp__.py @@ -13,6 +13,9 @@ 'account_bank_statement_import', 'web_widget_one2many_tags', ], + "demo": [ + "demo/account_bank_statement_import_auto_reconcile_rule.xml", + ], "data": [ "views/account_bank_statement_import.xml", "views/account_journal.xml", diff --git a/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml b/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml new file mode 100644 index 0000000..fbe6e72 --- /dev/null +++ b/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml @@ -0,0 +1,9 @@ + + + + + + account.bank.statement.import.auto.reconcile.exact.amount + + + diff --git a/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py b/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py index c5179ec..1f3f9b4 100644 --- a/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py +++ b/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py @@ -1,9 +1,68 @@ # -*- coding: utf-8 -*- # © 2017 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import base64 +from datetime import timedelta +from openerp import fields from openerp.tests.common import TransactionCase +from openerp.addons.account_bank_statement_import.models\ + .account_bank_statement_import import AccountBankStatementImport class TestAccountBankStatementImportAutoReconcile(TransactionCase): + def setUp(self): + super(TestAccountBankStatementImportAutoReconcile, self).setUp() + # we don't really have something to import, so we patch the + # import routine to return what we want for our tests + self.original_parse_file = AccountBankStatementImport._parse_file + AccountBankStatementImport._parse_file = self._parse_file + self.invoice = self.env.ref('account.invoice_4') + + def tearDown(self): + super(TestAccountBankStatementImportAutoReconcile, self).tearDown() + AccountBankStatementImport._parse_file = self.original_parse_file + + def _parse_file(self, data): + date = self.invoice.date_invoice + return [ + { + 'currency_code': self.invoice.company_id.currency_id.name, + 'account_number': + self.invoice.partner_id.bank_ids[:1].acc_number, + 'name': 'Auto reconcile test', + 'date': fields.Date.to_string( + fields.Date.from_string(date) + timedelta(days=5) + ), + 'transactions': [ + { + 'name': 'testtransaction', + 'date': fields.Date.to_string( + fields.Date.from_string(date) + timedelta(days=5) + ), + 'amount': self.invoice.residual, + 'unique_import_id': '42', + }, + ], + }, + ] + def test_account_bank_statement_import_auto_reconcile(self): - pass + # first, we do an import with auto reconciliation turned off + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode('hello world'), + 'journal_id': self.env.ref('account.bank_journal').id, + 'auto_reconcile': False, + }).import_file() + # nothing should have happened + self.assertEqual(self.invoice.state, 'open') + self.env['account.bank.statement'].browse( + action['context']['statement_ids'] + ).unlink() + # for exact amount matching, our first transaction should be matched + # to the invoice's move line, marking the invoice as paid + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode('hello world'), + 'journal_id': self.env.ref('account.bank_journal').id, + 'auto_reconcile': True, + }).import_file() + self.assertEqual(self.invoice.state, 'paid')