From e58b277652aeba989d5f666d38242c685cc43c19 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Thu, 27 Oct 2022 23:48:16 +0200 Subject: [PATCH] [IMP] account_ebics: pre-commit --- .copier-answers.yml | 2 +- .pre-commit-config.yaml | 2 +- account_ebics/__manifest__.py | 4 +- account_ebics/data/ebics_file_format.xml | 310 +++++++++--------- .../models/account_bank_statement.py | 2 +- account_ebics/models/ebics_config.py | 4 +- account_ebics/models/ebics_file.py | 37 ++- account_ebics/models/ebics_file_format.py | 4 +- account_ebics/models/ebics_userid.py | 43 ++- account_ebics/views/ebics_config_views.xml | 2 +- .../views/ebics_file_format_views.xml | 2 +- account_ebics/views/ebics_file_views.xml | 4 +- account_ebics/views/ebics_userid_views.xml | 2 +- .../wizards/ebics_change_passphrase.py | 6 +- account_ebics/wizards/ebics_xfer.py | 35 +- 15 files changed, 233 insertions(+), 226 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index ff65852..54333b0 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -12,6 +12,6 @@ rebel_module_groups: [] repo_description: 'TODO: add repo description.' repo_name: account_ebics repo_slug: account_ebics -repo_website: https://github.com/Noviat/account_ebics +repo_website: https://www.noviat.com travis_apt_packages: [] travis_apt_sources: [] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad32b2d..6113cb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: # update the NOT INSTALLABLE ADDONS section above - id: oca-update-pre-commit-excluded-addons - id: oca-fix-manifest-website - args: ["https://github.com/Noviat/account_ebics"] + args: ["https://www.noviat.com"] - repo: https://github.com/myint/autoflake rev: v1.4 hooks: diff --git a/account_ebics/__manifest__.py b/account_ebics/__manifest__.py index 1f8ab33..101b6a0 100644 --- a/account_ebics/__manifest__.py +++ b/account_ebics/__manifest__.py @@ -3,10 +3,10 @@ { "name": "EBICS banking protocol", - "version": "14.0.1.0.5", + "version": "15.0.1.0.0", "license": "LGPL-3", "author": "Noviat", - "website": "https://github.com/Noviat/account_ebics", + "website": "https://www.noviat.com", "category": "Accounting & Finance", "depends": ["account"], "data": [ diff --git a/account_ebics/data/ebics_file_format.xml b/account_ebics/data/ebics_file_format.xml index 42119b9..e1baaad 100644 --- a/account_ebics/data/ebics_file_format.xml +++ b/account_ebics/data/ebics_file_format.xml @@ -1,180 +1,174 @@ - - + - + - - camt.052 - down - C52 - camt.052 - bank to customer account report in format camt.052 - c52.xml - + + camt.052 + down + C52 + camt.052 + bank to customer account report in format camt.052 + c52.xml + - - camt.052 - down - Z52 - camt.052 - bank to customer account report in format camt.052 - c52.xml - + + camt.052 + down + Z52 + camt.052 + bank to customer account report in format camt.052 + c52.xml + - - camt.053 - down - C53 - camt.053 - Bank to customer statement report in format camt.053 - c53.xml - + + camt.053 + down + C53 + camt.053 + Bank to customer statement report in format camt.053 + c53.xml + - - camt.053 - down - Z53 - camt.053 - Bank to customer statement report in format camt.053 - c53.xml - + + camt.053 + down + Z53 + camt.053 + Bank to customer statement report in format camt.053 + c53.xml + - - camt.054 - down - C54 - camt.054 - Bank to customer debit credit notification in format camt.054 - c52.xml - + + camt.054 + down + C54 + camt.054 + Bank to customer debit credit notification in format camt.054 + c52.xml + - - camt.054 - down - Z54 - camt.054 - Bank to customer debit credit notification in format camt.054 - c52.xml - + + camt.054 + down + Z54 + camt.054 + Bank to customer debit credit notification in format camt.054 + c52.xml + - - camt.xxx.cfonb120.stm - down - FDL - cfonb120 - Bank to customer statement report in format cfonb120 - cfonb120.dat - + + camt.xxx.cfonb120.stm + down + FDL + cfonb120 + Bank to customer statement report in format cfonb120 + cfonb120.dat + - - pain.002 - down - CDZ - Payment status report for direct debit in format pain.002 - psr.xml - + + pain.002 + down + CDZ + Payment status report for direct debit in format pain.002 + psr.xml + - - pain.002 - down - Z01 - pain.002 - Payment status report for direct debit in format pain.002 - psr.xml - + + pain.002 + down + Z01 + pain.002 + Payment status report for direct debit in format pain.002 + psr.xml + - + - - pain.xxx.cfonb160.dco - up - FUL - Remises de LCR - txt - + + pain.xxx.cfonb160.dco + up + FUL + Remises de LCR + txt + - - pain.001.001.03 - up - CCT - Payment Order in format pain.001.001.03 - xml - + + pain.001.001.03 + up + CCT + Payment Order in format pain.001.001.03 + xml + - - pain.001.001.03 - up - XE2 - Payment Order in format pain.001.001.03 - xml - + + pain.001.001.03 + up + XE2 + Payment Order in format pain.001.001.03 + xml + - - pain.008.001.02.sdd - up - CDD - Sepa Core Direct Debit Order in format pain.008.001.02 - xml - + + pain.008.001.02.sdd + up + CDD + Sepa Core Direct Debit Order in format pain.008.001.02 + xml + - - pain.008.001.02.sdd - up - XE3 - Sepa Core Direct Debit Order in format pain.008.001.02 - xml - + + pain.008.001.02.sdd + up + XE3 + Sepa Core Direct Debit Order in format pain.008.001.02 + xml + - - pain.008.001.02.sbb - up - CDB - Sepa Direct Debit (B2B) Order in format pain.008.001.02 - xml - + + pain.008.001.02.sbb + up + CDB + Sepa Direct Debit (B2B) Order in format pain.008.001.02 + xml + - - pain.008.001.02.sbb - up - XE4 - Sepa Direct Debit (B2B) Order in format pain.008.001.02 - xml - + + pain.008.001.02.sbb + up + XE4 + Sepa Direct Debit (B2B) Order in format pain.008.001.02 + xml + - - pain.001.001.02.sct - up - FUL - Payment Order in format pain.001.001.02 - xml - + + pain.001.001.02.sct + up + FUL + Payment Order in format pain.001.001.02 + xml + - diff --git a/account_ebics/models/account_bank_statement.py b/account_ebics/models/account_bank_statement.py index e1e1c2b..6b6540f 100644 --- a/account_ebics/models/account_bank_statement.py +++ b/account_ebics/models/account_bank_statement.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2022 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). from odoo import fields, models diff --git a/account_ebics/models/ebics_config.py b/account_ebics/models/ebics_config.py index 1dcb4fb..23826ce 100644 --- a/account_ebics/models/ebics_config.py +++ b/account_ebics/models/ebics_config.py @@ -22,7 +22,6 @@ class EbicsConfig(models.Model): _order = "name" name = fields.Char( - string="Name", readonly=True, states={"draft": [("readonly", False)]}, required=True, @@ -131,7 +130,6 @@ class EbicsConfig(models.Model): ) state = fields.Selection( [("draft", "Draft"), ("confirm", "Confirmed")], - string="State", default="draft", required=True, readonly=True, @@ -144,7 +142,7 @@ class EbicsConfig(models.Model): "\nThis number should match the following pattern : " "[A-Z]{1}[A-Z0-9]{3}", ) - active = fields.Boolean(string="Active", default=True) + active = fields.Boolean(default=True) company_ids = fields.Many2many( comodel_name="res.company", string="Companies", diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index 7e5b390..eea6539 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -46,7 +46,6 @@ class EbicsFile(models.Model): ) state = fields.Selection( [("draft", "Draft"), ("done", "Done")], - string="State", default="draft", required=True, readonly=True, @@ -93,8 +92,7 @@ class EbicsFile(models.Model): def process(self): self.ensure_one() - ctx = dict(self.env.context, allowed_company_ids=self.env.user.company_ids.ids) - self = self.with_context(ctx) + self = self.with_context(allowed_company_ids=self.env.user.company_ids.ids) self.note_process = "" ff_methods = self._file_format_methods() ff = self.format_id.download_process_method @@ -159,11 +157,12 @@ class EbicsFile(models.Model): if raise_if_not_found: raise UserError( _( - "The module to process the '%s' format is not installed " + "The module to process the '%(ebics_format)s' format is not installed " "on your system. " - "\nPlease install module '%s'" + "\nPlease install module '%(module)s'", + ebics_format=self.format_id.name, + module=module, ) - % (self.format_id.name, module) ) return False return True @@ -288,9 +287,12 @@ class EbicsFile(models.Model): "notifications": [], }, } - wiz_ctx = dict(self.env.context, active_model="ebics.file") for i, wiz_vals in enumerate(wiz_vals_list, start=1): - wiz = self.env[wiz_model].with_context(wiz_ctx).create(wiz_vals) + wiz = ( + self.env[wiz_model] + .with_context(active_model="ebics.file") + .create(wiz_vals) + ) res = wiz.import_file_button() ctx = res.get("context") if res.get("res_model") == "account.bank.statement.import.journal.creation": @@ -360,11 +362,12 @@ class EbicsFile(models.Model): if not found: raise UserError( _( - "The module to process the '%s' format is not installed " - "on your system. " - "\nPlease install one of the following modules: \n%s." + "The module to process the '%(ebics_format)s' format is " + "not installed on your system. " + "\nPlease install one of the following modules: \n%(modules)s.", + ebics_format=self.format_id.name, + modules=", ".join([x[1] for x in modules]), ) - % (self.format_id.name, ", ".join([x[1] for x in modules])) ) if _src == "oca": self._process_camt053_oca() @@ -386,8 +389,9 @@ class EbicsFile(models.Model): "notifications": [], }, } - wiz_ctx = dict(self.env.context, active_model="ebics.file") - wiz = self.env[wiz_model].with_context(wiz_ctx).create(wiz_vals) + wiz = ( + self.env[wiz_model].with_context(active_model="ebics.file").create(wiz_vals) + ) res = wiz.import_file_button() ctx = res.get("context") if res.get("res_model") == "account.bank.statement.import.journal.creation": @@ -418,8 +422,9 @@ class EbicsFile(models.Model): ) ] } - ctx = dict(self.env.context, active_model="ebics.file") - wiz = self.env[wiz_model].with_context(ctx).create(wiz_vals) + wiz = ( + self.env[wiz_model].with_context(active_model="ebics.file").create(wiz_vals) + ) res = wiz.import_file() if res.get("res_model") == "account.bank.statement.import.journal.creation": if res.get("context"): diff --git a/account_ebics/models/ebics_file_format.py b/account_ebics/models/ebics_file_format.py index 8dee0a9..ffeb0f0 100644 --- a/account_ebics/models/ebics_file_format.py +++ b/account_ebics/models/ebics_file_format.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2022 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). from odoo import api, fields, models @@ -22,7 +22,6 @@ class EbicsFileFormat(models.Model): selection=[("down", "Download"), ("up", "Upload")], required=True ) order_type = fields.Char( - string="Order Type", required=True, help="E.g. C53 (check your EBICS contract).\n" "For most banks in France you should use the " @@ -40,7 +39,6 @@ class EbicsFileFormat(models.Model): # move signature_class parameter so that it can be set per EBICS config signature_class = fields.Selection( selection=[("E", "Single signature"), ("T", "Transport signature")], - string="Signature Class", help="Please doublecheck the security of your Odoo " "ERP system when using class 'E' to prevent unauthorised " "users to make supplier payments." diff --git a/account_ebics/models/ebics_userid.py b/account_ebics/models/ebics_userid.py index f7fc99f..3c27bd0 100644 --- a/account_ebics/models/ebics_userid.py +++ b/account_ebics/models/ebics_userid.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2022 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). import base64 @@ -75,7 +75,6 @@ class EbicsUserID(models.Model): # Classes A and B are not yet supported. signature_class = fields.Selection( selection=[("E", "Single signature"), ("T", "Transport signature")], - string="Signature Class", required=True, default="T", readonly=True, @@ -157,12 +156,11 @@ class EbicsUserID(models.Model): ("to_verify", "Verification"), ("active_keys", "Active Keys"), ], - string="State", default="draft", required=True, readonly=True, ) - active = fields.Boolean(string="Active", default=True) + active = fields.Boolean(default=True) company_ids = fields.Many2many( comodel_name="res.company", string="Companies", @@ -243,11 +241,11 @@ class EbicsUserID(models.Model): partnerid=self.ebics_config_id.ebics_partner, userid=self.name, ) - except Exception: + except Exception as err: exctype, value = exc_info()[:2] error = _("EBICS Initialisation Error:") error += "\n" + str(exctype) + "\n" + str(value) - raise UserError(error) + raise UserError(error) from err self.ebics_config_id._check_ebics_keys() if not os.path.isfile(self.ebics_keys_fn): @@ -265,11 +263,11 @@ class EbicsUserID(models.Model): keyversion=self.ebics_config_id.ebics_key_version, bitlength=self.ebics_config_id.ebics_key_bitlength, ) - except Exception: + except Exception as err: exctype, value = exc_info()[:2] error = _("EBICS Initialisation Error:") error += "\n" + str(exctype) + "\n" + str(value) - raise UserError(error) + raise UserError(error) from err if self.swift_3skey and not self.ebics_key_x509: raise UserError( @@ -314,7 +312,7 @@ class EbicsUserID(models.Model): _logger.info("%s, EBICS INI command, OrderID=%s", self._name, OrderID) if ebics_version == "H003": self.ebics_config_id._update_order_number(OrderID) - except URLError: + except URLError as err: exctype, value = exc_info()[:2] tb = "".join(format_exception(*exc_info())) _logger.error( @@ -323,21 +321,22 @@ class EbicsUserID(models.Model): tb, ) raise UserError( - _("urlopen error:\n url '%s' - %s") - % (self.ebics_config_id.ebics_url, str(value)) - ) - except EbicsFunctionalError: + _("urlopen error:\n url '%(url)s' - %(val)s"), + url=self.ebics_config_id.ebics_url, + val=str(value), + ) from err + except EbicsFunctionalError as err: e = exc_info() error = _("EBICS Functional Error:") error += "\n" error += "{} (code: {})".format(e[1].message, e[1].code) - raise UserError(error) - except EbicsTechnicalError: + raise UserError(error) from err + except EbicsTechnicalError as err: e = exc_info() error = _("EBICS Technical Error:") error += "\n" error += "{} (code: {})".format(e[1].message, e[1].code) - raise UserError(error) + raise UserError(error) from err # Send the public authentication and encryption keys to the bank. if ebics_version == "H003": @@ -411,25 +410,25 @@ class EbicsUserID(models.Model): userid=self.name, ) client = EbicsClient(bank, user, version=self.ebics_config_id.ebics_version) - except Exception: + except Exception as err: exctype, value = exc_info()[:2] error = _("EBICS Initialisation Error:") error += "\n" + str(exctype) + "\n" + str(value) - raise UserError(error) + raise UserError(error) from err try: public_bank_keys = client.HPB() - except EbicsFunctionalError: + except EbicsFunctionalError as err: e = exc_info() error = _("EBICS Functional Error:") error += "\n" error += "{} (code: {})".format(e[1].message, e[1].code) - raise UserError(error) - except Exception: + raise UserError(error) from err + except Exception as err: exctype, value = exc_info()[:2] error = _("EBICS Initialisation Error:") error += "\n" + str(exctype) + "\n" + str(value) - raise UserError(error) + raise UserError(error) from err public_bank_keys = public_bank_keys.encode() tmp_dir = os.path.normpath(self.ebics_config_id.ebics_files + "/tmp") diff --git a/account_ebics/views/ebics_config_views.xml b/account_ebics/views/ebics_config_views.xml index d407af5..d7b9aec 100644 --- a/account_ebics/views/ebics_config_views.xml +++ b/account_ebics/views/ebics_config_views.xml @@ -5,7 +5,7 @@ ebics.config.tree ebics.config - + diff --git a/account_ebics/views/ebics_file_format_views.xml b/account_ebics/views/ebics_file_format_views.xml index 03dd598..1402ac2 100644 --- a/account_ebics/views/ebics_file_format_views.xml +++ b/account_ebics/views/ebics_file_format_views.xml @@ -5,7 +5,7 @@ ebics.file.format.tree ebics.file.format - + diff --git a/account_ebics/views/ebics_file_views.xml b/account_ebics/views/ebics_file_views.xml index 5961602..f64d4bb 100644 --- a/account_ebics/views/ebics_file_views.xml +++ b/account_ebics/views/ebics_file_views.xml @@ -38,7 +38,7 @@ ebics.file.tree ebics.file - + @@ -169,7 +169,7 @@ ebics.file.tree ebics.file - + diff --git a/account_ebics/views/ebics_userid_views.xml b/account_ebics/views/ebics_userid_views.xml index 8626d68..cd22353 100644 --- a/account_ebics/views/ebics_userid_views.xml +++ b/account_ebics/views/ebics_userid_views.xml @@ -5,7 +5,7 @@ ebics.userid.tree ebics.userid - + diff --git a/account_ebics/wizards/ebics_change_passphrase.py b/account_ebics/wizards/ebics_change_passphrase.py index 1ac046c..3f3c3ee 100644 --- a/account_ebics/wizards/ebics_change_passphrase.py +++ b/account_ebics/wizards/ebics_change_passphrase.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2022 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). import logging @@ -43,8 +43,8 @@ class EbicsChangePassphrase(models.TransientModel): passphrase=self.ebics_userid_id.ebics_passphrase, ) keyring.change_passphrase(self.new_pass) - except ValueError as e: - raise UserError(str(e)) + except ValueError as err: + raise UserError(str(err)) from err self.ebics_userid.ebics_passphrase = self.new_pass self.note = "The EBICS Passphrase has been changed." diff --git a/account_ebics/wizards/ebics_xfer.py b/account_ebics/wizards/ebics_xfer.py index 5493056..73abbb4 100644 --- a/account_ebics/wizards/ebics_xfer.py +++ b/account_ebics/wizards/ebics_xfer.py @@ -86,7 +86,6 @@ class EbicsXfer(models.TransientModel): "and 'FDL' for download.", ) test_mode = fields.Boolean( - string="Test Mode", help="Select this option to test if the syntax of " "the upload file is correct." "\nThis option is only available for " @@ -222,8 +221,11 @@ class EbicsXfer(models.TransientModel): e = exc_info() self.note += "\n" self.note += _( - "EBICS Functional Error during download of File Format %s (%s):" - ) % (df.name, df.order_type) + "EBICS Functional Error during download of " + "File Format %(name)s (%(order_type)s):", + name=df.name, + order_type=df.order_type, + ) self.note += "\n" self.note += "{} (code: {})".format(e[1].message, e[1].code) except EbicsTechnicalError: @@ -231,8 +233,11 @@ class EbicsXfer(models.TransientModel): e = exc_info() self.note += "\n" self.note += _( - "EBICS Technical Error during download of File Format %s (%s):" - ) % (df.name, df.order_type) + "EBICS Technical Error during download of " + "File Format %(name)s (%(order_type)s):", + name=df.name, + order_type=df.order_type, + ) self.note += "\n" self.note += "{} (code: {})".format(e[1].message, e[1].code) except EbicsVerificationError: @@ -240,23 +245,31 @@ class EbicsXfer(models.TransientModel): self.note += "\n" self.note += _( "EBICS Verification Error during download of " - "File Format %s (%s):" - ) % (df.name, df.order_type) + "File Format %(name)s (%(order_type)s):", + name=df.name, + order_type=df.order_type, + ) self.note += "\n" self.note += _("The EBICS response could not be verified.") except UserError as e: self.note += "\n" self.note += _( - "Warning during download of File Format %s (%s):" - ) % (df.name, df.order_type) + "Warning during download of " + "File Format %(name)s (%(order_type)s):", + name=df.name, + order_type=df.order_type, + ) self.note += "\n" self.note += e.name except Exception: err_cnt += 1 self.note += "\n" self.note += _( - "Unknown Error during download of File Format %s (%s):" - ) % (df.name, df.order_type) + "Unknown Error during download of " + "File Format %(name)s (%(order_type)s):", + name=df.name, + order_type=df.order_type, + ) tb = "".join(format_exception(*exc_info())) self.note += "\n%s" % tb else: