changeset 92c25177eff1 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=92c25177eff1
description:
        Remove id to on_change calls that are cached

        issue8234
        review275131002
diffstat:

 CHANGELOG                     |  1 +
 trytond/model/fields/field.py |  9 +++++++++
 trytond/model/modelview.py    |  7 ++++++-
 3 files changed, 16 insertions(+), 1 deletions(-)

diffs (44 lines):

diff -r 34ec4c3b700c -r 92c25177eff1 CHANGELOG
--- a/CHANGELOG Mon Apr 08 10:10:40 2019 +0200
+++ b/CHANGELOG Mon Apr 08 10:14:39 2019 +0200
@@ -1,3 +1,4 @@
+* Do not set id for on_change calls if cached
 * Add cache on RPC
 * Remove support for Python 3.4
 * Allow to update record when importing data
diff -r 34ec4c3b700c -r 92c25177eff1 trytond/model/fields/field.py
--- a/trytond/model/fields/field.py     Mon Apr 08 10:10:40 2019 +0200
+++ b/trytond/model/fields/field.py     Mon Apr 08 10:14:39 2019 +0200
@@ -435,6 +435,15 @@
             'sortable': hasattr(model, 'search'),
             }
 
+        # Add id to on_change's if they are not cached
+        # Not having the id increase the efficiency of the cache
+        for method in ['on_change', 'on_change_with']:
+            changes = definition[method]
+            if changes:
+                method_name = method + '_' + self.name
+                if not model.__rpc__[method_name].cache:
+                    changes.append('id')
+
         name = '%s,%s' % (model.__name__, self.name)
         for attr, ttype in [('string', 'field'), ('help', 'help')]:
             definition[attr] = ''
diff -r 34ec4c3b700c -r 92c25177eff1 trytond/model/modelview.py
--- a/trytond/model/modelview.py        Mon Apr 08 10:10:40 2019 +0200
+++ b/trytond/model/modelview.py        Mon Apr 08 10:14:39 2019 +0200
@@ -603,7 +603,12 @@
 
             change = cls.__change_buttons[button_name]
             if change:
-                element.set('change', encoder.encode(list(change)))
+                change = list(change)
+                # Add id to change if the button is not cached
+                # Not having the id increase the efficiency of the cache
+                if cls.__rpc__[button_name].cache:
+                    change.append('id')
+                element.set('change', encoder.encode(change))
             if not is_instance_method(cls, button_name):
                 element.set('type', 'class')
             else:

Reply via email to