Skip to content

Commit 5d985e6

Browse files
committed
[IMP] util.remove_view : remove redundant t-calls
while removing the view, removing the content having t-call in other views which  are calling to have the content of it. As there are many specific fixes available for this, it's better to handle  it in remove_view. Before fix: t-call with the same xml_id will remain in other views that are using it. So during access of that view, the system is raising an error "view not found." ``` <t name="Payment" t-name="website_sale.payment"> <t t-call="website_sale.cart_summary"/> </t> ``` After fix: t-call will be removed, so no error will be raised. ``` <t name="Payment" t-name="website_sale.payment"> </t> ``` Traceback: ``` Error while render the template ValueError: View 'website_sale.cart_summary' in website 1 not found Template: website_sale.payment Path: /t/t/div/div[1]/div/div[4]/div[1]/t Node: <t t-call="website_sale.address_on_payment"/> ```
1 parent 86bd61f commit 5d985e6

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/util/records.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
from operator import itemgetter
1010

1111
import lxml
12+
from psycopg2 import sql
1213
from psycopg2.extras import Json, execute_values
1314

1415
try:
15-
from odoo import release
16+
from odoo import modules, release
1617
from odoo.tools.convert import xml_import
1718
from odoo.tools.misc import file_open
1819
from odoo.tools.translate import xml_translate
1920
except ImportError:
20-
from openerp import release
21+
from openerp import modules, release
2122
from openerp.tools.convert import xml_import
2223
from openerp.tools.misc import file_open
2324

@@ -98,6 +99,9 @@ def remove_view(cr, xml_id=None, view_id=None, silent=False, key=None):
9899
cr.execute("SELECT module, name FROM ir_model_data WHERE model='ir.ui.view' AND res_id=%s", [view_id])
99100
if cr.rowcount:
100101
xml_id = "%s.%s" % cr.fetchone()
102+
else: # In terms of calling remove_view with view_id
103+
cr.execute("SELECT key FROM ir_ui_view WHERE id = %s", [view_id])
104+
[key] = cr.fetchone() or [None]
101105

102106
# From given or determined xml_id, the views duplicated in a multi-website
103107
# context are to be found and removed.
@@ -106,6 +110,45 @@ def remove_view(cr, xml_id=None, view_id=None, silent=False, key=None):
106110
for [v_id] in cr.fetchall():
107111
remove_view(cr, view_id=v_id, silent=silent, key=xml_id)
108112

113+
# Occurrences of xml_id in the t-call of views are to be found and removed.
114+
if xml_id != "?" or key:
115+
arch_col = (
116+
get_value_or_en_translation(cr, "ir_ui_view", "arch_db")
117+
if column_exists(cr, "ir_ui_view", "arch_db")
118+
else "arch"
119+
)
120+
cr.execute(
121+
format_query(
122+
cr,
123+
"""
124+
SELECT iv.id, imd.module, imd.name
125+
FROM ir_ui_view iv
126+
LEFT JOIN ir_model_data imd
127+
ON iv.id = imd.res_id
128+
AND imd.model = 'ir.ui.view'
129+
WHERE {} ~ %s
130+
""",
131+
sql.SQL(arch_col),
132+
),
133+
[
134+
r"""\yt-call=(["'']){}\1""".format(
135+
xml_id if xml_id != "?" else key,
136+
)
137+
],
138+
)
139+
standard_modules = set(modules.get_modules()) - {"studio_customization"}
140+
for vid, module, name in cr.fetchall():
141+
with edit_view(cr, view_id=vid) as arch:
142+
for node in arch.findall(".//t[@t-call='{}']".format(xml_id if xml_id != "?" else key)):
143+
node.getparent().remove(node)
144+
if not module or module not in standard_modules:
145+
_logger.info(
146+
"The view %s with ID: %s has been updated, removed a t-call to a deprecated view %s",
147+
('"{}.{}"'.format(module, name) if module else ""),
148+
vid,
149+
xml_id if xml_id != "?" else key,
150+
)
151+
109152
if not view_id:
110153
return
111154

0 commit comments

Comments
 (0)