From 4a698da8b37055922be75a85f76d750dfbbadd42 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 30 Jan 2015 14:03:10 +0100 Subject: [PATCH] [IMP] qweb: Allow to propagate value to variables outside the loop. If the variable was existing outside the context of the ``foreach``, the value is copied at the end of the foreach into the global context. Fix #4461 - Q74531 - Q71486 - Q71675 --- addons/web/static/lib/qweb/qweb2.js | 4 ++++ doc/reference/qweb.rst | 20 ++++++++++++++++++++ openerp/addons/base/ir/ir_qweb.py | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index 2fbef19000a..92139b3c483 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -187,6 +187,10 @@ var QWeb2 = { } } } + + _.each(Object.keys(old_dict), function(z) { + old_dict[z] = new_dict[z]; + }); } else { this.exception("No enumerator given to foreach", context); } diff --git a/doc/reference/qweb.rst b/doc/reference/qweb.rst index a7564ded394..30ef4c25196 100644 --- a/doc/reference/qweb.rst +++ b/doc/reference/qweb.rst @@ -158,6 +158,26 @@ variables for various data points: a boolean flag indicating that the current iteration round is on an odd index + +These extra variables provided and all new variables created into the +``foreach`` are only available in the scope of the``foreach``. If the +variable exists outside the context of the ``foreach``, the value is copied +at the end of the foreach into the global context. + +:: + + + + +

+ + + +

+ + + + .. _reference/qweb/attributes: attributes diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index 4e8d60d0256..e28eebcc6d1 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -414,6 +414,10 @@ class QWeb(orm.AbstractModel): '%s_odd' % varname: False, }) ru.append(self.render_element(element, template_attributes, generated_attributes, copy_qwebcontext)) + + for k in qwebcontext.keys(): + qwebcontext[k] = copy_qwebcontext[k] + return "".join(ru) def render_tag_if(self, element, template_attributes, generated_attributes, qwebcontext):