|
5 | 5 |
|
6 | 6 | from odoo import api |
7 | 7 | from odoo.exceptions import ValidationError |
| 8 | +from odoo.modules.module import get_resource_from_path |
8 | 9 | from odoo.tools import mute_logger |
9 | 10 |
|
10 | 11 | from odoo.addons.base.models.ir_ui_view import IrUiView |
@@ -70,9 +71,26 @@ def _check_field_paths(self, node, field_paths, model_name, use): |
70 | 71 | pass |
71 | 72 |
|
72 | 73 |
|
| 74 | +def _inverse_arch(self): |
| 75 | + """ |
| 76 | + Remove install_filename from context if it's from openupgrade_scripts. |
| 77 | + Without this, arch_fs will point to openupgrade_scripts' file which most likely |
| 78 | + won't exist when the migrated database is deployed, which breaks resetting views |
| 79 | + """ |
| 80 | + if "install_filename" in self.env.context: |
| 81 | + path_info = get_resource_from_path(self.env.context["install_filename"]) |
| 82 | + if path_info[0] == "openupgrade_scripts": |
| 83 | + self = self.with_context( # pylint: disable=context-overridden |
| 84 | + {k: v for k, v in self.env.context.items() if k != "install_filename"} |
| 85 | + ) |
| 86 | + return _inverse_arch._original_method(self) |
| 87 | + |
| 88 | + |
73 | 89 | _check_xml._original_method = IrUiView._check_xml |
74 | 90 | IrUiView._check_xml = _check_xml |
75 | 91 | _raise_view_error._original_method = IrUiView._raise_view_error |
76 | 92 | IrUiView._raise_view_error = _raise_view_error |
77 | 93 | _check_field_paths._original_method = IrUiView._check_field_paths |
78 | 94 | IrUiView._check_field_paths = _check_field_paths |
| 95 | +_inverse_arch._original_method = IrUiView._inverse_arch |
| 96 | +IrUiView._inverse_arch = _inverse_arch |
0 commit comments