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
as you see in the image the value is always blank
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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.