gpt4 book ai didi

python - 我该如何解决这个错误: Expected singleton candidat(1, 2,3,4)

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:38 25 4
gpt4 key购买 nike

def _get_index_content(self, cr, uid, ids, fields, args, context=None):
res = dict.fromkeys(ids, '')
Attachment = self.pool.get('ir.attachment')
applicant_ids = self.pool.get('hr.applicant').search(cr, uid, [('email_from', '=', self.browse(cr, uid, ids, context=context).email_candidat)], context=context)
attachment_ids = Attachment.search(cr, uid, ['|', '&', ('res_model', '=', 'candidat.base'), ('res_id', 'in', ids), '&', ('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)], context=context)
for attachment in Attachment.browse(cr, uid, attachment_ids, context=context):
res[attachment.res_id] += attachment.index_content or ''
return res


def _content_search(self, cr, user, obj, name, args, context=None):
record_ids = set()
Attachment = self.pool.get('ir.attachment')
ids = obj.search(cr, uid, [])
applicant_ids = self.pool.get('hr.applicant').search(cr, user, [('email_from', '=', self.browse(cr, user, ids, context=context).email_candidat)], context=context)
args = ['&'] + args + ['|', '&', ('res_model', '=', 'candidat.base'), ('res_id', 'in', ids), '&', ('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)]
att_ids = Attachment.search(cr, user, args, context=context)
record_ids = set(att.res_id for att in Attachment.browse(cr, user, att_ids, context=context))
return [('id', 'in', list(record_ids))]

'index_content': fields.function(_get_index_content,fnct_search=_content_search, string='索引内容', type="text"),

我得到 Expected singleton candidat.base(1,2,3,4) 作为错误。

最佳答案

applicant_ids = self.pool.get('hr.applicant').search(cr, user, [('email_from', '=', self.browse(cr, user, ids, context=context).email_candidat)], context=context)

如果 ids 是 2 个或更多 ID 的列表,则不起作用。浏览将获得一个包含 2 个条目的 RecordSet,您无法在其中调用 email_candidat 等字段值。

尝试搜索所有电子邮件地址,例如:

applicant_ids = self.pool.get('hr.applicant').search(cr, user, [('email_from', 'in', [x.email_candidat for x in self.browse(cr, user, ids, context=context)])], context=context)

也许可以使用更多行来使代码更具可读性。

关于python - 我该如何解决这个错误: Expected singleton candidat(1, 2,3,4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37793063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com