Odoo 8-计算字段为"store = True"无法存储在数据库中 [英] Odoo 8 - Compute Field with "store=True" can't store in database

查看:1068
本文介绍了Odoo 8-计算字段为"store = True"无法存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Odoo 8,而类型为Many2Onecompute 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,但是它没有将该字段的值存储在数据库中.
  • 我做了一个测试.我添加类型为Textcompute_field,它可以正常工作,我不知道为什么计算字段不适用于类型为Many2One的计算机.

  • In the declaration of department_id, I set store=True, but it did NOT store the value of this field in database.
  • I did a test. I add compute_field with type Text, It works, I don't know why compute field doesn't work with type Many2One.

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