From 296695f97a4d621cd243aa50a861a6c7226366d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Didderen?= Date: Tue, 27 Oct 2026 18:02:20 +0100 Subject: [PATCH] [IMP] addons-repo-template v9.2.1 --- .copier-answers.yml | 3 +- .github/workflows/check-version-bump.yml | 2 +- .github/workflows/pre-commit.yml | 2 +- .github/workflows/test.yml | 66 +++++----- .pre-commit-config.yaml | 14 +-- .pylintrc | 118 ------------------ .pylintrc-mandatory | 3 +- .ruff.toml | 34 +++++ account_ebics/__init__.py | 2 +- .../migrations/13.0.1.1/post-migration.py | 2 +- account_ebics/models/ebics_config.py | 7 +- account_ebics/models/ebics_file.py | 21 ++-- account_ebics/models/ebics_file_format.py | 2 +- account_ebics/models/ebics_userid.py | 18 ++- .../models/fintech_ebics_register.py | 5 +- .../wizards/ebics_change_passphrase.py | 3 +- account_ebics/wizards/ebics_xfer.py | 31 ++--- account_ebics_batch/models/ebics_batch_log.py | 10 +- .../__manifest__.py | 2 +- .../wizards/account_statement_import.py | 67 +++++----- .../models/account_payment_order.py | 67 +++++----- 21 files changed, 188 insertions(+), 291 deletions(-) delete mode 100644 .pylintrc diff --git a/.copier-answers.yml b/.copier-answers.yml index 0dad1bf..395641e 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,7 +1,8 @@ # Do NOT update manually; changes here will be overwritten by Copier -_commit: v8.0.2 +_commit: v9.1.0 _src_path: git@github.com:Noviat-CI/addons-repo-template.git ci_disable_autoinstall_modules: account_asset +community_excluded_modules: account_ebics_batch_payment,account_ebics_oe odoo_test_flavor: Both odoo_version: 18.0 org_slug: Noviat diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml index d31d3f5..3fb6ea3 100644 --- a/.github/workflows/check-version-bump.yml +++ b/.github/workflows/check-version-bump.yml @@ -24,6 +24,6 @@ jobs: - name: Add Noviat CI Tools to PATH run: | git clone https://github.com/Noviat-CI/noviat-ci-tools.git /opt/noviat-ci-tools - echo "/opt/noviat-ci-tools" >> $GITHUB_PATH + echo "/opt/noviat-ci-tools" >> "$GITHUB_PATH" - name: Check module version bump run: check_module_version_bump diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a58efe7..5c2ec71 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -23,7 +23,7 @@ jobs: cache: 'pip' cache-dependency-path: '.pre-commit-config.yaml' - name: Get python version - run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV" - uses: actions/cache@v6 with: path: ~/.cache/pre-commit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b13a7eb..d2601b1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,11 +20,11 @@ jobs: - uses: actions/checkout@v7 - run: | for reqfile in requirements.txt test-requirements.txt ; do - if [ -f ${reqfile} ] ; then + if [ -f "${reqfile}" ] ; then result=0 # reject non-comment lines that contain a / (i.e. URLs, relative paths) # unless they have a "# SKIP TEST" comment - grep "^[^#].*/" ${reqfile} | grep -v "# SKIP TEST" || result=$? + grep "^[^#].*/" "${reqfile}" | grep -v "# SKIP TEST" || result=$? if [ $result -eq 0 ] ; then echo "Unreleased dependencies found in ${reqfile}." exit 1 @@ -33,7 +33,11 @@ jobs: done test: runs-on: ubuntu-latest - container: ${{ matrix.container }} + container: + image: ${{ matrix.container }} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.PRIVATE_TOKEN }} name: ${{ matrix.name }} permissions: pull-requests: write @@ -42,12 +46,12 @@ jobs: fail-fast: false matrix: include: - - container: ghcr.io/oca/oca-ci/py3.10-odoo18.0:latest + - container: ghcr.io/noviat-ci/odoo-ci:18.0-stable name: test with Odoo Community odoo_enterprise : 0 exclude_modules : "account_asset" - exclude: "account_ebics_batch_payment,account_ebics_oe" - - container: ghcr.io/oca/oca-ci/py3.10-odoo18.0:latest + skip: "account_ebics_batch_payment,account_ebics_oe" + - container: ghcr.io/noviat-ci/odoo-ci:18.0-stable name: test with Odoo Enterprise odoo_enterprise : 1 exclude_modules : "account_asset" @@ -73,49 +77,43 @@ jobs: TOKEN: ${{ secrets.PRIVATE_TOKEN }} run: | git config --global http.https://github.com/.extraheader "AUTHORIZATION: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" - - name: Set pip constraints (pyOpenSSL / cryptography) + - name: Show the CI image age run: | - cat > /tmp/constraints.txt <<'EOF' - pyOpenSSL == 22.1.0 - cryptography == 38.0.4 - EOF - echo "PIP_CONSTRAINT=/tmp/constraints.txt" >> $GITHUB_ENV - - name: Upgrade pip in container - run: python -m pip install --upgrade pip - - name: Install Odoo upgrade util - run: python -m pip install git+https://github.com/odoo/upgrade-util@master - - name: Add Noviat CI Tools to PATH - run: | - git clone https://github.com/Noviat-CI/noviat-ci-tools.git /opt/noviat-ci-tools - echo "/opt/noviat-ci-tools" >> $GITHUB_PATH - - name: Clone Odoo Enterprise - if: ${{ matrix.odoo_enterprise == 1 }} - run : | - git clone https://github.com/odoo/enterprise.git --depth 1 -b 18.0 /opt/enterprise + age=$(( ( $(date -u +%s) - $(date -u -d "$NOVIAT_CI_IMAGE_BUILD_DATE" +%s) ) / 86400 )) + echo "Image $NOVIAT_CI_ODOO_VERSION built $NOVIAT_CI_IMAGE_BUILD_DATE ($age days old)" | tee -a "$GITHUB_STEP_SUMMARY" - name: Clone Noviat Dependencies run: clone_oca_dependencies_by_noviat - name: Create addons path run: | - mkdir -p ${{ env.INSTALL_ADDONS_DIR }}/setup - find $(realpath $ADDONS_DIR) $(realpath ${{ env.ADDITIONAL_ADDONS_DIR }}) -name __manifest__.py -exec sh -c 'ln -s "$(dirname "$0")" "${{ env.INSTALL_ADDONS_DIR }}"' {} \; - find $(realpath $ADDONS_DIR) $(realpath ${{ env.ADDITIONAL_ADDONS_DIR }}) -iwholename '*/setup/*/setup.py' -exec sh -c 'ln -s "$(dirname "$0")" "${{ env.INSTALL_ADDONS_DIR }}/setup"' {} \; - if [ -n ${{ matrix.exclude}} ] + mkdir -p "$INSTALL_ADDONS_DIR/setup" + find "$(realpath "$ADDONS_DIR")" "$(realpath "$ADDITIONAL_ADDONS_DIR")" -name __manifest__.py -exec sh -c 'ln -s "$(dirname "$0")" "$1"' {} "$INSTALL_ADDONS_DIR" \; + find "$(realpath "$ADDONS_DIR")" "$(realpath "$ADDITIONAL_ADDONS_DIR")" -iwholename '*/setup/*/setup.py' -exec sh -c 'ln -s "$(dirname "$0")" "$1/setup"' {} "$INSTALL_ADDONS_DIR" \; + # EXCLUDE (from matrix.exclude) only exists with rebel module groups + if [ -n "${EXCLUDE:-}" ] then - remove_excluded_modules ${{ env.INSTALL_ADDONS_DIR }} ${{ matrix.exclude }} + remove_excluded_modules "$INSTALL_ADDONS_DIR" "$EXCLUDE" fi + - name: Skip addons + if: ${{ matrix.skip }} + env: + SKIPPED: ${{ matrix.skip }} + run: | + remove_excluded_modules "$INSTALL_ADDONS_DIR" "$SKIPPED" + echo "EXCLUDE=${EXCLUDE:+$EXCLUDE,}$SKIPPED" >> "$GITHUB_ENV" + echo "Not installed nor tested with Odoo Community: $SKIPPED" | tee -a "$GITHUB_STEP_SUMMARY" - name: Update addons path with enterprise if: ${{ matrix.odoo_enterprise == 1 }} run: | - echo "ADDONS_PATH=/opt/odoo/addons,/opt/enterprise,${{ env.INSTALL_ADDONS_DIR }}" >> $GITHUB_ENV + echo "ADDONS_PATH=/opt/odoo/addons,/opt/enterprise,${{ env.INSTALL_ADDONS_DIR }}" >> "$GITHUB_ENV" - name: Update addons path without enterprise if: ${{ matrix.odoo_enterprise == 0 }} run: | - echo "ADDONS_PATH=/opt/odoo/addons,${{ env.INSTALL_ADDONS_DIR }}" >> $GITHUB_ENV + echo "ADDONS_PATH=/opt/odoo/addons,${{ env.INSTALL_ADDONS_DIR }}" >> "$GITHUB_ENV" - name: Add addons to EXCLUDE PATH if: ${{ matrix.EXCLUDE_MODULES }} run: | - echo "server_wide_modules = web,module_change_auto_install" >> ${ODOO_RC} - echo "ODOO_MODULES_AUTO_INSTALL_DISABLED=${{ matrix.EXCLUDE_MODULES }}" >> $GITHUB_ENV + echo "server_wide_modules = web,module_change_auto_install" >> "${ODOO_RC}" + echo "ODOO_MODULES_AUTO_INSTALL_DISABLED=${{ matrix.EXCLUDE_MODULES }}" >> "$GITHUB_ENV" - name: Install addons and dependencies run: | (ADDONS_PATH=${ADDONS_PATH} ADDONS_DIR=${INSTALL_ADDONS_DIR} oca_install_addons) @@ -149,7 +147,7 @@ jobs: hide_complexity: true - name: Write to Job Summary if: steps.coverage.outputs.report == 'true' - run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY + run: cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY" - name: Update .pot files run: noviat_export_and_push_pot https://github.com/${{ github.repository }} if: ${{ matrix.makepot == 'true' && github.event_name == 'push' }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cc3fae..c62c1c3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ exclude: | ^setup/|/static/description/index\.html$| # We don't want to mess with tool-generated files .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs| - # Maybe reactivate this when all README files include prettier ignore tags? + # README.md holds the generated addons table ^README\.md$| # Library files can have extraneous formatting (even minimized) /static/(src/)?lib/| @@ -121,10 +121,6 @@ repos: - id: check-xml - id: mixed-line-ending args: ["--fix=lf"] - - repo: https://github.com/asottile/pyupgrade - rev: v3.21.2 - hooks: - - id: pyupgrade - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.16.9 hooks: @@ -137,13 +133,7 @@ repos: rev: v10.0.11 hooks: - id: pylint_odoo - name: pylint (optional, core only) - args: - - --rcfile=.pylintrc - - --exit-zero - verbose: true - - id: pylint_odoo - name: pylint-odoo (mandatory, blocking) + name: pylint-odoo args: - --disable=missing-readme - --rcfile=.pylintrc-mandatory diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index b3e77fc..0000000 --- a/.pylintrc +++ /dev/null @@ -1,118 +0,0 @@ -[MASTER] -ignore-patterns=["^.*/TODO/.*$"] -load-plugins=pylint_odoo -score=n - -[IMPORTS] -deprecated-modules=pdb,pudb,ipdb,bs4 - -[ODOOLINT] -#readme-template-url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" -manifest-required-authors=Noviat -manifest-required-keys=license -manifest-deprecated-keys=description,active -license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 -valid-odoo-versions=18.0 - -[MESSAGES CONTROL] -disable=all - -# This .pylintrc contains optional AND mandatory checks and is meant to be -# loaded in an IDE to have it check everything, in the hope this will make -# optional checks more visible to contributors who otherwise never look at a -# green travis to see optional checks that failed. -# .pylintrc-mandatory containing only mandatory checks is used the pre-commit -# config as a blocking check. - -enable = - anomalous-backslash-in-string, - assignment-from-none, - attribute-deprecated, - dangerous-default-value, - deprecated-module, - development-status-allowed, - duplicate-key, - eval-used, - license-allowed, - manifest-author-string, - manifest-deprecated-key, - # manifest-required-author, - manifest-required-key, - manifest-version-format, - method-compute, - method-inverse, - method-required-super, - method-search, - pointless-statement, - pointless-string-statement, - print-used, - redundant-keyword-arg, - reimported, - return-in-init, - sql-injection, - too-few-format-args, - translation-field, - translation-required, - unreachable, - use-vim-comment, - # >= 15 - attribute-string-redundant, - consider-merging-classes-inherited, - context-overridden, - except-pass, - invalid-commit, - manifest-external-assets, - manifest-maintainers-list, - missing-readme, - missing-return, - odoo-addons-relative-import, - odoo-exception-warning, - renamed-field-parameter, - resource-not-exist, - test-folder-imported, - translation-contains-variable, - translation-positional-used, - website-manifest-key-not-valid-uri, - # >= 16 - external-request-timeout, - # >= 19 - bad-builtin-groupby, - category-allowed, - deprecated-name-get, - deprecated-odoo-model-method, - deprecated-self-cr, - inheritable-method-lambda, - inheritable-method-string, - invalid-email, - manifest-behind-migrations, - manifest-data-duplicated, - missing-odoo-file, - no-raise-unlink, - no-search-all, - no-wizard-in-models, - prohibited-method-override, - prefer-env-translation, - translation-format-interpolation, - translation-format-truncated, - translation-injection, - translation-fstring-interpolation, - translation-not-lazy, - translation-too-few-args, - translation-too-many-args, - translation-unsupported-format, - no-write-in-compute, - odoolint, - # >= 20 - manifest-summary-multiline, - # messages that do not cause the lint step to fail - consider-merging-classes-inherited, - invalid-commit, - missing-readme, - odoo-addons-relative-import, - redefined-builtin - - -[REPORTS] -msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} -output-format=colorized -reports=no diff --git a/.pylintrc-mandatory b/.pylintrc-mandatory index cd769dc..7f68d44 100644 --- a/.pylintrc-mandatory +++ b/.pylintrc-mandatory @@ -11,12 +11,11 @@ deprecated-modules=pdb,pudb,ipdb,bs4 manifest-required-authors=Noviat manifest-required-keys=license manifest-deprecated-keys=description,active -license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 +license-allowed=AGPL-3,LGPL-3,Other proprietary valid-odoo-versions=18.0 [MESSAGES CONTROL] disable=all - enable = anomalous-backslash-in-string, assignment-from-none, diff --git a/.ruff.toml b/.ruff.toml index b153261..1798474 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -16,6 +16,40 @@ select = [ "E501", # line too long (default 88) "I", # isort "UP", # pyupgrade + # Autofixed + "RET501", + "RET502", + "RET505", + "RET506", + "RET507", + "RET508", + "PLR1711", + "PLR5501", + "RUF019", + "RUF021", + "RUF100", + "SIM114", + "ISC001", + "C4", + "PIE", + "FLY", + "FURB", + # Few and real: logging format, performance, security + "G", + "PERF", + "S102", + "S105", + "S106", + "S107", + "S108", + "S301", + "S603", + "S607", + "S704", + # Commented-out code, blind except, unused unpacked variables + "ERA001", + "BLE001", + "RUF059", ] extend-safe-fixes = ["UP008"] exclude = ["setup/*"] diff --git a/account_ebics/__init__.py b/account_ebics/__init__.py index ecdeb04..2feacf9 100644 --- a/account_ebics/__init__.py +++ b/account_ebics/__init__.py @@ -8,7 +8,7 @@ _logger = logging.getLogger(__name__) try: from . import models from . import wizards -except Exception: +except Exception: # noqa: BLE001 - the module must load without fintech _logger.warning("Import Error, check if fintech lib has been installed") diff --git a/account_ebics/migrations/13.0.1.1/post-migration.py b/account_ebics/migrations/13.0.1.1/post-migration.py index 94783f9..387e175 100644 --- a/account_ebics/migrations/13.0.1.1/post-migration.py +++ b/account_ebics/migrations/13.0.1.1/post-migration.py @@ -25,7 +25,7 @@ def _ebics_config_upgrade(env, version): if os.path.isfile(keys_fn_old): keys_fn = ebics_keys_root + "/" + cfg_data["ebics_user"] + "_keys" os.rename(keys_fn_old, keys_fn) - state = cfg_data["state"] == "active" and "confirm" or "draft" + state = (cfg_data["state"] == "active" and "confirm") or "draft" cfg.write( { "company_ids": [(6, 0, [cfg_data["company_id"]])], diff --git a/account_ebics/models/ebics_config.py b/account_ebics/models/ebics_config.py index b75d1a7..185e6d3 100644 --- a/account_ebics/models/ebics_config.py +++ b/account_ebics/models/ebics_config.py @@ -127,7 +127,7 @@ class EbicsConfig(models.Model): @api.model def _default_ebics_keys(self): - return "/".join(["/etc/odoo/ebics_keys", self._cr.dbname]) + return f"/etc/odoo/ebics_keys/{self._cr.dbname}" @api.constrains("ebics_key_bitlength") def _check_ebics_key_bitlength(self): @@ -185,9 +185,8 @@ class EbicsConfig(models.Model): if c == "Z": o_list[-i] = "0" continue - else: - o_list[-i] = chr(ord(c) + 1) - break + o_list[-i] = chr(ord(c) + 1) + break next_order_number = "".join(o_list) if next_order_number == "ZZZZ": next_order_number = "A000" diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index 33f80ec..9c0c35f 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -225,9 +225,8 @@ class EbicsFile(models.Model): journal_currency = jrnl.currency_id or jrnl.company_id.currency_id if journal_currency != currency: continue - else: - journal = jrnl - break + journal = jrnl + break if not journal: message = self.env._( @@ -301,7 +300,7 @@ class EbicsFile(models.Model): self.note_process += self.env._( "%(st_cnt)s bank statement%(sp)s been imported: ", st_cnt=st_cnt, - sp=st_cnt == 1 and self.env._(" has") or self.env._("s have"), + sp=(st_cnt == 1 and self.env._(" has")) or self.env._("s have"), ) self.note_process += "\n" for statement in statements: @@ -392,9 +391,7 @@ class EbicsFile(models.Model): res["notifications"].append({"type": "error", "message": message}) return datas - lines = [] - for i in range(0, len(file_data), 120): - lines.append(file_data[i : i + 120]) + lines = [file_data[i : i + 120] for i in range(0, len(file_data), 120)] st_lines = b"" transactions = False @@ -488,11 +485,12 @@ class EbicsFile(models.Model): try: with self.env.cr.savepoint(): self._create_bank_statement_oca(res, st_data) - except UserError as e: + except UserError as e: # noqa: PERF203 res["notifications"].append( {"type": "error", "message": "".join(e.args)} ) - except Exception: + # Each statement fails alone; the traceback is reported to the user + except Exception: # noqa: BLE001 tb = "".join(format_exception(*exc_info())) res["notifications"].append({"type": "error", "message": tb}) @@ -514,7 +512,7 @@ class EbicsFile(models.Model): try: self._create_bank_statement_oe(res, st_data) self.env.cr.commit() # pylint: disable=E8102 - except UserError as e: + except UserError as e: # noqa: PERF203 msg = "".join(e.args) msg += "\n" msg += self.env._( @@ -522,7 +520,8 @@ class EbicsFile(models.Model): nr=st_data["acc_number"], ) res["notifications"].append({"type": "error", "message": msg}) - except Exception: + # Each statement fails alone; the traceback is reported to the user + except Exception: # noqa: BLE001 tb = "".join(format_exception(*exc_info())) res["notifications"].append({"type": "error", "message": tb}) diff --git a/account_ebics/models/ebics_file_format.py b/account_ebics/models/ebics_file_format.py index b937ec0..3c84744 100644 --- a/account_ebics/models/ebics_file_format.py +++ b/account_ebics/models/ebics_file_format.py @@ -113,7 +113,7 @@ class EbicsFileFormat(models.Model): @api.depends("ebics_version", "name", "btf_message", "description") def _compute_display_name(self): for rec in self: - name = rec.ebics_version == "2" and rec.name or rec.btf_message + name = (rec.ebics_version == "2" and rec.name) or rec.btf_message if rec.description: name += " - " + rec.description rec.display_name = name diff --git a/account_ebics/models/ebics_userid.py b/account_ebics/models/ebics_userid.py index 4aef532..c876466 100644 --- a/account_ebics/models/ebics_userid.py +++ b/account_ebics/models/ebics_userid.py @@ -38,7 +38,7 @@ class EbicsBank(EbicsBank): The OrderID must be a string between 'A000' and 'ZZZZ' and unique for each partner id. """ - return hasattr(self, "_order_number") and self._order_number or "A000" + return (hasattr(self, "_order_number") and self._order_number) or "A000" class EbicsUserID(models.Model): @@ -216,7 +216,9 @@ class EbicsUserID(models.Model): rec.ebics_passphrase_store_readonly = True if rec.state == "draft": rec.ebics_passphrase_required = True - rec.ebics_passphrase_invisible = rec.ebics_keys_found and True or False + rec.ebics_passphrase_invisible = ( + rec.ebics_keys_found and True + ) or False rec.ebics_passphrase_store_readonly = False elif rec.state == "init": rec.ebics_passphrase_required = False @@ -289,9 +291,8 @@ class EbicsUserID(models.Model): keyring["#USER"] except ValueError as err: # noqa: F841 raise UserError(self.env._("Passphrase mismatch.")) # noqa: B904 - else: - if self.state != "draft": - self.ebics_passphrase = False + elif self.state != "draft": + self.ebics_passphrase = False @api.onchange("swift_3skey") def _onchange_swift_3skey(self): @@ -479,7 +480,7 @@ class EbicsUserID(models.Model): lang = lang.lower() lang = lang if lang in INI_LETTER_LANGS else "en" fn_date = fields.Date.today().isoformat() - fn = "_".join([self.ebics_config_id.ebics_host, "ini_letter", fn_date]) + ".pdf" + fn = f"{self.ebics_config_id.ebics_host}_ini_letter_{fn_date}" + ".pdf" letter = user.create_ini_letter(bankname=ebics_config_bank.name, lang=lang) vals = { "ebics_ini_letter": base64.encodebytes(letter), @@ -548,10 +549,7 @@ class EbicsUserID(models.Model): public_bank_keys = public_bank_keys.encode() fn_date = fields.Date.today().isoformat() - fn = ( - "_".join([self.ebics_config_id.ebics_host, "public_bank_keys", fn_date]) - + ".txt" - ) + fn = f"{self.ebics_config_id.ebics_host}_public_bank_keys_{fn_date}" + ".txt" vals = { "ebics_public_bank_keys": base64.encodebytes(public_bank_keys), "ebics_public_bank_keys_fn": fn, diff --git a/account_ebics/models/fintech_ebics_register.py b/account_ebics/models/fintech_ebics_register.py index 7225620..ef220b7 100644 --- a/account_ebics/models/fintech_ebics_register.py +++ b/account_ebics/models/fintech_ebics_register.py @@ -24,8 +24,7 @@ try: fintech_register_users = ( fintech_register_users and [x.strip() for x in fintech_register_users.split(",")] - or None - ) + ) or None fintech.cryptolib = "cryptography" fintech.register( name=fintech_register_name, @@ -38,7 +37,7 @@ except RuntimeError as e: else: _logger.error(str(e)) fintech.register() -except Exception: +except Exception: # noqa: BLE001 - logged with the traceback, then retried msg = "fintech.register error" tb = "".join(format_exception(*exc_info())) msg += f"\n{tb}" diff --git a/account_ebics/wizards/ebics_change_passphrase.py b/account_ebics/wizards/ebics_change_passphrase.py index 628aaa5..7633fc5 100644 --- a/account_ebics/wizards/ebics_change_passphrase.py +++ b/account_ebics/wizards/ebics_change_passphrase.py @@ -70,8 +70,7 @@ class EbicsChangePassphrase(models.TransientModel): passphrase = ( self.ebics_userid_id.ebics_passphrase_store and self.ebics_userid_id.ebics_passphrase - or self.old_pass - ) + ) or self.old_pass try: keyring_params = { "keys": self.ebics_userid_id.ebics_keys_fn, diff --git a/account_ebics/wizards/ebics_xfer.py b/account_ebics/wizards/ebics_xfer.py index 215c476..4ddc1e2 100644 --- a/account_ebics/wizards/ebics_xfer.py +++ b/account_ebics/wizards/ebics_xfer.py @@ -37,7 +37,7 @@ class EbicsBank(EbicsBank): The OrderID must be a string between 'A000' and 'ZZZZ' and unique for each partner id. """ - return hasattr(self, "_order_number") and self._order_number or "A000" + return (hasattr(self, "_order_number") and self._order_number) or "A000" class EbicsXfer(models.TransientModel): @@ -109,8 +109,7 @@ class EbicsXfer(models.TransientModel): ) if cfg and len(cfg) == 1: return cfg - else: - return cfg_mod + return cfg_mod def _compute_ebics_sig_passphrase_invisible(self): for rec in self: @@ -236,8 +235,8 @@ class EbicsXfer(models.TransientModel): ) ) ebics_files = self.env["ebics.file"] - date_from = self.date_from and self.date_from.isoformat() or None - date_to = self.date_to and self.date_to.isoformat() or None + date_from = (self.date_from and self.date_from.isoformat()) or None + date_to = (self.date_to and self.date_to.isoformat()) or None for df in download_formats: success = False try: @@ -314,7 +313,8 @@ class EbicsXfer(models.TransientModel): ) self.note += "\n" self.note += " ".join(e.args) - except Exception: + # Reported to the user in the note + except Exception: # noqa: BLE001 err_cnt += 1 self.note += "\n" self.note += self.env._( @@ -412,7 +412,7 @@ class EbicsXfer(models.TransientModel): suffix = self.format_id.suffix fn = self.upload_fname if suffix and not fn.endswith(suffix): - fn = ".".join([fn, suffix]) + fn = f"{fn}.{suffix}" ef_vals = { "name": self.upload_fname, "data": self.upload_data, @@ -449,7 +449,8 @@ class EbicsXfer(models.TransientModel): self.note += self.env._("EBICS Verification Error:") self.note += "\n" self.note += self.env._("The EBICS response could not be verified.") - except Exception: + # Reported to the user in the note, with the traceback + except Exception: # noqa: BLE001 self.note += "\n" self.note += self.env._("Unknown Error") tb = "".join(format_exception(*exc_info())) @@ -523,7 +524,7 @@ class EbicsXfer(models.TransientModel): # manual_approval replaced by transport_only class param in fintech 7.4 fintech74 = hasattr(EbicsUser, "transport_only") if fintech74: - user_params["transport_only"] = signature_class == "T" and True or False + user_params["transport_only"] = (signature_class == "T" and True) or False try: user = EbicsUser(**user_params) except ValueError as err: @@ -543,7 +544,8 @@ class EbicsXfer(models.TransientModel): try: client = EbicsClient(bank, user, version=self.ebics_config_id.ebics_version) - except Exception: + # Reported to the user in the note, with the traceback + except Exception: # noqa: BLE001 self.note += "\n" self.note += self.env._("Unknown Error") tb = "".join(format_exception(*exc_info())) @@ -608,7 +610,7 @@ class EbicsXfer(models.TransientModel): suffix = file_format.suffix if suffix and not fn.endswith(suffix): - fn = ".".join([fn, suffix]) + fn = f"{fn}.{suffix}" dups = self._check_duplicate_ebics_file(fn, file_format) if dups: raise UserError( @@ -627,7 +629,7 @@ class EbicsXfer(models.TransientModel): "date_from": self.date_from, "date_to": self.date_to, "format_id": file_format.id, - "state": file_format.download_process_method and "draft" or "done", + "state": (file_format.download_process_method and "draft") or "done", "user_id": self._uid, "ebics_userid_id": self.ebics_userid_id.id, "company_ids": self.ebics_config_id.company_ids.ids, @@ -656,9 +658,8 @@ class EbicsXfer(models.TransientModel): break if c == "Z": continue - else: - o_list[-i] = chr(ord(c) + 1) - break + o_list[-i] = chr(ord(c) + 1) + break next_nr = "".join(o_list) if next_nr == "ZZZZ": next_nr = "A000" diff --git a/account_ebics_batch/models/ebics_batch_log.py b/account_ebics_batch/models/ebics_batch_log.py index 8f196fc..61b68db 100644 --- a/account_ebics_batch/models/ebics_batch_log.py +++ b/account_ebics_batch/models/ebics_batch_log.py @@ -120,7 +120,8 @@ class EbicsBatchLog(models.Model): ) except UserError as e: import_dict["errors"].append(err_msg + " ".join(e.args)) - except Exception: + # Each configuration fails alone; reported in the batch log + except Exception: # noqa: BLE001 tb = "".join(format_exception(*exc_info())) import_dict["errors"].append(err_msg + tb) log.file_ids = [(6, 0, ebics_file_ids)] @@ -128,14 +129,15 @@ class EbicsBatchLog(models.Model): log._ebics_process(import_dict) except UserError as e: import_dict["errors"].append(err_msg + " ".join(e.args)) - except Exception: + # Reported in the batch log with the traceback + except Exception: # noqa: BLE001 tb = "".join(format_exception(*exc_info())) import_dict["errors"].append(err_msg + tb) log._finalise_processing(import_dict) def _finalise_processing(self, import_dict): log_item_model = self.env["ebics.batch.log.item"] - state = self.has_draft_files and "draft" or "done" + state = (self.has_draft_files and "draft") or "done" note = "" error_count = 0 if import_dict["errors"]: @@ -157,7 +159,7 @@ class EbicsBatchLog(models.Model): lambda r: r.ebics_passphrase_store ) t_userids = ebics_userids.filtered(lambda r: r.signature_class == "T") - ebics_userid = t_userids and t_userids[0] or ebics_userids[0] + ebics_userid = (t_userids and t_userids[0]) or ebics_userids[0] xfer_wiz = ( self.env["ebics.xfer"] .with_context(ebics_download=True) diff --git a/account_ebics_oca_statement_import/__manifest__.py b/account_ebics_oca_statement_import/__manifest__.py index ac06ec2..f7cd0a1 100644 --- a/account_ebics_oca_statement_import/__manifest__.py +++ b/account_ebics_oca_statement_import/__manifest__.py @@ -4,7 +4,7 @@ { "name": "EBICS - Bank Statement Import (OCA)", "summary": "Process EBICS statement files with the OCA bank statement import", - "version": "18.0.1.0.2", + "version": "18.0.1.0.3", "author": "Noviat", "website": "https://www.noviat.com/", "category": "Hidden", diff --git a/account_ebics_oca_statement_import/wizards/account_statement_import.py b/account_ebics_oca_statement_import/wizards/account_statement_import.py index 369b296..ac54fc1 100644 --- a/account_ebics_oca_statement_import/wizards/account_statement_import.py +++ b/account_ebics_oca_statement_import/wizards/account_statement_import.py @@ -64,7 +64,7 @@ class AccountStatementImport(models.TransientModel): + message ) _logger.warning(log_msg) - return + return None return super()._check_parsed_data(stmts_vals) def _create_bank_statements(self, stmts_vals, result): @@ -79,42 +79,39 @@ class AccountStatementImport(models.TransientModel): """ 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( - self.env._( - "Statement %(st_name)s dated %(date)s " - "has already been imported.", - st_name=st_vals["name"], - date=st_date, - ) + 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( + self.env._( + "Statement %(st_name)s dated %(date)s " + "has already been imported.", + st_name=st_vals["name"], + date=st_date, ) + ) - if not transactions: - messages.append( - self.env._("This file doesn't contain any transaction.") - ) - if messages: - result["notifications"].append( - {"type": "warning", "message": "\n".join(messages)} - ) - return + if not transactions: + messages.append(self.env._("This file doesn't contain any transaction.")) + if messages: + result["notifications"].append( + {"type": "warning", "message": "\n".join(messages)} + ) + return None def _set_statement_name(self, st_vals): """ diff --git a/account_ebics_payment_order/models/account_payment_order.py b/account_ebics_payment_order/models/account_payment_order.py index cd6b489..7af550d 100644 --- a/account_ebics_payment_order/models/account_payment_order.py +++ b/account_ebics_payment_order/models/account_payment_order.py @@ -59,7 +59,7 @@ class AccountPaymentOrder(models.Model): "\nPlease generate first the Payment Order file." ) ) - elif len(attach) > 1: + if len(attach) > 1: raise UserError( self.env._( "This payment order contains multiple attachments." @@ -68,39 +68,38 @@ class AccountPaymentOrder(models.Model): "EBICS Processing > EBICS Upload menu" ) ) - else: - origin = self.env._("Payment Order") + ": " + self.name - if not self.journal_id.ebics_config_id: - raise UserError( - self.env._( - "No active EBICS configuration available for the selected bank." - ) + origin = self.env._("Payment Order") + ": " + self.name + if not self.journal_id.ebics_config_id: + raise UserError( + self.env._( + "No active EBICS configuration available for the selected bank." ) - ctx.update( - { - "default_ebics_config_id": self.journal_id.ebics_config_id.id, - "default_upload_data": attach.datas, - "default_upload_fname": attach.name, - "origin": origin, - } ) - ebics_xfer = ( - self.env["ebics.xfer"] - .with_company(self.company_id) - .with_context(**ctx) - .create({}) - ) - ebics_xfer._onchange_ebics_config_id() - ebics_xfer._onchange_upload_data() - view = self.env.ref("account_ebics.ebics_xfer_view_form_upload") - act = { - "name": self.env._("EBICS Upload"), - "view_mode": "form", - "res_model": "ebics.xfer", - "view_id": view.id, - "res_id": ebics_xfer.id, - "type": "ir.actions.act_window", - "target": "new", - "context": ctx, + ctx.update( + { + "default_ebics_config_id": self.journal_id.ebics_config_id.id, + "default_upload_data": attach.datas, + "default_upload_fname": attach.name, + "origin": origin, } - return act + ) + ebics_xfer = ( + self.env["ebics.xfer"] + .with_company(self.company_id) + .with_context(**ctx) + .create({}) + ) + ebics_xfer._onchange_ebics_config_id() + ebics_xfer._onchange_upload_data() + view = self.env.ref("account_ebics.ebics_xfer_view_form_upload") + act = { + "name": self.env._("EBICS Upload"), + "view_mode": "form", + "res_model": "ebics.xfer", + "view_id": view.id, + "res_id": ebics_xfer.id, + "type": "ir.actions.act_window", + "target": "new", + "context": ctx, + } + return act