I have the following function in the class hr_evaluation_interview
:
我在hr_evaluation_interview类中有以下函数:
@api.onchange('evaluation_id')
def onchange_evalID(self):
self.deadline=self.env.cr.execute('SELECT date FROM hr_evaluation_evaluation where id=119')
Note: I'm just giving id=119
in the query for testing purposes.
注意:我只是在查询中给出id = 119以进行测试。
When I give self.deadline=datetime.now.strftime(%Y-%m-%d %H:%M:%S")
it works fine and changes the value of field deadline
when the value of field evaluation_id
changes. Again for just testing.
当我给self.deadline = datetime.now.strftime(%Y-%m-%d%H:%M:%S“)时,它工作正常,并在字段evaluation_id的值发生变化时更改字段截止时间的值。只是测试。
What I really need is to execute a query similar to what I mentioned. However when I execute this query nothing is printing on the deadline
field. When I check the log I see this warning:
我真正需要的是执行类似于我提到的查询。但是,当我执行此查询时,没有在截止日期字段上打印。当我检查日志时,我看到了这个警告:
WARNING db_name openerp.models: Cannot execute name_search, no _rec_name defined on hr_evaluation.evaluation
I tried checking online why this warning, but got no help. Am I doing something wrong? How exactly can I execute query from within @api.onchange(self)
?
我试着在网上查看为什么这个警告,但没有得到帮助。难道我做错了什么?我怎样才能从@ api.onchange(self)中执行查询?
2 个解决方案
#1
5
As Hardik said, cr.execute()
doesn't return directly you result. You need to fetch the values from the cursor after executing the query. Try like this:
正如Hardik所说,cr.execute()不直接返回你的结果。您需要在执行查询后从游标中获取值。试试这样:
@api.onchange('evaluation_id')
def onchange_evalID(self):
self.env.cr.execute('SELECT date '
'FROM hr_evaluation_evaluation where id=119')
self.deadline = self.env.cr.fetchone()[0]
#2
1
If evaluation_id
is m2o
field of hr.evaluation.evaluation
model you can try below code. you don't need to execute query at all.
如果evaluation_id是hr.evaluation.evaluation模型的m2o字段,您可以尝试下面的代码。你根本不需要执行查询。
@api.onchange('evaluation_id')
def onchange_evalID(self):
if self.evaluation_id and self.evaluation_id.date:
self.date = self.evaluation_id.date
#1
5
As Hardik said, cr.execute()
doesn't return directly you result. You need to fetch the values from the cursor after executing the query. Try like this:
正如Hardik所说,cr.execute()不直接返回你的结果。您需要在执行查询后从游标中获取值。试试这样:
@api.onchange('evaluation_id')
def onchange_evalID(self):
self.env.cr.execute('SELECT date '
'FROM hr_evaluation_evaluation where id=119')
self.deadline = self.env.cr.fetchone()[0]
#2
1
If evaluation_id
is m2o
field of hr.evaluation.evaluation
model you can try below code. you don't need to execute query at all.
如果evaluation_id是hr.evaluation.evaluation模型的m2o字段,您可以尝试下面的代码。你根本不需要执行查询。
@api.onchange('evaluation_id')
def onchange_evalID(self):
if self.evaluation_id and self.evaluation_id.date:
self.date = self.evaluation_id.date