Odoo 8-计算字段为"store = True"无法存储在数据库中 [英] Odoo 8 - Compute Field with "store=True" can't store in database
问题描述
我正在使用Odoo 8
,而类型为Many2One
的compute field
出现问题.
I'm using Odoo 8
and I have a problem with compute field
with type is Many2One
.
在这里,我声明了department_id
:
department_id = fields.Text(
string="Department", store=True,
comodel_name="hr.department",
compute="_get_department_id"
)
此计算字段的功能:
@api.depends('employee_id')
def _get_department_id(self):
if self.employee_id.department_id:
self.department_id = self.employee_id.department_id.name
现在似乎可以正常工作,但事实并非如此.在视图中,我可以看到department_id
的值.但是在数据库中,该表没有列department_id
,也没有该列的值.
It seems to work right now, but it's not. In view, I can see the value of department_id
. But in the database, the table has no column department_id
and has no value of this column.
我的问题是:如何将department_id
存储在数据库中?
My question is: how can I store the department_id
in database?
注意:
- 在
department_id
的声明中,我设置了store=True
,但是它没有将该字段的值存储在数据库中. -
我做了一个测试.我添加类型为
Text
的compute_field
,它可以正常工作,我不知道为什么计算字段不适用于类型为Many2One
的计算机.
- In the declaration of
department_id
, I setstore=True
, but it did NOT store the value of this field in database. I did a test. I add
compute_field
with typeText
, It works, I don't know why compute field doesn't work with typeMany2One
.
@api.depends('employee_id')
def _get_compute_field(self):
if self.employee_id.department_id:
self.compute_field = self.employee_id.department_id.name
compute_field = fields.Text(
string="Compute Field", store=True,
compute="_get_compute_field"
)
推荐答案
store=True
有效.
可能是您在数据库上创建了计算之后将计算添加到了该字段.在这种情况下,不会触发初始计算.
The store=True
works.
It may be that you added the computation to the field after it was created on the database. In this case the initial computation is not triggered.
一种解决方法是从表中删除该列,然后升级您的模块.重新创建该字段时,应计算初始值.
A work around is to drop the column from the table and then upgrade your module. When the field is recreated the initial values should be computed.
这篇关于Odoo 8-计算字段为"store = True"无法存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!