Odoo可以显示一个在菜单后边显示一个提示性数子,提示用户有多少个待处理文档
为了实现这样的效果,先要在自己的 model 继承ir.needaction_mixin:
_inherit = ['ir.needaction_mixin']
然后你需要定义一个方法 _needaction_domain_get,返回一个记录的集合.记录的个数将显示在菜单上
@api.model
def _needaction_domain_get(self):
return [('state', '=', 'new')]
[('id', '!=', 0)] 代表查询表里所有记录
@api.model
def _needaction_domain_get(self):
if self._context.get('approve_type'):
return [('id', '!=', 0)]
完整代码如下:
class Horse(models.Model):
_name = 'horse'
_inherit = ['ir.needaction_mixin']
STATES = [
('healthy', u"正常的马"),
('sick', u"出轨的马)"),
]
name = fields.Char(required=True)
state = fields.Selection(STATES, default='healthy')
@api.model
def _needaction_domain_get(self):
return [('state', '=', 'sick')]