changeset bb821b08ba73 in trytond:5.0
details: https://hg.tryton.org/trytond?cmd=changeset;node=bb821b08ba73
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 a74485c9bbae -r bb821b08ba73 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
@@ -86,7 +86,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