Skip to content

Commit d7a7e93

Browse files
authored
Merge pull request #5435 from dixmit/18.0-fix-snippet
[18.0][OU][ADD] web_editor: Fix snippets
2 parents acb1a01 + 65ae525 commit d7a7e93

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docsource/modules170-180.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ Module coverage 17.0 -> 18.0
10781078
+---------------------------------------------------+----------------------+-------------------------------------------------+
10791079
| web |Nothing to do | |
10801080
+---------------------------------------------------+----------------------+-------------------------------------------------+
1081-
| web_editor |Nothing to do | |
1081+
| web_editor |Done | |
10821082
+---------------------------------------------------+----------------------+-------------------------------------------------+
10831083
| web_hierarchy |Nothing to do | |
10841084
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import logging
2+
3+
from lxml import etree
4+
from openupgradelib import openupgrade
5+
6+
_logger = logging.getLogger(__name__)
7+
8+
9+
@openupgrade.migrate()
10+
def migrate(env, version):
11+
views = env["ir.ui.view"].search(
12+
[("arch_db", "like", "expr=\"//div[@id='snippet_custom']\"")]
13+
)
14+
for view in views:
15+
try:
16+
t_element = etree.fromstring(view.arch_db).xpath("//t")[0]
17+
thumbnail_url = t_element.attrib["t-thumbnail"]
18+
full_snippet_key = t_element.attrib["t-snippet"]
19+
template_key, snippet_key = view.key.rsplit(".", 1)
20+
view.write(
21+
{
22+
"arch": f"""
23+
<data inherit_id="{template_key}">
24+
<xpath expr="//snippets[@id='snippet_custom']" position="inside">
25+
<t t-snippet="{full_snippet_key}" t-thumbnail="{thumbnail_url}"/>
26+
</xpath>
27+
</data>
28+
""" # noqa: E501
29+
}
30+
)
31+
except Exception as e:
32+
_logger.error(f"View with id {view.id} cannot be transformed {e}")

0 commit comments

Comments
 (0)