تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4972 أدوات العرض

I want to make a field required, but to not break the workflow from before the field was required. I want to make it required only after a specific date.

<field name="create_date" invisible="1"/>
<field name="customer_answer" nolabel="1" attrs="{'required': [('create_date', '&gt;', '2019-11-18 8:00:00')]}"/>

I've tried it with the above example and with one with '>' but it doesn't work. Can I even do this?


الصورة الرمزية
إهمال
أفضل إجابة

If I'm not mistaken 'datetime' is not passed to form views (only to search views). So, the simpliest way to achieve your goal is to calculate the criteria in Python. Something like:

def _compute_hide_answer(self):
 to_compare_date = fields.Datetime.from_string('2019-11-18 8:00:00') # date might have different formar
for record in self:
record.hide_answer = record.create_date < to_compare_date

hide_answer = fields.Boolean(compute=_compute_hide_answer,)


<field name="hide_answer" invisible="1"/>
<field name="customer_answer" nolabel="1" attrs="{'required': [('hide_answer', '=', False)]}"/>


الصورة الرمزية
إهمال
الكاتب

yeah... I know that I can make it this way, but I didn't want to change the python code/model. Wanted to do it in the view.

I'm afraid it is not possible in that way. In search view you can use datetime.strftime, but it form view it is not available (If I'm not mistaken - otherwise something like [('create_date', '&gt;', datetime.strftime('2019-11-18 8:00:00'))] should work.

الكاتب

Yeah... you're right. I've to do it in python.

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
يونيو 19
3322
1
أبريل 19
4165
2
نوفمبر 18
5187
1
يوليو 17
14555
1
ديسمبر 16
7866