我的记录只能在给定日期之前修改(在字段中)。
我考虑过使用记录规则,但无法将日期字段与访问规则中的当前日期进行比较。
有什么方法可以做比较或其他方式来实现这个目标?
<record id="my_rule_date_foo" model="ir.rule">
<field name="name">foo bar</field>
<field name="model_id" ref="model_my_foo"/>
<field name="domain_force">
[('many2one_field.the_limit_date','≥', 'what_to_put_here_?')]
</field>
<field name="groups" eval="[(4, ref('group_peff'))]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
你应该能够在context_today()
中使用datetime
或domain_force
:
# Should be the best choice, considers user timezone
[('many2one_field.the_limit_date','>=', context_today())]
# If context_today() doesn't work for some reason, you can use datetime
[('many2one_field.the_limit_date','>=', datetime.date.today().strftime('%Y-%m-%d'))]
这是来自核心和the context_today
method的relevant gist for reference。