我正在尝试创建一个功能字段
class base_candidat_specialite(osv.osv):
""" Spécialité du candidat """
_name = "base.candidat.specialite"
_description = "Spécialité du candidat"
_columns = {
'name': fields.char('Name', required=True),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of degrees."),
}
_defaults = {
'sequence': 1,
}
_sql_constraints = [
('name_uniq', 'unique (name)', 'Le nom de la specialité doit etre unique')
]
class base_candidat(osv.osv):
_name = 'base.candidat'
def _application(self, cr, uid, ids, fields, arg, context=None):
res = {}
_candidat = self.pool.get('base.candidat')
candidat = _candidat.browse(cr, uid, ids[0], context=context)
_application = self.pool.get('hr.applicant')
if candidat:
for _obj in self.browse(cr, uid, ids, context=context):
_applications = _application.search(cr, uid, [('email_from', '=', candidat.email_candidat)], context=context)
res[_obj.id] = [(6, 0, _applications)]
return res
_colunms{
'candidat_name': fields.char('Candidat', size=128, required=True),
'active': fields.boolean('Active', help="If a candidat is not active, it will not be displayed in module"),
'blacklist': fields.boolean('Blacklist'),
'email_candidat': fields.char('Email', size=32),
'mobile': fields.char('Mobile', size=32),
'description': fields.text('Description'),
'probability': fields.float('Probability'),
'create_date': fields.datetime('Creation Date', readonly=True, select=True),
'write_date': fields.datetime('Update Date', readonly=True),
'date_closed': fields.datetime('Closed', readonly=True, select=True),
'date_open': fields.datetime('Assigned', readonly=True, select=True),
'date_action': fields.date('Next Action Date'),
'title_action': fields.char('Next Action', size=64),
'reference': fields.char('Referred By'),
'user_id': fields.many2one('res.users', 'Responsable'),
'specialite': fields.many2one('base.candidat.specialite', 'Specialite'),
'liensource': fields.char('Lien Source'),
'type_id': fields.many2one('hr.recruitment.degree', 'Niveau de formation'),
'niveau_experience': fields.many2one('hr.recruitment.degree', 'Niveau d"experience'),
'source_id': fields.many2one('hr.recruitment.source', 'Source'),
'categ_ids': fields.many2many('hr.applicant_category', string='Tags'),
'candidature_ids': fields.function(_application, string="Candidature", type="one2many", relation='hr.applicant'),
}
创建记录时出错
ProgrammingError:ARRAY类型整数和布尔值无法匹配 第1行:...... bourkia','abourkiakhadija',true,ARRAY [ARRAY [6,false, “{} ...
答案 0 :(得分:1)
预期的返回值是字典,键是记录ID,值是简单ID的列表。
例如:{1:[23,32,41],5:[],78:[234,55,56,78,343,55]}
您的代码无法使用,因为密钥必须包含base_base_candidat
的所有内容,并且值必须包含来自hr.applicant
的ID。
所以这段代码在这里打破了:ids[0]
。
我无法通过魔术参数[(6, '0', _applications)]
了解您的代码。
如果您编写想要编码的内容,我会帮助您更多!
答案 1 :(得分:-1)
您应该声明您的功能字段:
'candidature_ids': fields.function(_application, method=True, string="Candidature", type="many2many", relation='hr.applicant')
方法:
def _application(self, cr, uid, ids, fields, arg, context=None):
app_obj = self.pool.get('hr.applicant')
res = {}
for cand in self.browse(cr, uid, ids, context=context):
res[cand.id] = [(6, 0, app_obj.search(cr, uid, [
('email_from', '=', cand.email_candidat),
], context=context)
return res