如何在字段访问规则[odoo 10]中将日期字段与当前日期进行比较

问题描述 投票:0回答:1

我的记录只能在给定日期之前修改(在字段中)。

我考虑过使用记录规则,但无法将日期字段与访问规则中的当前日期进行比较。

有什么方法可以做比较或其他方式来实现这个目标?

<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','&ge;', '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"/>

openerp odoo-10
1个回答
1
投票

你应该能够在context_today()中使用datetimedomain_force

# Should be the best choice, considers user timezone
[('many2one_field.the_limit_date','&gt;=', context_today())]

# If context_today() doesn't work for some reason, you can use datetime
[('many2one_field.the_limit_date','&gt;=', datetime.date.today().strftime('%Y-%m-%d'))]

这是来自核心和the context_today methodrelevant gist for reference

© www.soinside.com 2019 - 2024. All rights reserved.