Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] views_migration_17: support alternative output directory for transformed views instead of in-place write #3189

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions views_migration_17/patch_xml_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import ast
import logging
import os
import re

from lxml import etree
Expand Down Expand Up @@ -28,6 +29,19 @@ def new_tag_record(self, rec, extra_vals=None):
xml_import._tag_record = new_tag_record


def write_to_file(filename, content):
output_folder = os.getenv("VIEWS_MIGRATION_17_OUTPUT_DIR")
if output_folder:
filename = os.path.join(output_folder, *filename.split(os.sep)[-3:])
try:
os.makedirs(os.path.dirname(filename), exist_ok=True)
except PermissionError:
_logger.error(f"Permission denied: {filename}")
return
with open(filename, "w", encoding="utf-8") as file:
file.write(content)


def _convert_ir_ui_view_modifiers(self, record_node, extra_vals=None):
rec_id = record_node.get("id", "")
f_model = record_node.find('field[@name="model"]')
Expand Down Expand Up @@ -131,8 +145,7 @@ def _convert_ir_ui_view_modifiers(self, record_node, extra_vals=None):
f_arch.text = root_content.text

new_xml = previous_xml.replace(arch, arch_result)
with file_open(self.xml_filename, "w") as file:
file.write(new_xml)
write_to_file(self.xml_filename, new_xml)
try:
# test file before save
etree.fromstring(new_xml.encode())
Expand All @@ -147,6 +160,7 @@ def _convert_ir_ui_view_modifiers(self, record_node, extra_vals=None):


import itertools
import os

from odoo.osv.expression import (
AND_OPERATOR,
Expand Down Expand Up @@ -1545,12 +1559,3 @@ def modifier_to_domain(modifier):
return _modifier_to_domain_ast_wrap_domain(modifier_ast)
except Exception as e:
raise ValueError(f"{e}: {modifier}")


def str2bool(s):
s = s.lower()
if s in ("1", "true"):
return True
if s in ("0", "false"):
return False
raise ValueError()
10 changes: 9 additions & 1 deletion views_migration_17/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ This module is not installable, to use this module, you need to:

odoo -d DATABASE_NAME -i MODULE_TO_MIGRATE --load=base,web,views_migration_17 --stop-after-init

2. If successful, the modifications will be applied to the source code of your module. Alternatively, you can set the environment variable `VIEWS_MIGRATION_17_OUTPUT_DIR` to specify a different output directory for the modified views. Ensure that the user running the Odoo process has the appropriate permissions for the specified path.

2. If success the modifications will be in the source code of your module.
.. code-block:: shell

export VIEWS_MIGRATION_17_OUTPUT_DIR=/path/to/output/directory

Example in a [doodba-copier-template](https://github.com/Tecnativa/doodba-copier-template) project:

.. code-block:: shell

docker compose run -e VIEWS_MIGRATION_17_OUTPUT_DIR=/opt/odoo/auto/migrated_views -u odoo --rm odoo odoo -d devel -i $modules --load=base,web,views_migration_17 --stop-after-init
Loading