changeset 1fefe6d2f903 in proteus:4.8
details: https://hg.tryton.org/proteus?cmd=changeset;node=1fefe6d2f903
description:
        Do not send empty x2Many fields when saving

        issue8588
        review264091002
        (grafted from 25198402e9f72c848b450c7ca6398fbbc442dcf2)
diffstat:

 proteus/__init__.py |  16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diffs (26 lines):

diff -r 49358331105c -r 1fefe6d2f903 proteus/__init__.py
--- a/proteus/__init__.py       Mon Apr 22 10:40:32 2019 +0200
+++ b/proteus/__init__.py       Sat Aug 31 01:40:47 2019 +0200
@@ -893,8 +893,20 @@
         'Return dictionary values'
         if fields is None:
             fields = self._values.keys()
-        return dict((x, getattr(self, '__%s_value' % x)) for x in fields
-                if x not in ('id', '_timestamp'))
+        values = {}
+        for name in fields:
+            if name in ['id', '_timestamp']:
+                continue
+            definition = self._fields[name]
+            if definition.get('readonly') and definition['type'] != 'one2many':
+                continue
+            values[name] = getattr(self, '__%s_value' % name)
+            # Sending an empty X2Many fields breaks ModelFieldAccess.check
+            if (definition['type'] in {'one2many', 'many2many'}
+                    and not values[name]):
+                breakpoint()
+                del values[name]
+        return values
 
     @property
     def _timestamp(self):

Reply via email to