changeset 553562d4fc2a in trytond:5.4
details: https://hg.tryton.org/trytond?cmd=changeset;node=553562d4fc2a
description:
        Set default value for missing depends field

        This avoid to fill an instance with None value which will prevent it to 
be
        saved with the default value for fields not explicitly assigned.

        issue9726
        review314481004
        (grafted from 65b6783a3b63d45f751c79278bd3cb186218ba46)
diffstat:

 trytond/model/fields/field.py |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diffs (15 lines):

diff -r 5565e0736e7f -r 553562d4fc2a trytond/model/fields/field.py
--- a/trytond/model/fields/field.py     Wed Oct 14 14:43:40 2020 +0200
+++ b/trytond/model/fields/field.py     Wed Oct 21 23:23:17 2020 +0200
@@ -89,7 +89,10 @@
     if field.startswith('_parent_'):
         field = field[8:]  # Strip '_parent_'
     if not hasattr(record, field):
-        setattr(record, field, None)
+        default = None
+        if hasattr(record, '_defaults') and field in record._defaults:
+            default = record._defaults[field]()
+        setattr(record, field, default)
     elif nested:
         parent = getattr(record, field)
         if parent:

Reply via email to