diff --git a/account_bank_statement_import_camt_oca/README.rst b/account_bank_statement_import_camt_oca/README.rst index 327bd47..8269ec7 100644 --- a/account_bank_statement_import_camt_oca/README.rst +++ b/account_bank_statement_import_camt_oca/README.rst @@ -10,6 +10,20 @@ Module to import SEPA CAMT.053 and CAMT.054 Format bank statement files. Based on the Banking addons framework. +Configuration +============= + +The user can configure the way CAMT bank statements are imported: + +* Go to *Settings* -> *General Settings* -> *Invoicing* +* Set the *CAMT (OCA) Import Batch* checkbox + +If the *CAMT (OCA) Import Batch* checkbox is false, the import will load every single line of the TxDtls details; +instead if it's true, it will load only the total amount of each batch of lines. + +To be able to access the configuration settings, the user must belong to *Show Full Accounting Features* group. + + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/174/11.0 diff --git a/account_bank_statement_import_camt_oca/__manifest__.py b/account_bank_statement_import_camt_oca/__manifest__.py index d5e8ab0..d09c6cb 100644 --- a/account_bank_statement_import_camt_oca/__manifest__.py +++ b/account_bank_statement_import_camt_oca/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CAMT Format Bank Statements Import', - 'version': '11.0.1.0.4', + 'version': '11.0.1.1.0', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', @@ -12,5 +12,6 @@ ], 'data': [ 'views/account_bank_statement_import.xml', + 'views/res_config_settings.xml', ], } diff --git a/account_bank_statement_import_camt_oca/models/__init__.py b/account_bank_statement_import_camt_oca/models/__init__.py index 8b7d2c6..a281617 100644 --- a/account_bank_statement_import_camt_oca/models/__init__.py +++ b/account_bank_statement_import_camt_oca/models/__init__.py @@ -2,3 +2,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import parser from . import account_bank_statement_import +from . import res_company +from . import res_config_settings diff --git a/account_bank_statement_import_camt_oca/models/parser.py b/account_bank_statement_import_camt_oca/models/parser.py index 8bb871c..c188966 100644 --- a/account_bank_statement_import_camt_oca/models/parser.py +++ b/account_bank_statement_import_camt_oca/models/parser.py @@ -19,13 +19,13 @@ class CamtParser(models.AbstractModel): sign = 1 amount = 0.0 sign_node = node.xpath('ns:CdtDbtInd', namespaces={'ns': ns}) - if not sign_node: + if not sign_node and not self.env.user.company_id.camt_import_batch: sign_node = node.xpath( '../../ns:CdtDbtInd', namespaces={'ns': ns}) if sign_node and sign_node[0].text == 'DBIT': sign = -1 amount_node = node.xpath('ns:Amt', namespaces={'ns': ns}) - if not amount_node: + if not amount_node and not self.env.user.company_id.camt_import_batch: amount_node = node.xpath( './ns:AmtDtls/ns:TxAmt/ns:Amt', namespaces={'ns': ns}) if amount_node: @@ -133,6 +133,8 @@ class CamtParser(models.AbstractModel): transaction = transaction_base.copy() self.parse_transaction_details(ns, node, transaction) yield transaction + if self.env.user.company_id.camt_import_batch: + break def get_balance_amounts(self, ns, node): """Return opening and closing balance. diff --git a/account_bank_statement_import_camt_oca/models/res_company.py b/account_bank_statement_import_camt_oca/models/res_company.py new file mode 100644 index 0000000..aaabc7d --- /dev/null +++ b/account_bank_statement_import_camt_oca/models/res_company.py @@ -0,0 +1,10 @@ +# Copyright 2018 Onestein () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = 'res.company' + + camt_import_batch = fields.Boolean() diff --git a/account_bank_statement_import_camt_oca/models/res_config_settings.py b/account_bank_statement_import_camt_oca/models/res_config_settings.py new file mode 100644 index 0000000..8a6ea13 --- /dev/null +++ b/account_bank_statement_import_camt_oca/models/res_config_settings.py @@ -0,0 +1,10 @@ +# Copyright 2018 Onestein () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + camt_import_batch = fields.Boolean(related='company_id.camt_import_batch') diff --git a/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py b/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py index 95ef967..1f0fe0f 100644 --- a/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py @@ -148,3 +148,64 @@ class TestImport(TransactionCase): action['context']['statement_ids'] ): self.assertTrue(statement.line_ids) + + def test_statement_import_batch(self): + """Test correct creation of single statement.""" + transactions = [ + { + 'account_number': 'NL46ABNA0499998748', + 'amount': -754.25, + 'date': '2014-01-05', + 'ref': '435005714488-ABNO33052620', + }, + { + 'account_number': 'NL46ABNA0499998748', + 'amount': -664.05, + 'date': '2014-01-05', + 'ref': 'TESTBANK/NL/20141229/01206408', + }, + { + 'account_number': 'NL69ABNA0522123643', + 'amount': 1405.31, + 'date': '2014-01-05', + 'ref': '115', + }, + ] + + self.env.user.company_id.camt_import_batch = True + testfile = get_module_resource( + 'account_bank_statement_import_camt_oca', + 'test_files', + 'test-camt053', + ) + with open(testfile, 'rb') as datafile: + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode(datafile.read()) + }).import_file() + + for statement in self.env['account.bank.statement'].browse( + action['context']['statement_ids'] + ): + self.assertTrue(any( + all( + line[key] == transactions[0][key] + for key in ['amount', 'date', 'ref'] + ) and + line.bank_account_id.acc_number == + self.transactions[0]['account_number'] + for line in statement.line_ids + )) + + def test_config(self): + """Test configuration of batch statements.""" + self.assertFalse(self.env.user.company_id.camt_import_batch) + conf = self.env['res.config.settings'].create({ + 'camt_import_batch': True + }) + conf.set_values() + self.assertTrue(self.env.user.company_id.camt_import_batch) + conf.write({ + 'camt_import_batch': False + }) + conf.set_values() + self.assertFalse(self.env.user.company_id.camt_import_batch) diff --git a/account_bank_statement_import_camt_oca/views/res_config_settings.xml b/account_bank_statement_import_camt_oca/views/res_config_settings.xml new file mode 100644 index 0000000..4398af6 --- /dev/null +++ b/account_bank_statement_import_camt_oca/views/res_config_settings.xml @@ -0,0 +1,24 @@ + + + + + + res.config.settings + + +
+
+ +
+
+
+
+
+
+
+ +