fieldstoreodooopenerp-8

Odoo 8 - Compute Field with "store=True" can't store in database


I'm using Odoo 8 and I have a problem with compute field with type is Many2One.

Here, I declared department_id:

department_id = fields.Text(
    string="Department", store=True,
    comodel_name="hr.department",
    compute="_get_department_id"
)

And fuction of this compute field:

@api.depends('employee_id')
def _get_department_id(self):
    if self.employee_id.department_id:
        self.department_id = self.employee_id.department_id.name

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.

My question is: how can I store the department_id in database?

Notes:


Solution

  • 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.