Odoo12源码的model模型中有这样一段代码:含义为如果模型中有active字段、并且context上下文中获取到'active_test'=True时查询domain条件中会添加 active=True 条件。
# if the object has a field named 'active', filter out all inactive
# records unless they were explicitely asked for
if 'active' in self._fields and active_test and self._context.get('active_test', True):
# the item[0] trick below works for domain items and '&'/'|'/'!'
# operators too
if not any(item[0] == 'active' for item in domain):
domain = [('active', '=', 1)] + domain
所以这段代码产生的效果就是当模型中有active字段存在时,当active值为False时,Odoo会把active字段为False的记录过滤掉。
解决办法如下:根据具体代码情况,向context中添加 {'active_test': False},这样就会失效掉这段代码,从而达到显示active=False的记录。
代码如下:
向action中context添加 {'active_test': False}。
添加 {'active_test': False} 之后,升级模块,当点击菜单触发action之后就会看到'active'=False的记录了。