diff --git a/account_statement_import_camt54/README.rst b/account_statement_import_camt54/README.rst new file mode 100644 index 00000000..2c8e7be1 --- /dev/null +++ b/account_statement_import_camt54/README.rst @@ -0,0 +1,100 @@ +========================== +Bank Account Camt54 Import +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/15.0/account_statement_import_camt54 + :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-15-0/bank-statement-import-15-0-account_statement_import_camt54 + :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/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + + This module allows you to import CAMT.054 file (details of customers payments batch) into a dedicated journal taking care of the start/end balance and the remittance reference number. + +Customer invoices will be reconciled/Paid. Payment entries will be posted into an internal transfer account (that you have to create with a type current asset and set on the journal) + +After this first step, import normally your CAMT.053 (full bank statement) into the bank journal. You will be able to clear the internal transfer account to end up the accounting flow. + +Optionally we can activate add generation of additional line in bank statement which will balance your bank statement total to 0. +This line can be consolidated later with different account. +To enable option of final statement line you need properly set flag on Account Journal +Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration + + +Switzerland localisation +------------------------ + +For ISR containing a partner reference, uses the config parameter key `isr_partner_ref`. +Doing so will fill the partners on bank statement lines and speed up the matches in the reconciliation process. + +Value to set in `isr_partner_ref` defines the position of the partner reference inside the ISR. +The format is `i[,n]` +For instance `13,6` to start on position 13 with a 6 digit long reference. +`n` is optional and it's default value is `6`. + +**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 +~~~~~~~ + +* camptocamp + +Contributors +~~~~~~~~~~~~ + +* Yannick Vaucher +* Timon Tschanz + +Other credits +~~~~~~~~~~~~~ + +* Digital4efficiency.ch + +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_camt54/__init__.py b/account_statement_import_camt54/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_statement_import_camt54/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_statement_import_camt54/__manifest__.py b/account_statement_import_camt54/__manifest__.py new file mode 100644 index 00000000..4d83d628 --- /dev/null +++ b/account_statement_import_camt54/__manifest__.py @@ -0,0 +1,12 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Bank Account Camt54 Import", + "version": "15.0.1.0.0", + "category": "Account", + "website": "https://github.com/OCA/bank-statement-import", + "author": "camptocamp, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["account_statement_import_camt"], +} diff --git a/account_statement_import_camt54/i18n/account_statement_import_camt54.pot b/account_statement_import_camt54/i18n/account_statement_import_camt54.pot new file mode 100644 index 00000000..0cb545ad --- /dev/null +++ b/account_statement_import_camt54/i18n/account_statement_import_camt54.pot @@ -0,0 +1,81 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_statement_import_camt54 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_statement_import_camt_parser +msgid "Account Bank Statement Import CAMT parser" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__transfer_line +msgid "Add balance Line" +msgstr "" + +#. module: account_statement_import_camt54 +#: code:addons/account_statement_import_camt54/models/parser.py:0 +#, python-format +msgid "" +"Config parameter `isr_partner_ref` is wrong.\n" +"It must be in format `i[,n]` \n" +"`i` and `n` must be integers.\n" +"e.g. \"13,6\"" +msgstr "" + +#. module: account_statement_import_camt54 +#: code:addons/account_statement_import_camt54/models/parser.py:0 +#, python-format +msgid "" +"Config parameter `isr_partner_ref` is wrong.\n" +"It must be in format `i[,n]` \n" +"where `i` is the position of the first digit and\n" +"`n` the number of digit in the reference, by default 6.\n" +"e.g. \"13,6\"" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__display_name +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import__display_name +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser__display_name +msgid "Display Name" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,help:account_statement_import_camt54.field_account_journal__transfer_line +msgid "Generate balance line on total of bank statement import" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__id +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import__id +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser__id +msgid "ID" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_statement_import +msgid "Import Bank Statement Files" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_journal +msgid "Journal" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal____last_update +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import____last_update +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser____last_update +msgid "Last Modified on" +msgstr "" diff --git a/account_statement_import_camt54/i18n/it.po b/account_statement_import_camt54/i18n/it.po new file mode 100644 index 00000000..e7a48957 --- /dev/null +++ b/account_statement_import_camt54/i18n/it.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_statement_import_camt54 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-11-25 17:36+0000\n" +"Last-Translator: Sergio Zanchetta \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_statement_import_camt_parser +msgid "Account Bank Statement Import CAMT parser" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__transfer_line +msgid "Add balance Line" +msgstr "" + +#. module: account_statement_import_camt54 +#: code:addons/account_statement_import_camt54/models/parser.py:0 +#, python-format +msgid "" +"Config parameter `isr_partner_ref` is wrong.\n" +"It must be in format `i[,n]` \n" +"`i` and `n` must be integers.\n" +"e.g. \"13,6\"" +msgstr "" + +#. module: account_statement_import_camt54 +#: code:addons/account_statement_import_camt54/models/parser.py:0 +#, python-format +msgid "" +"Config parameter `isr_partner_ref` is wrong.\n" +"It must be in format `i[,n]` \n" +"where `i` is the position of the first digit and\n" +"`n` the number of digit in the reference, by default 6.\n" +"e.g. \"13,6\"" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__display_name +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import__display_name +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,help:account_statement_import_camt54.field_account_journal__transfer_line +msgid "Generate balance line on total of bank statement import" +msgstr "" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal__id +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import__id +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser__id +msgid "ID" +msgstr "ID" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_statement_import +msgid "Import Bank Statement Files" +msgstr "Importazione file estratto conto bancario" + +#. module: account_statement_import_camt54 +#: model:ir.model,name:account_statement_import_camt54.model_account_journal +msgid "Journal" +msgstr "Registro" + +#. module: account_statement_import_camt54 +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_journal____last_update +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import____last_update +#: model:ir.model.fields,field_description:account_statement_import_camt54.field_account_statement_import_camt_parser____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" diff --git a/account_statement_import_camt54/models/__init__.py b/account_statement_import_camt54/models/__init__.py new file mode 100644 index 00000000..7a228b17 --- /dev/null +++ b/account_statement_import_camt54/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_statement_import +from . import account_journal +from . import parser diff --git a/account_statement_import_camt54/models/account_journal.py b/account_statement_import_camt54/models/account_journal.py new file mode 100644 index 00000000..752187a6 --- /dev/null +++ b/account_statement_import_camt54/models/account_journal.py @@ -0,0 +1,14 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountBankStatementImport(models.Model): + + _inherit = "account.journal" + + transfer_line = fields.Boolean( + string="Add balance Line", + help="Generate balance line on total of bank statement import", + ) diff --git a/account_statement_import_camt54/models/account_statement_import.py b/account_statement_import_camt54/models/account_statement_import.py new file mode 100644 index 00000000..594c656c --- /dev/null +++ b/account_statement_import_camt54/models/account_statement_import.py @@ -0,0 +1,51 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging + +from odoo import models + +_logger = logging.getLogger(__name__) + + +class AccountStatementImport(models.TransientModel): + """Add process_camt method to account.bank.statement.import.""" + + _inherit = "account.statement.import" + + def _create_bank_statements(self, stmts_vals, result): + """Create additional line in statement to set bank statement statement + to 0 balance""" + + super()._create_bank_statements(stmts_vals, result) + statements = self.env["account.bank.statement"].browse(result["statement_ids"]) + for statement in statements: + amount = sum(statement.line_ids.mapped("amount")) + if statement.journal_id.transfer_line: + if amount != 0: + amount = -amount + statement.line_ids.create( + { + "amount": amount, + "statement_id": statement.id, + "date": statement.date, + "payment_ref": statement.name, + } + ) + statement.balance_end_real = statement.balance_start + else: + statement.balance_end_real = statement.balance_start + amount + return + + def _complete_stmts_vals(self, stmts_vals, journal, account_number): + """Search partner from partner reference""" + stmts_vals = super()._complete_stmts_vals(stmts_vals, journal, account_number) + for st_vals in stmts_vals: + for line_vals in st_vals["transactions"]: + if "partner_ref" in line_vals: + partner_ref = line_vals.pop("partner_ref") + partner = self.env["res.partner"].search( + [("ref", "=", partner_ref)], limit=1 + ) + line_vals["partner_id"] = partner.id + + return stmts_vals diff --git a/account_statement_import_camt54/models/parser.py b/account_statement_import_camt54/models/parser.py new file mode 100644 index 00000000..ef74f438 --- /dev/null +++ b/account_statement_import_camt54/models/parser.py @@ -0,0 +1,100 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, exceptions, models + + +class CamtParser(models.AbstractModel): + """Parser for camt bank statement import files.""" + + _inherit = "account.statement.import.camt.parser" + + def _get_partner_ref(self, isr): + ICP = self.env["ir.config_parameter"] + ref_format = ICP.sudo().get_param("isr_partner_ref") + if not ref_format: + return + config = ref_format.split(",") + if len(config) == 2: + start, size = config + elif len(config) == 1: + start = config[0] + size = 6 + else: + raise exceptions.UserError( + _( + "Config parameter `isr_partner_ref` is wrong.\n" + "It must be in format `i[,n]` \n" + "where `i` is the position of the first digit and\n" + "`n` the number of digit in the reference," + " by default 6.\n" + 'e.g. "13,6"' + ) + ) + try: + start = int(start) - 1 # count from 1 instead of 0 + size = int(size) + end = start + size + except ValueError as err: + raise exceptions.UserError( + _( + "Config parameter `isr_partner_ref` is wrong.\n" + "It must be in format `i[,n]` \n" + "`i` and `n` must be integers.\n" + 'e.g. "13,6"' + ) + ) from err + return isr[start:end].lstrip("0") + + def parse_transaction_details(self, ns, node, transaction): + """Put ESR in label and add aditional information to label + if no esr is available + """ + super().parse_transaction_details(ns, node, transaction) + # put the esr in the label. odoo reconciles based on the label, + # if there is no esr it tries to use the information textfield + + isr_number = node.xpath( + "./ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref", namespaces={"ns": ns} + ) + if len(isr_number): + transaction["payment_ref"] = isr_number[0].text + partner_ref = self._get_partner_ref(isr_number[0].text) + if partner_ref: + transaction["partner_ref"] = partner_ref + else: + xpath_exprs = [ + "./ns:RmtInf/ns:Ustrd|./ns:RtrInf/ns:AddtlInf", + "./ns:AddtlNtryInf", + "/ns:Refs/ns:InstrId", + ] + payment_ref = transaction["payment_ref"] + for xpath_expr in xpath_exprs: + found_node = node.xpath(xpath_expr, namespaces={"ns": ns}) + if found_node: + payment_ref = found_node[0].text + break + trans_id_node = ( + node.getparent() + .getparent() + .xpath("./ns:AcctSvcrRef", namespaces={"ns": ns}) + ) + if trans_id_node: + payment_ref = "{} ({})".format(payment_ref, trans_id_node[0].text) + if payment_ref: + transaction["payment_ref"] = payment_ref + # End add esr to the label. + + # add transaction id to ref + self.add_value_from_node( + ns, + node, + [ + "./../../ns:AcctSvcrRef", + "./ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref", + "./ns:Refs/ns:EndToEndId", + ], + transaction, + "ref", + ) + return True diff --git a/account_statement_import_camt54/readme/CONTRIBUTORS.rst b/account_statement_import_camt54/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..0cf04074 --- /dev/null +++ b/account_statement_import_camt54/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Yannick Vaucher +* Timon Tschanz diff --git a/account_statement_import_camt54/readme/CREDITS.rst b/account_statement_import_camt54/readme/CREDITS.rst new file mode 100644 index 00000000..5ee91fa4 --- /dev/null +++ b/account_statement_import_camt54/readme/CREDITS.rst @@ -0,0 +1 @@ +* Digital4efficiency.ch diff --git a/account_statement_import_camt54/readme/DESCRIPTION.rst b/account_statement_import_camt54/readme/DESCRIPTION.rst new file mode 100644 index 00000000..4b97b805 --- /dev/null +++ b/account_statement_import_camt54/readme/DESCRIPTION.rst @@ -0,0 +1,22 @@ + This module allows you to import CAMT.054 file (details of customers payments batch) into a dedicated journal taking care of the start/end balance and the remittance reference number. + +Customer invoices will be reconciled/Paid. Payment entries will be posted into an internal transfer account (that you have to create with a type current asset and set on the journal) + +After this first step, import normally your CAMT.053 (full bank statement) into the bank journal. You will be able to clear the internal transfer account to end up the accounting flow. + +Optionally we can activate add generation of additional line in bank statement which will balance your bank statement total to 0. +This line can be consolidated later with different account. +To enable option of final statement line you need properly set flag on Account Journal +Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration + + +Switzerland localisation +------------------------ + +For ISR containing a partner reference, uses the config parameter key `isr_partner_ref`. +Doing so will fill the partners on bank statement lines and speed up the matches in the reconciliation process. + +Value to set in `isr_partner_ref` defines the position of the partner reference inside the ISR. +The format is `i[,n]` +For instance `13,6` to start on position 13 with a 6 digit long reference. +`n` is optional and it's default value is `6`. diff --git a/account_statement_import_camt54/static/description/icon.png b/account_statement_import_camt54/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_statement_import_camt54/static/description/icon.png differ diff --git a/account_statement_import_camt54/static/description/index.html b/account_statement_import_camt54/static/description/index.html new file mode 100644 index 00000000..aebd4a1a --- /dev/null +++ b/account_statement_import_camt54/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Bank Account Camt54 Import + + + +
+

