From 561a40f6dc850f1b94c1d64deb79737b4eea9c7f Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Thu, 9 Nov 2023 18:17:24 +0100 Subject: [PATCH] [UPD] load data exceptions --- .pre-commit-config.yaml | 35 +++++---- wizard/scop_invoice_idf_wizard.py | 121 +++++++++++++++++------------- 2 files changed, 86 insertions(+), 70 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 732d0c4..4acca68 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,8 @@ exclude: | ^setup/|/static/description/index\.html$| # We don't want to mess with tool-generated files .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/| + # Maybe reactivate this when all README files include prettier ignore tags? + ^README\.md$| # Library files can have extraneous formatting (even minimized) /static/(src/)?lib/| # Repos using Sphinx to generate docs don't need prettying @@ -25,8 +27,13 @@ repos: entry: found forbidden files; remove them language: fail files: "\\.rej$" + - id: en-po-files + name: en.po files cannot exist + entry: found a en.po file + language: fail + files: '[a-zA-Z0-9_]*/i18n/en\.po$' - repo: https://github.com/oca/maintainer-tools - rev: 7d8a9f9ad73db0976fb03cbee43d953bc29b89e9 + rev: ab1d7f6 hooks: # update the NOT INSTALLABLE ADDONS section above - id: oca-update-pre-commit-excluded-addons @@ -48,7 +55,7 @@ repos: hooks: - id: black - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.6.2 + rev: v2.1.2 hooks: - id: prettier name: prettier (with plugin-xml) @@ -59,7 +66,7 @@ repos: - --plugin=@prettier/plugin-xml files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$ - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.15.0 + rev: v7.8.1 hooks: - id: eslint verbose: true @@ -67,7 +74,7 @@ repos: - --color - --fix - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v3.2.0 hooks: - id: trailing-whitespace # exclude autogenerated files @@ -89,37 +96,33 @@ repos: - id: mixed-line-ending args: ["--fix=lf"] - repo: https://github.com/asottile/pyupgrade - rev: v2.32.1 + rev: v2.7.2 hooks: - id: pyupgrade args: ["--keep-percent-format"] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort name: isort except __init__.py args: - --settings=. exclude: /__init__\.py$ - - repo: https://gitlab.com/PyCQA/flake8 - rev: 3.9.2 + - repo: https://github.com/PyCQA/flake8 + rev: 3.8.3 hooks: - id: flake8 name: flake8 additional_dependencies: ["flake8-bugbear==20.1.4"] - - repo: https://github.com/PyCQA/pylint - rev: v2.11.1 + - repo: https://github.com/OCA/pylint-odoo + rev: 7.0.2 hooks: - - id: pylint + - id: pylint_odoo name: pylint with optional checks args: - --rcfile=.pylintrc - --exit-zero verbose: true - additional_dependencies: &pylint_deps - - pylint-odoo==5.0.5 - - id: pylint - name: pylint with mandatory checks + - id: pylint_odoo args: - --rcfile=.pylintrc-mandatory - additional_dependencies: *pylint_deps diff --git a/wizard/scop_invoice_idf_wizard.py b/wizard/scop_invoice_idf_wizard.py index 160b753..a203913 100644 --- a/wizard/scop_invoice_idf_wizard.py +++ b/wizard/scop_invoice_idf_wizard.py @@ -6,6 +6,8 @@ import csv import mimetypes from io import StringIO +from dateutil.parser import parse + from odoo import _, api, fields, models from odoo.exceptions import UserError from odoo.tools.mimetypes import guess_mimetype @@ -105,72 +107,83 @@ class ScopImportIDFWizard(models.TransientModel): if journal in ["VE", "BFC"]: tried_lines += 1 compte = row["Compte"] - partner_id = self.env["res.partner"].search( - [ - ["member_number_int", "=", int(compte[2:7])], - ["member_number_int", "!=", 0], - ] - ) - if len(partner_id) != 1: + if not compte[2:7].isdigit(): logs += ( "<li> Ligne " + str(line) - + ": Impossible de rattacher le compte " + + ": Le compte " + compte - + "</li>" + + " n'est pas lié à un adhérent</li>" ) else: - writing_date = row["Date écriture"] - libelle = row["Libellé écriture"] - existing_import_line = self.env[model].search( + partner_id = self.env["res.partner"].search( [ - ["partner_id", "=", partner_id.id], - ["writing_date", "=", writing_date], - ["journal", "=", journal], - ["name", "=", libelle], + ["member_number_int", "=", int(compte[2:7])], + ["member_number_int", "!=", 0], ] ) - if len(existing_import_line) > 0: - logs += "<li> Ligne " + str(line) + ": Doublon</li>" + if len(partner_id) != 1: + logs += ( + "<li> Ligne " + + str(line) + + ": Impossible de rattacher le compte " + + compte + + "</li>" + ) else: - debit = float(row["Débit euro"].replace(",", ".")) - credit = float(row["Crédit euro"].replace(",", ".")) - if debit > 0 and credit > 0: - logs += ( - "<li> Ligne " + str(line) + ": Montants incorrects</li>" - ) + writing_date = parse(row["Date écriture"]) + libelle = row["Libellé écriture"] + existing_import_line = self.env[model].search( + [ + ["partner_id", "=", partner_id.id], + ["writing_date", "=", writing_date], + ["journal", "=", journal], + ["name", "=", libelle], + ] + ) + if len(existing_import_line) > 0: + logs += "<li> Ligne " + str(line) + ": Doublon</li>" else: - if journal == "VE" and debit > 0: - line_type = "inv" - elif journal == "BFC" and credit > 0: - line_type = "pay" - elif journal == "BFC" and debit > 0: - line_type = "reject" - credit = debit * (-1) - debit = 0 + debit = float(row["Débit euro"].replace(",", ".")) + credit = float(row["Crédit euro"].replace(",", ".")) + if debit > 0 and credit > 0: + logs += ( + "<li> Ligne " + + str(line) + + ": Montants incorrects</li>" + ) else: - line_type = "refund" - - lettrage = row["Lettrage N"] - year = row["Année"] - acc_doc = row["Pièce"] - - values = { - "company_id": company_id.id, - "partner_id": partner_id.id, - "journal": journal, - "writing_date": writing_date, - "acc_doc": acc_doc, - "name": libelle, - "year": year, - "type": line_type, - "lettrage": lettrage, - "debit": debit, - "credit": credit, - } - new_line = self.env[model].create(values) - success += 1 - new_lines_years.add(new_line.year) + if journal == "VE" and debit > 0: + line_type = "inv" + elif journal == "BFC" and credit > 0: + line_type = "pay" + elif journal == "BFC" and debit > 0: + line_type = "reject" + credit = debit * (-1) + debit = 0 + else: + line_type = "refund" + + lettrage = row["Lettrage N"] + year = row["Année"] + acc_doc = row["Pièce"] + + values = { + "company_id": company_id.id, + "partner_id": partner_id.id, + "journal": journal, + "writing_date": writing_date, + "acc_doc": acc_doc, + "name": libelle, + "year": year, + "type": line_type, + "lettrage": lettrage, + "debit": debit, + "credit": credit, + } + new_line = self.env[model].create(values) + success += 1 + new_lines_years.add(new_line.year) logs += "</ul>" new_log.write( -- GitLab