From 39070d40fffc8e8100d7b4c1b7aca5339f2b33f0 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Thu, 25 Aug 2022 14:14:33 +0000 Subject: [PATCH] [FIX] web_editor, website: define specific dynamic snippet name Since [1] when the Dynamic Snippet was first introduced, it also introduced a concept of "inherited" snippets. Specific snippets would all `t-call` the same template for their rendering. A mechanism was introduced to deduce the `data-snippet` from the caller template, but it stored the obtained value in the `t-called` template itself. Because of this if several "specific snippets" that used that template had to be rendered, they would all have the `data-snippet` value of the first one that got compiled. We could compile the snippet template into something having a dynamically obtained `data-snippet` value, but then that would be equivalent to just using a `t-attf-data-snippet`. All specific snippets already do set a `snippet_name` in the context because it needs to be added in the classes. This commit therefore adds a `t-att-data-snippet` attribute on the base template, and populates with that same value in `onBuilt` for stable versions. During forward ports across stable versions, each new caller must be patched as well - and all patches must be removed in master. [1]: https://github.com/odoo/odoo/pull/53175 task-2922635 closes odoo/odoo#115566 X-original-commit: 73d2c9f87bf9a1a792f4318325c2e52fc81db5f2 Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Benoit Socias (bso) --- addons/web_editor/models/ir_qweb_fields.py | 2 +- addons/website/views/snippets/s_dynamic_snippet.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/models/ir_qweb_fields.py b/addons/web_editor/models/ir_qweb_fields.py index bf6a75c7909..7a4e338721f 100644 --- a/addons/web_editor/models/ir_qweb_fields.py +++ b/addons/web_editor/models/ir_qweb_fields.py @@ -59,7 +59,7 @@ class IrQWeb(models.AbstractModel): sub_call = el.get('t-call') if sub_call: el.set('t-options', f"{{'snippet-key': '{snippet_key}', 'snippet-sub-call-key': '{sub_call}'}}") - # If it already has a data-snippet it is a saved snippet. + # If it already has a data-snippet it is a saved or an inherited snippet. # Do not override it. elif 'data-snippet' not in el.attrib: el.attrib['data-snippet'] = snippet_key.split('.', 1)[-1] diff --git a/addons/website/views/snippets/s_dynamic_snippet.xml b/addons/website/views/snippets/s_dynamic_snippet.xml index 7138bed2fa0..953fdaf7396 100644 --- a/addons/website/views/snippets/s_dynamic_snippet.xml +++ b/addons/website/views/snippets/s_dynamic_snippet.xml @@ -1,7 +1,7 @@