Computed field on a tree view in odoo 12

Viewed 1596

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

2 Answers

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

You have to iterate over the records and assign some value to it, check the code below.

@api.multi
def _roles_assigned(self):
    for rec in self:
        rec.assigned = 'assign your value here'
Related