From 0f111ee561783c7600d926a3226cd390540864e6 Mon Sep 17 00:00:00 2001 From: Kev-Roche Date: Fri, 14 Feb 2025 15:22:08 +0100 Subject: [PATCH] [16.0][IMP] pre_init_hook pattern_import_export --- pattern_import_export/__init__.py | 1 + pattern_import_export/__manifest__.py | 1 + pattern_import_export/hooks.py | 27 +++++++++++++++++++ .../static/description/index.html | 7 ++--- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 pattern_import_export/hooks.py diff --git a/pattern_import_export/__init__.py b/pattern_import_export/__init__.py index 9b429614..0759f948 100644 --- a/pattern_import_export/__init__.py +++ b/pattern_import_export/__init__.py @@ -1,2 +1,3 @@ from . import models from . import wizard +from .hooks import pre_init_hook diff --git a/pattern_import_export/__manifest__.py b/pattern_import_export/__manifest__.py index a6a6b066..cbc752d5 100644 --- a/pattern_import_export/__manifest__.py +++ b/pattern_import_export/__manifest__.py @@ -31,4 +31,5 @@ ], "demo": ["demo/demo.xml"], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/pattern_import_export/hooks.py b/pattern_import_export/hooks.py new file mode 100644 index 00000000..8974063a --- /dev/null +++ b/pattern_import_export/hooks.py @@ -0,0 +1,27 @@ +# Copyright (C) 2025 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import SUPERUSER_ID, api + + +def pre_init_hook(cr): + env = api.Environment(cr, SUPERUSER_ID, {}) + all_export_lines = env["ir.exports.line"].search([]) + line_to_process = all_export_lines.filtered(lambda x: ".id" in x.name) + line_to_delete = env["ir.exports.line"] + for line in line_to_process: + new_name = line.name.replace(".id", "id") + lines_from_export = env["ir.exports.line"].search( + [("export_id", "=", line.export_id.id)] + ) + if not any( + [ + new_name in line_from_export.name + for line_from_export in lines_from_export + ] + ): + line.write({"name": new_name}) + else: + line_to_delete += line + line_to_delete.unlink() diff --git a/pattern_import_export/static/description/index.html b/pattern_import_export/static/description/index.html index f972ef49..78f5dc44 100644 --- a/pattern_import_export/static/description/index.html +++ b/pattern_import_export/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle {