diff --git a/account_statement_import_sftp/README.rst b/account_statement_import_sftp/README.rst new file mode 100644 index 00000000..d993649d --- /dev/null +++ b/account_statement_import_sftp/README.rst @@ -0,0 +1,97 @@ +========================== +Bank Statement SFTP import +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5c3cf1f51472f25338373320dc7fb418546e2fa8d4de688e6f32a1c937267b6a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github + :target: https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_sftp + :alt: OCA/bank-statement-import +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-statement-import-14-0/bank-statement-import-14-0-account_statement_import_sftp + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add the functionality to automatically import into bank statement the files retrieved from SFTP. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure you should configure an EDI Backend with the backend type *Bank SFTP* + +Usage +===== + +To use this module you should configure an exchange type and a backend SFTP. +Then when the scheduled action of EDI will run you will get your statement imported automatically. + +To post the statement at import create a config parameter import_statement_edi_auto_post with True as value + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Compassion CH + +Contributors +~~~~~~~~~~~~ + +* Simon Gonzalez + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-OCA| image:: https://github.com/OCA.png?size=40px + :target: https://github.com/OCA + :alt: OCA + +Current `maintainer `__: + +|maintainer-OCA| + +This module is part of the `OCA/bank-statement-import `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_statement_import_sftp/__init__.py b/account_statement_import_sftp/__init__.py new file mode 100644 index 00000000..1377f57f --- /dev/null +++ b/account_statement_import_sftp/__init__.py @@ -0,0 +1 @@ +from . import components diff --git a/account_statement_import_sftp/__manifest__.py b/account_statement_import_sftp/__manifest__.py new file mode 100644 index 00000000..97545ced --- /dev/null +++ b/account_statement_import_sftp/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2019 ForgeFlow, S.L. +# Copyright 2020 CorporateHub (https://corporatehub.eu) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Bank Statement SFTP import", + "summary": "Import bank statement from an SFTP server", + "version": "14.0.1.0.0", + "category": "Accounting", + "website": "https://github.com/OCA/bank-statement-import", + "author": "Odoo Community Association (OCA), Compassion CH", + "maintainers": ["OCA"], + "license": "AGPL-3", + "installable": True, + "depends": [ + "edi_storage_oca", # OCA/edi + "storage_backend_sftp", # OCA/storage + "account_statement_import", + "base_automation", + ], + "data": [ + "data/edi_data.xml", + ], +} diff --git a/account_statement_import_sftp/components/__init__.py b/account_statement_import_sftp/components/__init__.py new file mode 100644 index 00000000..cf2eb057 --- /dev/null +++ b/account_statement_import_sftp/components/__init__.py @@ -0,0 +1 @@ +from . import account_statement_import_process diff --git a/account_statement_import_sftp/components/account_statement_import_process.py b/account_statement_import_sftp/components/account_statement_import_process.py new file mode 100644 index 00000000..46b756bd --- /dev/null +++ b/account_statement_import_sftp/components/account_statement_import_process.py @@ -0,0 +1,34 @@ +# Copyright 2023 Compassion CH +# @author: Simon Gonzalez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import _ +from odoo.tools import str2bool + +from odoo.addons.component.core import Component + + +class EdiBankStatementImportProcess(Component): + _name = "edi.input.process.bank.statement.import" + _usage = "input.process" + _backend_type = "bk_sftp_imp" + _inherit = "edi.component.input.mixin" + + def process(self): + ir_config = self.env["ir.config_parameter"].sudo() + auto_post = str2bool(ir_config.get_param("import_statement_edi_auto_post")) + statement_import = self.env["account.statement.import"].create( + [ + { + "statement_file": self.exchange_record.exchange_file, + "statement_filename": self.exchange_record.exchange_filename, + } + ] + ) + action = statement_import.import_file_button() + if not action: + raise ValueError(_("The import didn't succeed.")) + statement = self.env["account.bank.statement"].browse(action.get("res_id")) + if not (statement.state and statement.state in ["posted", "open"]): + raise ValueError(_("The bank statement could not be validated.")) + if auto_post: + statement.button_post() diff --git a/account_statement_import_sftp/data/edi_data.xml b/account_statement_import_sftp/data/edi_data.xml new file mode 100644 index 00000000..f0b122a3 --- /dev/null +++ b/account_statement_import_sftp/data/edi_data.xml @@ -0,0 +1,7 @@ + + + + Bank SFTP Import + bk_sftp_imp + + diff --git a/account_statement_import_sftp/readme/CONFIGURE.rst b/account_statement_import_sftp/readme/CONFIGURE.rst new file mode 100644 index 00000000..593072ce --- /dev/null +++ b/account_statement_import_sftp/readme/CONFIGURE.rst @@ -0,0 +1 @@ +To configure you should configure an EDI Backend with the backend type *Bank SFTP* diff --git a/account_statement_import_sftp/readme/CONTRIBUTORS.rst b/account_statement_import_sftp/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..3ac5359f --- /dev/null +++ b/account_statement_import_sftp/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Simon Gonzalez diff --git a/account_statement_import_sftp/readme/DESCRIPTION.rst b/account_statement_import_sftp/readme/DESCRIPTION.rst new file mode 100644 index 00000000..eba19370 --- /dev/null +++ b/account_statement_import_sftp/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add the functionality to automatically import into bank statement the files retrieved from SFTP. diff --git a/account_statement_import_sftp/readme/HISTORY.rst b/account_statement_import_sftp/readme/HISTORY.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_statement_import_sftp/readme/USAGE.rst b/account_statement_import_sftp/readme/USAGE.rst new file mode 100644 index 00000000..83f51f47 --- /dev/null +++ b/account_statement_import_sftp/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module you should configure an exchange type and a backend SFTP. +Then when the scheduled action of EDI will run you will get your statement imported automatically. + +To post the statement at import create a config parameter import_statement_edi_auto_post with True as value diff --git a/account_statement_import_sftp/static/description/index.html b/account_statement_import_sftp/static/description/index.html new file mode 100644 index 00000000..8526d7a2 --- /dev/null +++ b/account_statement_import_sftp/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Bank Statement SFTP import + + + +
+

