Expected singleton: hr.employee(1, 2)

那年仲夏 提交于 2019-12-06 16:40:44

I don't know the relationship between hr.employee and hr.employee_documents. If this one is a One2many (many documents for a unique employee), there must be a One2many field in hr.employee model pointing to hr.employee_documents. Suppose this field is named documents (this is important to trigger the compute method through the api.depends). Then write this code:

@api.multi
@api.depends('documents.date_expiry')
def getdocumentStatus(self):
    server_date = datetime.datetime.strptime(DATE_NOW.strftime("%Y-%m-%d"), "%Y-%m-%d")
    for record in self:
        totaldoc = self.env['hr.employee_documents'].search_count([('date_expiry', '<', server_date),('employee_doc_id','=', self.id)])
        if totaldoc > 0:
            record.documents_status = True
        else:
            record.documents_status = False

You should write us the relationship between both models to give you an accurate answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!