Bank Account Camt54 Import

+ + +

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

+
+This module allows you to import CAMT.054 file (details of customers payments batch) into a dedicated journal taking care of the start/end balance and the remittance reference number.
+

Customer invoices will be reconciled/Paid. Payment entries will be posted into an internal transfer account (that you have to create with a type current asset and set on the journal)

+

After this first step, import normally your CAMT.053 (full bank statement) into the bank journal. You will be able to clear the internal transfer account to end up the accounting flow.

+

Optionally we can activate add generation of additional line in bank statement which will balance your bank statement total to 0. +This line can be consolidated later with different account. +To enable option of final statement line you need properly set flag on Account Journal +Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration

+
+

Switzerland localisation

+

For ISR containing a partner reference, uses the config parameter key isr_partner_ref. +Doing so will fill the partners on bank statement lines and speed up the matches in the reconciliation process.

+

Value to set in isr_partner_ref defines the position of the partner reference inside the ISR. +The format is i[,n] +For instance 13,6 to start on position 13 with a 6 digit long reference. +n is optional and it’s default value is 6.

+

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

+
    +
  • camptocamp
  • +
+
+ +
+

Other credits

+
    +
  • Digital4efficiency.ch
  • +
+
+
+

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_camt54/tests/__init__.py b/account_statement_import_camt54/tests/__init__.py new file mode 100644 index 00000000..002dfdba --- /dev/null +++ b/account_statement_import_camt54/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_get_partner_ref +from . import test_statement diff --git a/account_statement_import_camt54/tests/test_get_partner_ref.py b/account_statement_import_camt54/tests/test_get_partner_ref.py new file mode 100644 index 00000000..4e8f4b13 --- /dev/null +++ b/account_statement_import_camt54/tests/test_get_partner_ref.py @@ -0,0 +1,66 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.exceptions import UserError +from odoo.tests import common + + +class TestGetPartnerRef(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Parser = cls.env["account.statement.import.camt.parser"] + cls.ICP = cls.env["ir.config_parameter"] + + def test_no_ICP(self): + """Test no partner ref is read if param is not set""" + ref = "11 11111 11111 11111 11111 11111".replace(" ", "") + partner_ref = self.Parser._get_partner_ref(ref) + self.assertFalse(partner_ref) + + def test_ICP_empty(self): + self.ICP.set_param("isr_partner_ref", "") + ref = "11 11111 11111 11111 11111 11111".replace(" ", "") + partner_ref = self.Parser._get_partner_ref(ref) + self.assertFalse(partner_ref) + + def test_ICP_no_len(self): + """Test a default len of 6 is set if not provided""" + self.ICP.set_param("isr_partner_ref", "12") + ref = "11 11111 11112 34567 11111 11111".replace(" ", "") + partner_ref = self.Parser._get_partner_ref(ref) + self.assertEqual(partner_ref, "234567") + + def test_ICP_full(self): + """Test full format of partner ref definition""" + self.ICP.set_param("isr_partner_ref", "12,6") + ref = "11 11111 11112 34567 11111 11111".replace(" ", "") + partner_ref = self.Parser._get_partner_ref(ref) + self.assertEqual(partner_ref, "234567") + + def test_zero_stripped(self): + """Test full format of partner ref definition""" + self.ICP.set_param("isr_partner_ref", "12,6") + ref = "11 11111 11110 00560 11111 11111".replace(" ", "") + partner_ref = self.Parser._get_partner_ref(ref) + self.assertEqual(partner_ref, "560") + + def test_bad_ICP(self): + """Test ir config parameter validation""" + self.ICP.set_param("isr_partner_ref", "") + ref = "11 11111 11111 11111 11111 11111".replace(" ", "") + + self.ICP.set_param("isr_partner_ref", "A") + with self.assertRaises(UserError): + self.Parser._get_partner_ref(ref) + + self.ICP.set_param("isr_partner_ref", "A,B") + with self.assertRaises(UserError): + self.Parser._get_partner_ref(ref) + + self.ICP.set_param("isr_partner_ref", "1,X") + with self.assertRaises(UserError): + self.Parser._get_partner_ref(ref) + + self.ICP.set_param("isr_partner_ref", "A,8") + with self.assertRaises(UserError): + self.Parser._get_partner_ref(ref) diff --git a/account_statement_import_camt54/tests/test_statement.py b/account_statement_import_camt54/tests/test_statement.py new file mode 100644 index 00000000..b1db17d9 --- /dev/null +++ b/account_statement_import_camt54/tests/test_statement.py @@ -0,0 +1,68 @@ +# Copyright 2020 Camptocamp SA +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import base64 + +from odoo.modules.module import get_module_resource +from odoo.tests.common import TransactionCase + + +class TestGenerateBankStatement(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + eur = cls.env.ref("base.EUR") + eur.write({"active": True}) + bank = cls.env["res.partner.bank"].create( + { + "acc_number": "NL77ABNA0574908765", + "partner_id": cls.env.ref("base.main_partner").id, + "company_id": cls.env.ref("base.main_company").id, + "bank_id": cls.env.ref("base.res_bank_1").id, + } + ) + cls.env["res.partner.bank"].create( + { + "acc_number": "NL46ABNA0499998748", + "partner_id": cls.env.ref("base.main_partner").id, + "company_id": cls.env.ref("base.main_company").id, + "bank_id": cls.env.ref("base.res_bank_1").id, + } + ) + cls.journal = cls.env["account.journal"].create( + { + "name": "Bank Journal - (test camt)", + "code": "TBNKCAMT", + "type": "bank", + "bank_account_id": bank.id, + "currency_id": eur.id, + } + ) + + def _load_statement(self): + testfile = get_module_resource( + "account_statement_import_camt", "test_files", "test-camt053" + ) + with open(testfile, "rb") as datafile: + camt_file = base64.b64encode(datafile.read()) + self.env["account.statement.import"].create( + { + "statement_filename": "test import", + "statement_file": camt_file, + } + ).import_file_button() + bank_st_record = self.env["account.bank.statement"].search( + [("name", "=", "1234Test/1")], limit=1 + ) + statement_lines = bank_st_record.line_ids + return statement_lines + + def test_statement_import(self): + self.journal.transfer_line = True + lines = self._load_statement() + self.assertEqual(len(lines), 5) + self.assertAlmostEqual(sum(lines.mapped("amount")), 0) + self.journal.transfer_line = False + lines = self._load_statement() + self.assertEqual(len(lines), 4) + self.assertAlmostEqual(sum(lines.mapped("amount")), -12.99) diff --git a/setup/account_statement_import_camt54/odoo/addons/account_statement_import_camt54 b/setup/account_statement_import_camt54/odoo/addons/account_statement_import_camt54 new file mode 120000 index 00000000..73b6643f --- /dev/null +++ b/setup/account_statement_import_camt54/odoo/addons/account_statement_import_camt54 @@ -0,0 +1 @@ +../../../../account_statement_import_camt54 \ No newline at end of file diff --git a/setup/account_statement_import_camt54/setup.py b/setup/account_statement_import_camt54/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_statement_import_camt54/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)