Bank Statement SFTP import

+ + +

Beta License: AGPL-3 OCA/bank-statement-import Translate me on Weblate Try me on Runboat

+

This module add the functionality to automatically import into bank statement the files retrieved from SFTP.

+

Table of contents

+ +
+

Configuration

+

To configure you should configure an EDI Backend with the backend type Bank SFTP

+
+
+

Usage

+

To use this module you should configure an exchange type and a backend SFTP. +Then when the scheduled action of EDI will run you will get your statement imported automatically.

+

To post the statement at import create a config parameter import_statement_edi_auto_post with True as value

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Compassion CH
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

OCA

+

This module is part of the OCA/bank-statement-import project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_statement_import_sftp/test_files/camt053 b/account_statement_import_sftp/test_files/camt053 new file mode 100644 index 00000000..0627946a --- /dev/null +++ b/account_statement_import_sftp/test_files/camt053 @@ -0,0 +1,103 @@ + + + + NEWBANK/NL/20240304120000 + 2024-03-04T12:00:00.000Z + + + 5678ABC/1 + 1 + 2024-03-04T12:00:00.000Z + + 2024-03-01T00:00:00.000Z + 2024-03-03T23:59:59.999Z + + + + NL12ABCD3456789012 + + New Company Ltd + + + NEWBNL2X + + + + + + + OPBD + + + 75000.00 + CRDT +
+
2024-03-03
+ +
+ + 1200.00 + DBIT + BOOK + +
2024-03-02
+
+ +
2024-03-02
+
+ + + PMNT + + DBIT + SALR + + + + SLRY + + + + + + NEWBANK/NL/20240302/001 + 1234567890-NEWBNL2X + 987654321 + + + + 1200.00 + + + + + Employee X + + Street 123 + City ABC + NL + + + + + NL34EFGH5678901234 + + + + + + + NEWBNL2X + + + + + Salary payment for March + + Employee ID: 123456 + + +
+
+
+
diff --git a/account_statement_import_sftp/tests/__init__.py b/account_statement_import_sftp/tests/__init__.py new file mode 100644 index 00000000..6ed3dd4a --- /dev/null +++ b/account_statement_import_sftp/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_statement_import_process diff --git a/account_statement_import_sftp/tests/test_account_statement_import_process.py b/account_statement_import_sftp/tests/test_account_statement_import_process.py new file mode 100644 index 00000000..4cba9e24 --- /dev/null +++ b/account_statement_import_sftp/tests/test_account_statement_import_process.py @@ -0,0 +1,98 @@ +import base64 +import datetime + +from odoo.modules.module import get_module_resource +from odoo.tests.common import TransactionCase + +from ..components.account_statement_import_process import EdiBankStatementImportProcess + + +class MockExchangeRecord: + __slots__ = ["exchange_file", "exchange_filename"] + + def __init__(self, exchange_file, exchange_filename: str): + self.exchange_file = exchange_file + self.exchange_filename = exchange_filename + + +class MockWorkContext: + __slots__ = ["env"] + + def __init__(self, env): + self.env = env + + +class EdiBankStatementImportProcessTest(EdiBankStatementImportProcess): + _name = "edi.input.process.bank.statement.import.test" + _inherit = "edi.input.process.bank.statement.import" + + def __init__(self, exchange_record: MockExchangeRecord, *args, **kwargs): + super().__init__(*args, **kwargs) + self.exchange_record = exchange_record + + +class TestAccountStatementImportProcess(TransactionCase): + def setUp(self): + super(TestAccountStatementImportProcess, self).setUp() + + bank = self.env["res.partner.bank"].create( + { + "acc_number": "NL12ABCD3456789012", + "partner_id": self.env.ref("base.main_partner").id, + "company_id": self.env.ref("base.main_company").id, + "bank_id": self.env.ref("base.res_bank_1").id, + } + ) + self.env["account.journal"].create( + { + "name": "Bank Journal", + "type": "bank", + "bank_account_id": bank.id, + "currency_id": self.env.ref("base.EUR").id, + } + ) + + def test_account_statement_import_process(self): + filename = "camt053" + stmt_id = "5678ABC/1" + self._assert_account_statement_import_count(0, filename) + + data = get_module_resource( + "account_statement_import_sftp", "test_files", filename + ) + + with open(data, "rb") as datafile: + file = base64.b64encode(datafile.read()) + + mock_exchange_record = MockExchangeRecord(file, filename) + mock_work_context = MockWorkContext(self.env) + + EdiBankStatementImportProcessTest( + mock_exchange_record, + mock_work_context, + ).process() + + elt = self.env["account.bank.statement"].search( + [("name", "=", stmt_id)], + ) + + tot = 75000.0 + diff = -1200.0 + self.assertEqual("5678ABC/1", elt.name) + self.assertEqual(tot, elt.balance_start) + self.assertEqual(tot + diff, elt.balance_end) + self.assertEqual(datetime.date(2024, 3, 2), elt.date) + self.assertEqual("open", elt.state) + + lines = elt.line_ids + self.assertEqual(diff, lines[0].amount) + + self._assert_account_statement_import_count(1, filename) + + def _assert_account_statement_import_count(self, count, filename): + self.assertEqual( + count, + self.env["account.statement.import"].search_count( + [("statement_filename", "=", filename)] + ), + ) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 21b71834..c55a227e 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,2 +1,4 @@ # See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt web +edi +storage diff --git a/setup/account_statement_import_sftp/odoo/addons/account_statement_import_sftp b/setup/account_statement_import_sftp/odoo/addons/account_statement_import_sftp new file mode 120000 index 00000000..efd06767 --- /dev/null +++ b/setup/account_statement_import_sftp/odoo/addons/account_statement_import_sftp @@ -0,0 +1 @@ +../../../../account_statement_import_sftp \ No newline at end of file diff --git a/setup/account_statement_import_sftp/setup.py b/setup/account_statement_import_sftp/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_statement_import_sftp/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)