Skip to content

Commit

Permalink
[IMP] util.remove_view : remove redundant t-calls
Browse files Browse the repository at this point in the history
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"/>
```
  • Loading branch information
kmod-odoo committed Aug 5, 2024
1 parent 86bd61f commit 20793ea
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
from operator import itemgetter

import lxml
from psycopg2 import sql
from psycopg2.extras import Json, execute_values

try:
from odoo import release
from odoo import modules, release
from odoo.tools.convert import xml_import
from odoo.tools.misc import file_open
from odoo.tools.translate import xml_translate
except ImportError:
from openerp import release
from openerp import modules, release
from openerp.tools.convert import xml_import
from openerp.tools.misc import file_open

Expand Down Expand Up @@ -99,12 +100,47 @@ def remove_view(cr, xml_id=None, view_id=None, silent=False, key=None):
if cr.rowcount:
xml_id = "%s.%s" % cr.fetchone()

# From given or determined xml_id, the views duplicated in a multi-website
# context are to be found and removed.
if xml_id != "?" and column_exists(cr, "ir_ui_view", "key"):
cr.execute("SELECT id FROM ir_ui_view WHERE key = %s AND id != %s", [xml_id, view_id])
for [v_id] in cr.fetchall():
remove_view(cr, view_id=v_id, silent=silent, key=xml_id)
if xml_id != "?":
# From given or determined xml_id, the views duplicated in a multi-website
# context are to be found and removed.
if column_exists(cr, "ir_ui_view", "key"):
cr.execute("SELECT id FROM ir_ui_view WHERE key = %s AND id != %s", [xml_id, view_id])
for [v_id] in cr.fetchall():
remove_view(cr, view_id=v_id, silent=silent, key=xml_id)

# Occurrences of xml_id in the t-call of views are to be found and removed.
arch_col = (
get_value_or_en_translation(cr, "ir_ui_view", "arch_db")
if column_exists(cr, "ir_ui_view", "arch_db")
else "arch"
)
cr.execute(
format_query(
cr,
"""
SELECT iv.id, imd.module, imd.name
FROM ir_ui_view iv
LEFT JOIN ir_model_data imd
ON iv.id = imd.res_id
AND imd.model = 'ir.ui.view'
WHERE {} ~ %s
""",
sql.SQL(arch_col),
),
[r"""\yt-call=(["'']){}\1""".format(xml_id)],
)
standard_modules = set(modules.get_modules()) - {"studio_customization"}
for vid, module, name in cr.fetchall():
with edit_view(cr, view_id=vid) as arch:
for node in arch.findall(".//t[@t-call='{}']".format(xml_id)):
node.getparent().remove(node)
if not module or module not in standard_modules:
_logger.info(
"The view %s with ID: %s has been updated, removed a t-call to a deprecated view %s",
('"{}.{}"'.format(module, name) if module else ""),
vid,
xml_id,
)

if not view_id:
return
Expand Down

0 comments on commit 20793ea

Please sign in to comment.