Hi guys, how can I change a compulsory field to an optional field on the sample? For example the “Date Sampled”. I tried to add required=0 on the field in the analysisrequest.py but it doesn’t work.
I change
DateTimeField(
'DateSampled',
mode="rw",
read_permission=View,
write_permission=FieldEditDateSampled,
widget=DateTimeWidget(
label=_("Date Sampled"),
description=_("The date when the sample was taken"),
size=20,
show_time=True,
datepicker_nofuture=1,
visible={
'add': 'edit',
'secondary': 'disabled',
'header_table': 'prominent',
},
render_own_label=True,
),
),
To
DateTimeField(
'DateSampled',
mode="rw",
required=0,
read_permission=View,
write_permission=FieldEditDateSampled,
widget=DateTimeWidget(
label=_("Date Sampled"),
description=_("The date when the sample was taken"),
size=20,
show_time=True,
datepicker_nofuture=1,
visible={
'add': 'edit',
'secondary': 'disabled',
'header_table': 'prominent',
},
render_own_label=True,
),
),
By general rule adding the required=False
statement in a content type field should be enough to mark it as optional, but some fields save data required by the system. DateSampled
can be one of them because its visibility is modified based on active workflows: senaite.core/widgetvisibility.py at 1f82dcfacb151e764b4ddad330c536714bfa7c20 · senaite/senaite.core · GitHub
I am pointing to some other fragments of code I found after a quick search. Please, do not take them as a final answer, but for some guidance!
-
Sample’s workflow test: senaite.core/WorkflowAnalysisRequestSample.rst at 1f82dcfacb151e764b4ddad330c536714bfa7c20 · senaite/senaite.core · GitHub
-
Sample’s (analysis request) transition guards: senaite.core/guards.py at 1.3.x · senaite/senaite.core · GitHub
-
Transitions and guards defined for Sample workflow:
Thank you very much, it’s very helpful