diff --git a/account_ebics_oca_statement_import/README.rst b/account_ebics_oca_statement_import/README.rst new file mode 100644 index 0000000..ad87eca --- /dev/null +++ b/account_ebics_oca_statement_import/README.rst @@ -0,0 +1,17 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png + :target: https://www.gnu.org/licenses/lgpl + :alt: License: LGPL-3 + +========================================================== +Deploy account_ebics module with OCA Bank Statement Import +========================================================== + +This module makes it possible to use the OCA account_statement_import wizard +in combination with 'account_ebics'. + +This module will be installed automatically when following modules are activated +on your odoo database : + +- account_ebics +- account_statement_import_file + diff --git a/account_ebics_oca_statement_import/__init__.py b/account_ebics_oca_statement_import/__init__.py new file mode 100644 index 0000000..5cb1c49 --- /dev/null +++ b/account_ebics_oca_statement_import/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/account_ebics_oca_statement_import/__manifest__.py b/account_ebics_oca_statement_import/__manifest__.py new file mode 100644 index 0000000..d305694 --- /dev/null +++ b/account_ebics_oca_statement_import/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2020-2024 Noviat. +# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "account_ebics with OCA Bank Statement Imoort", + "summary": "Use OCA Bank Statement Import with account_ebics", + "version": "17.0.1.0.0", + "author": "Noviat", + "website": "https://www.noviat.com", + "category": "Hidden", + "license": "LGPL-3", + "depends": [ + "account_ebics", + "account_statement_import_file", + ], + "installable": True, + "auto_install": True, + "images": ["static/description/cover.png"], +} diff --git a/account_ebics_oca_statement_import/pyproject.toml b/account_ebics_oca_statement_import/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/account_ebics_oca_statement_import/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_ebics_oca_statement_import/static/description/cover.png b/account_ebics_oca_statement_import/static/description/cover.png new file mode 100644 index 0000000..1ce051a Binary files /dev/null and b/account_ebics_oca_statement_import/static/description/cover.png differ diff --git a/account_ebics_oca_statement_import/static/description/icon.png b/account_ebics_oca_statement_import/static/description/icon.png new file mode 100644 index 0000000..889d129 Binary files /dev/null and b/account_ebics_oca_statement_import/static/description/icon.png differ diff --git a/account_ebics_oca_statement_import/wizards/__init__.py b/account_ebics_oca_statement_import/wizards/__init__.py new file mode 100644 index 0000000..ae69bca --- /dev/null +++ b/account_ebics_oca_statement_import/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_statement_import diff --git a/account_ebics_oca_statement_import/wizards/account_statement_import.py b/account_ebics_oca_statement_import/wizards/account_statement_import.py new file mode 100644 index 0000000..0258b78 --- /dev/null +++ b/account_ebics_oca_statement_import/wizards/account_statement_import.py @@ -0,0 +1,89 @@ +# Copyright 2009-2024 Noviat. +# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). + +import logging +from datetime import date, datetime + +from odoo import _, models + +_logger = logging.getLogger(__name__) + + +class AccountStatementImport(models.TransientModel): + _inherit = "account.statement.import" + + def _check_parsed_data(self, stmts_vals): + """Basic and structural verifications""" + if self.env.context.get("active_model") == "ebics.file": + message = False + if len(stmts_vals) == 0: + message = _("This file doesn't contain any statement.") + if not message: + no_st_line = True + for vals in stmts_vals: + if vals["transactions"] and len(vals["transactions"]) > 0: + no_st_line = False + break + if no_st_line: + message = _("This file doesn't contain any transaction.") + if message: + log_msg = ( + _("Error detected while processing and EBICS File") + + ":\n" + + message + ) + _logger.warning(log_msg) + return + return super()._check_parsed_data(stmts_vals) + + def _create_bank_statements(self, stmts_vals, result): + """ + Return error message to ebics.file when handling empty camt. + + Remarks/TODO: + We could add more info to the message (e.g. date, balance, ...) + and write this to the ebics.file, note field. + We could also create empty bank statement (in state done) to clearly + show days without transactions via the bank statement list view. + """ + if self.env.context.get("active_model") != "ebics.file": + return super()._create_bank_statements(stmts_vals, result) + else: + messages = [] + transactions = False + for st_vals in stmts_vals: + statement_ids = result["statement_ids"][:] + self._set_statement_name(st_vals) + if st_vals.get("transactions"): + transactions = True + super()._create_bank_statements([st_vals], result) + if result["statement_ids"] == statement_ids: + # no statement has been created, this is the case + # when all transactions have been imported already + if isinstance(st_vals["date"], date) or isinstance( + st_vals["date"], datetime + ): + st_date = st_vals["date"].strftime("%Y-%m-%d") + else: + st_date = st_vals["date"] + messages.append( + _( + "Statement %(st_name)s dated %(date)s " + "has already been imported.", + st_name=st_vals["name"], + date=st_date, + ) + ) + + if not transactions: + messages.append(_("This file doesn't contain any transaction.")) + if messages: + result["notifications"].append( + {"type": "warning", "message": "\n".join(messages)} + ) + return + + def _set_statement_name(self, st_vals): + """ + Inherit this method to set your own statement naming policy. + """