Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5691 Vistas

I created a Module "A" that inherits the odoo module "projects"

odoo projects has a field "allowed_user_ids" that is computed and depends on 2 fields.

Inheriting the compute method works fine but changing the @api.depends annotation to add 1 additional field has no effect, the overrided method still only depends on the 2 old fields.

the project module:
allowed_user_ids = fields.Many2many('res.users', compute='_compute_allowed_users', inverse='_inverse_allowed_user')
allowed_internal_user_ids=fields.Many2many('res.users','project_allowed_internal_users_rel'string="Allowed Internal Users", default=lambdaself: self.env.user, domain=[('share', '=', False)])
allowed_portal_user_ids = fields.Many2many('res.users', 'project_allowed_portal_users_rel', string="Allowed Portal Users", domain=[('share', '=', True)])
@api.depends('allowed_internal_user_ids', 'allowed_portal_user_ids')    def_compute_allowed_users(self):
for 
project in self:
users
= project.allowed_internal_user_ids | project.allowed_portal_user_ids            project.allowed_user_ids = users

my module:
@api.depends('allowed_internal_user_ids','allowed_portal_user_ids','myfield')    def_compute_allowed_users(self):
print('override')


Would be great if someone can point me in the right direction on what i might be understanding or doing worng. 

Avatar
Descartar
Mejor respuesta

In project object there is one condition for depends fields for update value in allowed_users, so also you need to add custom field in that conditon for update allowed_users field, and once this field update the compute method will be called... 

def write(self, vals):
allowed_users_changed = 'allowed_portal_user_ids' in vals or 'allowed_internal_user_ids' in vals
if allowed_users_changed:
allowed_users = {project: project.allowed_user_ids for project in self} 

Just copy below code for write method and check it will work :

def write(self, vals):
allowed_users_changed = 'myfield' in vals
if allowed_users_changed:
{project: project.allowed_user_ids for project in self}
res = super(Project, self).write(vals)
return res

Thank you


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
dic 21
5027
1
jul 21
3601
4
mar 24
3312
2
mar 24
1847
1
oct 23
5267