Search code examples
pythonodooodoo-12

Computed field on a tree view in odoo 12


I'm trying to compute a value to be displayed in a tree view, the problem is that my private function never gets executed and not setting the value for my computed field.

I've simplified the following code:

class ProjectProject(models.Model):
    _inherit = "project.project"
    assigned = fields.Char(string='Assigned multi', compute='_roles_assigned', store=False)

    @api.multi
    @api.depends('task_ids')
    def _roles_assigned(self):
        #do dome calculations
        assigned = ' test of 1' #'0 / {total}'.format(total=total)
        return assigned

tree view

as you see in the image the value is always blank


Solution

  • When we display computed field in tree view, it will have multiple records set. So we have to set value for each record set.

    Try with following code:

    @api.multi
    def _roles_assigned(self):
        #do dome calculations
        for record in self:
            assigned = ' test of 1' #'0 / {total}'.format(total=total)
            record.assigned = assigned