mirror of
https://github.com/brain-tec/account_ebics.git
synced 2025-08-14 06:35:36 +00:00
[MIG] account_ebics: Migration to 18.0
This commit is contained in:
@@ -5,7 +5,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -132,7 +132,7 @@ class EbicsConfig(models.Model):
|
||||
def _check_ebics_key_bitlength(self):
|
||||
for cfg in self:
|
||||
if cfg.ebics_version == "H005" and cfg.ebics_key_bitlength < 2048:
|
||||
raise UserError(_("EBICS key bitlength must be >= 2048."))
|
||||
raise UserError(self.env._("EBICS key bitlength must be >= 2048."))
|
||||
|
||||
@api.constrains("order_number")
|
||||
def _check_order_number(self):
|
||||
@@ -148,7 +148,7 @@ class EbicsConfig(models.Model):
|
||||
ok = False
|
||||
if not ok:
|
||||
raise UserError(
|
||||
_( # pylint: disable=W8120
|
||||
self.env._( # pylint: disable=W8120
|
||||
"Order Number should comply with the following pattern:"
|
||||
"\n[A-Z]{1}[A-Z0-9]{3}"
|
||||
)
|
||||
@@ -178,7 +178,9 @@ class EbicsConfig(models.Model):
|
||||
def unlink(self):
|
||||
for ebics_config in self:
|
||||
if ebics_config.state == "active":
|
||||
raise UserError(_("You cannot remove active EBICS configurations."))
|
||||
raise UserError(
|
||||
self.env._("You cannot remove active EBICS configurations.")
|
||||
)
|
||||
return super().unlink()
|
||||
|
||||
def set_to_draft(self):
|
||||
@@ -211,7 +213,7 @@ class EbicsConfig(models.Model):
|
||||
dirname = self.ebics_keys or ""
|
||||
if not os.path.exists(dirname):
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"EBICS Keys Root Directory %s is not available."
|
||||
"\nPlease contact your system administrator."
|
||||
)
|
||||
|
@@ -9,7 +9,7 @@ from traceback import format_exception
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo import fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||
@@ -86,7 +86,9 @@ class EbicsFile(models.Model):
|
||||
ff_methods = self._file_format_methods()
|
||||
for ebics_file in self:
|
||||
if ebics_file.state == "done":
|
||||
raise UserError(_("You can only remove EBICS files in state 'Draft'."))
|
||||
raise UserError(
|
||||
self.env._("You can only remove EBICS files in state 'Draft'.")
|
||||
)
|
||||
# execute format specific actions
|
||||
ff = ebics_file.format_id.download_process_method
|
||||
if ff in ff_methods:
|
||||
@@ -167,7 +169,7 @@ class EbicsFile(models.Model):
|
||||
if not mod:
|
||||
if raise_if_not_found:
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"The module to process the '%(ebics_format)s' format is not "
|
||||
"installed on your system. "
|
||||
"\nPlease install module '%(module)s'",
|
||||
@@ -184,7 +186,7 @@ class EbicsFile(models.Model):
|
||||
)
|
||||
journal = self.env["account.journal"]
|
||||
if not currency:
|
||||
message = _("Currency %(cc)s not found.", cc=currency_code)
|
||||
message = self.env._("Currency %(cc)s not found.", cc=currency_code)
|
||||
res["notifications"].append({"type": "error", "message": message})
|
||||
return (currency, journal)
|
||||
|
||||
@@ -199,7 +201,7 @@ class EbicsFile(models.Model):
|
||||
]
|
||||
)
|
||||
if not journals:
|
||||
message = _(
|
||||
message = self.env._(
|
||||
"No financial journal found for Account Number %(nbr)s, "
|
||||
"Currency %(cc)s",
|
||||
nbr=acc_number,
|
||||
@@ -217,7 +219,7 @@ class EbicsFile(models.Model):
|
||||
break
|
||||
|
||||
if not journal:
|
||||
message = _(
|
||||
message = self.env._(
|
||||
"No financial journal found for Account Number %(nbr)s, "
|
||||
"Currency %(cc)s",
|
||||
nbr=acc_number,
|
||||
@@ -244,7 +246,7 @@ class EbicsFile(models.Model):
|
||||
notifications.append(
|
||||
{
|
||||
"type": "warning",
|
||||
"message": _("This file doesn't contain any transaction."),
|
||||
"message": self.env._("This file doesn't contain any transaction."),
|
||||
}
|
||||
)
|
||||
st_cnt = len(statements)
|
||||
@@ -265,28 +267,30 @@ class EbicsFile(models.Model):
|
||||
warning_cnt += 1
|
||||
warnings.append(notif + "\n")
|
||||
|
||||
self.note_process += _("Process file %(fn)s results:", fn=self.name)
|
||||
self.note_process += self.env._("Process file %(fn)s results:", fn=self.name)
|
||||
if error_cnt:
|
||||
self.note_process += "\n\n" + _("Errors") + ":\n"
|
||||
self.note_process += "\n\n" + self.env._("Errors") + ":\n"
|
||||
self.note_process += "\n".join(errors)
|
||||
self.note_process += "\n\n"
|
||||
self.note_process += _("Number of errors: %(nr)s", nr=error_cnt)
|
||||
self.note_process += self.env._("Number of errors: %(nr)s", nr=error_cnt)
|
||||
if warning_cnt:
|
||||
self.note_process += "\n\n" + _("Warnings") + ":\n"
|
||||
self.note_process += "\n\n" + self.env._("Warnings") + ":\n"
|
||||
self.note_process += "\n".join(warnings)
|
||||
self.note_process += "\n\n"
|
||||
self.note_process += _("Number of warnings: %(nr)s", nr=warning_cnt)
|
||||
self.note_process += self.env._(
|
||||
"Number of warnings: %(nr)s", nr=warning_cnt
|
||||
)
|
||||
self.note_process += "\n"
|
||||
if st_cnt:
|
||||
self.note_process += "\n\n"
|
||||
self.note_process += _(
|
||||
self.note_process += self.env._(
|
||||
"%(st_cnt)s bank statement%(sp)s been imported: ",
|
||||
st_cnt=st_cnt,
|
||||
sp=st_cnt == 1 and _(" has") or _("s have"),
|
||||
sp=st_cnt == 1 and self.env._(" has") or self.env._("s have"),
|
||||
)
|
||||
self.note_process += "\n"
|
||||
for statement in statements:
|
||||
self.note_process += "\n" + _(
|
||||
self.note_process += "\n" + self.env._(
|
||||
"Statement %(st)s dated %(date)s (Company: %(cpy)s)",
|
||||
st=statement.name,
|
||||
date=statement.date,
|
||||
@@ -300,7 +304,7 @@ class EbicsFile(models.Model):
|
||||
module = __name__.split("addons.")[1].split(".")[0]
|
||||
result_view = self.env.ref("%s.ebics_file_view_form_result" % module)
|
||||
return {
|
||||
"name": _("Import EBICS File"),
|
||||
"name": self.env._("Import EBICS File"),
|
||||
"res_id": self.id,
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
@@ -331,7 +335,7 @@ class EbicsFile(models.Model):
|
||||
]
|
||||
)
|
||||
if dup:
|
||||
message = _(
|
||||
message = self.env._(
|
||||
"Statement %(st_name)s dated %(date)s has already been imported.",
|
||||
st_name=statement.name,
|
||||
date=statement.date,
|
||||
@@ -369,7 +373,7 @@ class EbicsFile(models.Model):
|
||||
file_data = base64.b64decode(self.data)
|
||||
file_data.replace(b"\n", b"").replace(b"\r", b"")
|
||||
if len(file_data) % 120:
|
||||
message = _(
|
||||
message = self.env._(
|
||||
"Incorrect CFONB120 file:\n"
|
||||
"the file is not divisible in 120 char lines"
|
||||
)
|
||||
@@ -450,7 +454,7 @@ class EbicsFile(models.Model):
|
||||
break
|
||||
if not author:
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"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.",
|
||||
@@ -501,7 +505,7 @@ class EbicsFile(models.Model):
|
||||
except UserError as e:
|
||||
msg = "".join(e.args)
|
||||
msg += "\n"
|
||||
msg += _(
|
||||
msg += self.env._(
|
||||
"Statement for Account Number %(nr)s has not been processed.",
|
||||
nr=st_data["acc_number"],
|
||||
)
|
||||
@@ -555,7 +559,7 @@ class EbicsFile(models.Model):
|
||||
file_data = base64.b64decode(self.data)
|
||||
root = etree.fromstring(file_data, parser=etree.XMLParser(recover=True))
|
||||
if root is None:
|
||||
message = _("Invalid XML file.")
|
||||
message = self.env._("Invalid XML file.")
|
||||
res["notifications"].append({"type": "error", "message": message})
|
||||
ns = {k or "ns": v for k, v in root.nsmap.items()}
|
||||
camt_variant = ns["ns"].split("camt.")[1][:3]
|
||||
@@ -574,7 +578,7 @@ class EbicsFile(models.Model):
|
||||
)[0]
|
||||
)
|
||||
if not acc_number:
|
||||
message = _("No bank account number found.")
|
||||
message = self.env._("No bank account number found.")
|
||||
res["notifications"].append({"type": "error", "message": message})
|
||||
continue
|
||||
currency_code = stmt.xpath(
|
||||
@@ -626,7 +630,7 @@ class EbicsFile(models.Model):
|
||||
|
||||
def _process_undefined_format(self):
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"The current version of the 'account_ebics' module "
|
||||
"has no support to automatically process EBICS files "
|
||||
"with format %s."
|
||||
|
@@ -8,7 +8,7 @@ from sys import exc_info
|
||||
from traceback import format_exception
|
||||
from urllib.error import URLError
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -236,20 +236,26 @@ class EbicsUserID(models.Model):
|
||||
def _check_ebics_key_x509(self):
|
||||
for cfg in self:
|
||||
if cfg.ebics_version == "H005" and not cfg.ebics_key_x509:
|
||||
raise UserError(_("X.509 certificates must be used with EBICS 3.0."))
|
||||
raise UserError(
|
||||
self.env._("X.509 certificates must be used with EBICS 3.0.")
|
||||
)
|
||||
|
||||
@api.constrains("ebics_passphrase")
|
||||
def _check_ebics_passphrase(self):
|
||||
for rec in self:
|
||||
if rec.ebics_passphrase and len(rec.ebics_passphrase) < 8:
|
||||
raise UserError(_("The Passphrase must be at least 8 characters long"))
|
||||
raise UserError(
|
||||
self.env._("The Passphrase must be at least 8 characters long")
|
||||
)
|
||||
|
||||
@api.constrains("ebics_sig_passphrase")
|
||||
def _check_ebics_sig_passphrase(self):
|
||||
for rec in self:
|
||||
if rec.ebics_sig_passphrase and len(rec.ebics_sig_passphrase) < 8:
|
||||
raise UserError(
|
||||
_("The Signature Passphrase must be at least 8 characters long")
|
||||
self.env._(
|
||||
"The Signature Passphrase must be at least 8 characters long"
|
||||
)
|
||||
)
|
||||
|
||||
@api.onchange("ebics_version")
|
||||
@@ -280,7 +286,7 @@ class EbicsUserID(models.Model):
|
||||
# It will raise a ValueError on invalid passphrases
|
||||
keyring["#USER"]
|
||||
except ValueError as err: # noqa: F841
|
||||
raise UserError(_("Passphrase mismatch.")) # noqa: B904
|
||||
raise UserError(self.env._("Passphrase mismatch.")) # noqa: B904
|
||||
else:
|
||||
if self.state != "draft":
|
||||
self.ebics_passphrase = False
|
||||
@@ -302,7 +308,7 @@ class EbicsUserID(models.Model):
|
||||
self.ensure_one()
|
||||
if self.ebics_config_id.state != "draft":
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"Set the EBICS Configuation record to 'Draft' "
|
||||
"before starting the Key Renewal process."
|
||||
)
|
||||
@@ -317,14 +323,14 @@ class EbicsUserID(models.Model):
|
||||
self.ensure_one()
|
||||
if self.state != "draft":
|
||||
raise UserError(
|
||||
_("Set state to 'draft' before Bank Key (re)initialisation.")
|
||||
self.env._("Set state to 'draft' before Bank Key (re)initialisation.")
|
||||
)
|
||||
|
||||
if not self.ebics_passphrase:
|
||||
raise UserError(_("Set a passphrase."))
|
||||
raise UserError(self.env._("Set a passphrase."))
|
||||
|
||||
if self.swift_3skey and not self.swift_3skey_certificate:
|
||||
raise UserError(_("3SKey certificate missing."))
|
||||
raise UserError(self.env._("3SKey certificate missing."))
|
||||
|
||||
ebics_version = self.ebics_config_id.ebics_version
|
||||
try:
|
||||
@@ -347,7 +353,7 @@ class EbicsUserID(models.Model):
|
||||
)
|
||||
except Exception as err:
|
||||
exctype, value = exc_info()[:2]
|
||||
error = _("EBICS Initialisation Error:")
|
||||
error = self.env._("EBICS Initialisation Error:")
|
||||
error += "\n" + str(exctype) + "\n" + str(value)
|
||||
raise UserError(error) from err
|
||||
|
||||
@@ -369,13 +375,13 @@ class EbicsUserID(models.Model):
|
||||
)
|
||||
except Exception as err:
|
||||
exctype, value = exc_info()[:2]
|
||||
error = _("EBICS Initialisation Error:")
|
||||
error = self.env._("EBICS Initialisation Error:")
|
||||
error += "\n" + str(exctype) + "\n" + str(value)
|
||||
raise UserError(error) from err
|
||||
|
||||
if self.swift_3skey and not self.ebics_key_x509:
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"The current version of this module "
|
||||
"requires to X509 support when enabling 3SKey"
|
||||
)
|
||||
@@ -398,7 +404,7 @@ class EbicsUserID(models.Model):
|
||||
client = EbicsClient(bank, user, version=ebics_version)
|
||||
except RuntimeError as err:
|
||||
e = exc_info()
|
||||
error = _("EBICS Initialization Error:")
|
||||
error = self.env._("EBICS Initialization Error:")
|
||||
error += "\n"
|
||||
error += err.args[0]
|
||||
raise UserError(error) from err
|
||||
@@ -407,13 +413,15 @@ class EbicsUserID(models.Model):
|
||||
ebics_config_bank = self.ebics_config_id.journal_ids[0].bank_id
|
||||
if not ebics_config_bank:
|
||||
raise UserError(
|
||||
_("No bank defined for the financial journal " "of the EBICS Config")
|
||||
self.env._(
|
||||
"No bank defined for the financial journal " "of the EBICS Config"
|
||||
)
|
||||
)
|
||||
try:
|
||||
supported_versions = client.HEV()
|
||||
if supported_versions and ebics_version not in supported_versions:
|
||||
err_msg = _("EBICS version mismatch.") + "\n"
|
||||
err_msg += _("Versions supported by your bank:")
|
||||
err_msg = self.env._("EBICS version mismatch.") + "\n"
|
||||
err_msg += self.env._("Versions supported by your bank:")
|
||||
for k in supported_versions:
|
||||
err_msg += f"\n{k}: {supported_versions[k]} "
|
||||
raise UserError(err_msg)
|
||||
@@ -432,7 +440,7 @@ class EbicsUserID(models.Model):
|
||||
tb,
|
||||
)
|
||||
raise UserError(
|
||||
_(
|
||||
self.env._(
|
||||
"urlopen error:\n url '%(url)s' - %(val)s",
|
||||
url=self.ebics_config_id.ebics_url,
|
||||
val=str(value),
|
||||
@@ -440,13 +448,13 @@ class EbicsUserID(models.Model):
|
||||
) from err
|
||||
except EbicsFunctionalError as err:
|
||||
e = exc_info()
|
||||
error = _("EBICS Functional Error:")
|
||||
error = self.env._("EBICS Functional Error:")
|
||||
error += "\n"
|
||||
error += f"{e[1].message} (code: {e[1].code})"
|
||||
raise UserError(error) from err
|
||||
except EbicsTechnicalError as err:
|
||||
e = exc_info()
|
||||
error = _("EBICS Technical Error:")
|
||||
error = self.env._("EBICS Technical Error:")
|
||||
error += "\n"
|
||||
error += f"{e[1].message} (code: {e[1].code})"
|
||||
raise UserError(error) from err
|
||||
@@ -485,7 +493,7 @@ class EbicsUserID(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.state != "init":
|
||||
raise UserError(_("Set state to 'Initialisation'."))
|
||||
raise UserError(self.env._("Set state to 'Initialisation'."))
|
||||
vals = {"state": "get_bank_keys"}
|
||||
self._update_passphrase_vals(vals)
|
||||
return self.write(vals)
|
||||
@@ -499,7 +507,7 @@ class EbicsUserID(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.state != "get_bank_keys":
|
||||
raise UserError(_("Set state to 'Get Keys from Bank'."))
|
||||
raise UserError(self.env._("Set state to 'Get Keys from Bank'."))
|
||||
try:
|
||||
keyring = EbicsKeyRing(
|
||||
keys=self.ebics_keys_fn, passphrase=self.ebics_passphrase
|
||||
@@ -517,7 +525,7 @@ class EbicsUserID(models.Model):
|
||||
client = EbicsClient(bank, user, version=self.ebics_config_id.ebics_version)
|
||||
except Exception as err:
|
||||
exctype, value = exc_info()[:2]
|
||||
error = _("EBICS Initialisation Error:")
|
||||
error = self.env._("EBICS Initialisation Error:")
|
||||
error += "\n" + str(exctype) + "\n" + str(value)
|
||||
raise UserError(error) from err
|
||||
|
||||
@@ -525,13 +533,13 @@ class EbicsUserID(models.Model):
|
||||
public_bank_keys = client.HPB()
|
||||
except EbicsFunctionalError as err:
|
||||
e = exc_info()
|
||||
error = _("EBICS Functional Error:")
|
||||
error = self.env._("EBICS Functional Error:")
|
||||
error += "\n"
|
||||
error += f"{e[1].message} (code: {e[1].code})"
|
||||
raise UserError(error) from err
|
||||
except Exception as err:
|
||||
exctype, value = exc_info()[:2]
|
||||
error = _("EBICS Initialisation Error:")
|
||||
error = self.env._("EBICS Initialisation Error:")
|
||||
error += "\n" + str(exctype) + "\n" + str(value)
|
||||
raise UserError(error) from err
|
||||
|
||||
@@ -557,7 +565,7 @@ class EbicsUserID(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.state != "to_verify":
|
||||
raise UserError(_("Set state to 'Verification'."))
|
||||
raise UserError(self.env._("Set state to 'Verification'."))
|
||||
|
||||
keyring = EbicsKeyRing(
|
||||
keys=self.ebics_keys_fn, passphrase=self.ebics_passphrase
|
||||
@@ -578,7 +586,7 @@ class EbicsUserID(models.Model):
|
||||
module = __name__.split("addons.")[1].split(".")[0]
|
||||
view = self.env.ref("%s.ebics_change_passphrase_view_form" % module)
|
||||
return {
|
||||
"name": _("EBICS keys change passphrase"),
|
||||
"name": self.env._("EBICS keys change passphrase"),
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_model": "ebics.change.passphrase",
|
||||
|
Reference in New Issue
Block a user