diff --git a/account_statement_import_ofx_by_acctid/README.rst b/account_statement_import_ofx_by_acctid/README.rst new file mode 100644 index 00000000..6691a098 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/README.rst @@ -0,0 +1,76 @@ +=================================== +Import OFX Bank Statement by ACCTID +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_ofx_by_acctid + :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_ofx_by_acctid + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/174/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* `Escodoo `_: + + * Marcel Savegnago + * Douglas Custódio + * Augusto Lisboa + +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. + +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_ofx_by_acctid/__init__.py b/account_statement_import_ofx_by_acctid/__init__.py new file mode 100644 index 00000000..aee8895e --- /dev/null +++ b/account_statement_import_ofx_by_acctid/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/account_statement_import_ofx_by_acctid/__manifest__.py b/account_statement_import_ofx_by_acctid/__manifest__.py new file mode 100644 index 00000000..1b6954e8 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2022 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Import OFX Bank Statement by ACCTID", + "summary": """ + Import OFX Bank Statement by ACCTID""", + "category": "Banking addons", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/bank-statement-import", + "depends": [ + "account_statement_import_ofx", + ], + "data": [ + "views/res_partner_bank.xml", + ], + "demo": [], +} diff --git a/account_statement_import_ofx_by_acctid/models/__init__.py b/account_statement_import_ofx_by_acctid/models/__init__.py new file mode 100644 index 00000000..7ff1ea22 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner_bank diff --git a/account_statement_import_ofx_by_acctid/models/res_partner_bank.py b/account_statement_import_ofx_by_acctid/models/res_partner_bank.py new file mode 100644 index 00000000..e3ea0fc0 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/models/res_partner_bank.py @@ -0,0 +1,24 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + +from odoo.addons.base.models.res_bank import sanitize_account_number + + +class ResPartnerBank(models.Model): + + _inherit = "res.partner.bank" + + acctid = fields.Char("ACCTID") + sanitized_acctid = fields.Char( + compute="_compute_sanitized_acctid", + string="Sanitized ACCTID", + readonly=True, + store=True, + ) + + @api.depends("acctid") + def _compute_sanitized_acctid(self): + for bank in self: + bank.sanitized_acctid = sanitize_account_number(bank.acctid) diff --git a/account_statement_import_ofx_by_acctid/readme/CONTRIBUTORS.rst b/account_statement_import_ofx_by_acctid/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..30a89e31 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Escodoo `_: + + * Marcel Savegnago + * Douglas Custódio + * Augusto Lisboa diff --git a/account_statement_import_ofx_by_acctid/readme/DESCRIPTION.rst b/account_statement_import_ofx_by_acctid/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_statement_import_ofx_by_acctid/readme/USAGE.rst b/account_statement_import_ofx_by_acctid/readme/USAGE.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_statement_import_ofx_by_acctid/static/description/icon.png b/account_statement_import_ofx_by_acctid/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_statement_import_ofx_by_acctid/static/description/icon.png differ diff --git a/account_statement_import_ofx_by_acctid/static/description/index.html b/account_statement_import_ofx_by_acctid/static/description/index.html new file mode 100644 index 00000000..f113fa3b --- /dev/null +++ b/account_statement_import_ofx_by_acctid/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +Import OFX Bank Statement by ACCTID + + + +
+

Import OFX Bank Statement by ACCTID

+ + +

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

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Escodoo
  • +
+
+
+

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.

+

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_ofx_by_acctid/tests/__init__.py b/account_statement_import_ofx_by_acctid/tests/__init__.py new file mode 100644 index 00000000..bb3456ae --- /dev/null +++ b/account_statement_import_ofx_by_acctid/tests/__init__.py @@ -0,0 +1 @@ +from . import test_import_bank_statement diff --git a/account_statement_import_ofx_by_acctid/tests/test_import_bank_statement.py b/account_statement_import_ofx_by_acctid/tests/test_import_bank_statement.py new file mode 100644 index 00000000..6234dd7c --- /dev/null +++ b/account_statement_import_ofx_by_acctid/tests/test_import_bank_statement.py @@ -0,0 +1,114 @@ +import base64 +import datetime + +from odoo.modules.module import get_module_resource +from odoo.tests.common import TransactionCase + + +class TestOfxFile(TransactionCase): + """Tests for import bank statement ofx file format + (account.bank.statement.import) + """ + + def setUp(self): + super(TestOfxFile, self).setUp() + self.asi_model = self.env["account.statement.import"] + self.abs_model = self.env["account.bank.statement"] + self.j_model = self.env["account.journal"] + self.absl_model = self.env["account.bank.statement.line"] + cur = self.env.ref("base.USD") + # self.env.ref("base.main_company").currency_id = cur.id + bank = self.env["res.partner.bank"].create( + { + "acc_number": "223456", + "acctid": "223456-X", + "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 TEST OFX", + "code": "BNK12", + "type": "bank", + "bank_account_id": bank.id, + "currency_id": cur.id, + } + ) + + bank_iban_ofx = self.env["res.partner.bank"].create( + { + "acc_number": "FR7630001007942234567890185", + "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": "FR7630001007942234567890185", + "code": "BNK13", + "type": "bank", + "bank_account_id": bank_iban_ofx.id, + "currency_id": cur.id, + } + ) + + def test_wrong_ofx_file_import(self): + ofx_file_path = get_module_resource( + "account_statement_import_ofx_by_acctid", + "tests/test_ofx_file/", + "test_ofx_wrong.ofx", + ) + ofx_file_wrong = base64.b64encode(open(ofx_file_path, "rb").read()) + bank_statement = self.asi_model.create( + { + "statement_file": ofx_file_wrong, + "statement_filename": "test_ofx_wrong.ofx", + } + ) + self.assertFalse(bank_statement._check_ofx(data_file=ofx_file_wrong)) + + def test_ofx_file_import(self): + ofx_file_path = get_module_resource( + "account_statement_import_ofx_by_acctid", + "tests/test_ofx_file/", + "test_ofx.ofx", + ) + ofx_file = base64.b64encode(open(ofx_file_path, "rb").read()) + bank_statement = self.asi_model.create( + { + "statement_file": ofx_file, + "statement_filename": "test_ofx.ofx", + } + ) + bank_statement.import_file_button() + bank_st_record = self.abs_model.search([("name", "like", "223456-X")])[0] + self.assertEqual(bank_st_record.balance_start, 2516.56) + self.assertEqual(bank_st_record.balance_end_real, 2156.56) + + line = self.absl_model.search( + [ + ("payment_ref", "=", "Agrolait"), + ("statement_id", "=", bank_st_record.id), + ] + )[0] + self.assertEqual(line.date, datetime.date(2013, 8, 24)) + + def test_check_journal_bank_account(self): + ofx_file_path = get_module_resource( + "account_statement_import_ofx_by_acctid", + "tests/test_ofx_file/", + "test_ofx_iban.ofx", + ) + ofx_file = base64.b64encode(open(ofx_file_path, "rb").read()) + bank_st = self.asi_model.create( + { + "statement_file": ofx_file, + "statement_filename": "test_ofx_iban.ofx", + } + ) + bank_st.import_file_button() diff --git a/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx.ofx b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx.ofx new file mode 100644 index 00000000..7aac0753 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx.ofx @@ -0,0 +1,100 @@ + + + + + + + 0 + INFO + + 20130831165153.000[-8:PST] + ENG + + + + + 0 + + 0 + INFO + + + USD + + 000000123 + 223456-X + CHECKING + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -80 + 219378 + Agrolait + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219379 + China Export + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -100 + 219380 + Axelor Scuba + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219381 + China Scuba + + + + 2156.56 + 20130831165153 + + + + + + + 0 + + 0 + INFO + + + USD + + 123412341234 + + + + + -562.00 + 20130831165153 + + + + + diff --git a/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_iban.ofx b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_iban.ofx new file mode 100644 index 00000000..cbc5c344 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_iban.ofx @@ -0,0 +1,101 @@ + + + + + + + 0 + INFO + + 20130831165153.000[-8:PST] + ENG + + + + + 0 + + 0 + INFO + + + USD + + 30001 + 00794 + 22345678901 + CHECKING + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -80 + 219378 + Agrolait + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219379 + China Export + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -100 + 219380 + Axelor Scuba + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219381 + China Scuba + + + + 2156.56 + 20130831165153 + + + + + + + 0 + + 0 + INFO + + + USD + + 123412341234 + + + + + -562.00 + 20130831165153 + + + + + diff --git a/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_wrong.ofx b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_wrong.ofx new file mode 100644 index 00000000..23a66746 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/tests/test_ofx_file/test_ofx_wrong.ofx @@ -0,0 +1,100 @@ + + + + + + + 0 + INFO + + 20130831165153.000[-8:PST] + ENG + + + + + 0 + + 0 + INFO + + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -80 + 219378 + Agrolait + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + + China Export + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -100 + 219380 + Axelor Scuba + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219381 + China Scuba + + + + 2156.56 + 20130831165153 + + + + + + + 0 + + 0 + INFO + + + USD + + 123412341234 + + + + + -562.00 + 20130831165153 + + + + + diff --git a/account_statement_import_ofx_by_acctid/views/res_partner_bank.xml b/account_statement_import_ofx_by_acctid/views/res_partner_bank.xml new file mode 100644 index 00000000..ce069884 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/views/res_partner_bank.xml @@ -0,0 +1,19 @@ + + + + + + res.partner.bank.form (in account_statement_import_ofx_acctid) + res.partner.bank + + + + + + + + + diff --git a/account_statement_import_ofx_by_acctid/wizards/__init__.py b/account_statement_import_ofx_by_acctid/wizards/__init__.py new file mode 100644 index 00000000..ae69bca2 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_statement_import diff --git a/account_statement_import_ofx_by_acctid/wizards/account_statement_import.py b/account_statement_import_ofx_by_acctid/wizards/account_statement_import.py new file mode 100644 index 00000000..c6eaaa69 --- /dev/null +++ b/account_statement_import_ofx_by_acctid/wizards/account_statement_import.py @@ -0,0 +1,47 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 + +from odoo import _, api, models +from odoo.exceptions import UserError + +from odoo.addons.base.models.res_bank import sanitize_account_number + + +class AccountStatementImport(models.TransientModel): + + _inherit = "account.statement.import" + + @api.model + def _match_journal(self, account_number, currency): + journal_obj = self.env["account.journal"] + + file_data = base64.b64decode(self.statement_file) + if self._check_ofx(file_data): + sanitized_account_number = sanitize_account_number(account_number) + + journal = journal_obj.search( + [ + ("type", "=", "bank"), + ( + "bank_account_id.sanitized_acctid", + "ilike", + sanitized_account_number, + ), + ], + limit=1, + ) + journal_id = self.env.context.get("journal_id") + if journal_id and journal.id != journal_id: + raise UserError( + _( + "The journal found for the file is not consistent with the " + "selected journal. You should use the proper journal or " + "use the generic button on the top of the Accounting Dashboard" + ) + ) + if journal: + account_number = journal.bank_acc_number + + return super()._match_journal(account_number=account_number, currency=currency) diff --git a/setup/account_statement_import_ofx_by_acctid/odoo/addons/account_statement_import_ofx_by_acctid b/setup/account_statement_import_ofx_by_acctid/odoo/addons/account_statement_import_ofx_by_acctid new file mode 120000 index 00000000..875167d4 --- /dev/null +++ b/setup/account_statement_import_ofx_by_acctid/odoo/addons/account_statement_import_ofx_by_acctid @@ -0,0 +1 @@ +../../../../account_statement_import_ofx_by_acctid \ No newline at end of file diff --git a/setup/account_statement_import_ofx_by_acctid/setup.py b/setup/account_statement_import_ofx_by_acctid/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_statement_import_ofx_by_acctid/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)