55
66from odoo import api
77from odoo .exceptions import ValidationError
8+ from odoo .modules .module import get_resource_from_path
89from odoo .tools import mute_logger
910
1011from odoo .addons .base .models .ir_ui_view import NameManager , View
@@ -85,6 +86,21 @@ def _check_field_paths(self, node, field_paths, model_name, use):
8586 pass
8687
8788
89+ def _inverse_arch (self ):
90+ """
91+ Remove install_filename from context if it's from openupgrade_scripts.
92+ Without this, arch_fs will point to openupgrade_scripts' file which most likely
93+ won't exist when the migrated database is deployed, which breaks resetting views
94+ """
95+ if "install_filename" in self ._context :
96+ path_info = get_resource_from_path (self ._context ["install_filename" ])
97+ if path_info [0 ] == "openupgrade_scripts" :
98+ self = self .with_context (
99+ {k : v for k , v in self ._context .items () if k != "install_filename" }
100+ )
101+ return _inverse_arch ._original_method (self )
102+
103+
88104_check_xml ._original_method = View ._check_xml
89105View ._check_xml = _check_xml
90106check ._original_method = NameManager .check
@@ -93,3 +109,5 @@ def _check_field_paths(self, node, field_paths, model_name, use):
93109View ._raise_view_error = _raise_view_error
94110_check_field_paths ._original_method = View ._check_field_paths
95111View ._check_field_paths = _check_field_paths
112+ _inverse_arch ._original_method = View ._inverse_arch
113+ View ._inverse_arch = _inverse_arch
0 commit comments