changeset fc3a251dae3a in trytond:5.6
details: https://hg.tryton.org/trytond?cmd=changeset;node=fc3a251dae3a
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 f4497659144c -r fc3a251dae3a 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
@@ -88,7 +88,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: