2016-06-13 57 views
1
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,字符串= '索引內容',類型=「文本「),我怎樣才能解決這個錯誤:預期單candidat(1,2,3,4)

我得到了預期singleton candidat.base(1,2,3,4)作爲錯誤。

+0

您收到多個結果嗎? –

+0

是的,我有可能從https://github.com/odoo/odoo/issues/4377 收到多個結果 – Khadija

+0

它說「_行爲被改變爲不允許從具有多個記錄的記錄集中讀取。」 –

回答

1
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個條目的記錄集,其中您不能調用像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) 

並可能使用一些線,使代碼更易讀。

+1

它是謝謝@CZoellner – Khadija

相關問題