Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
5703 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 21
5038
1
jul. 21
3608
4
mrt. 24
3332
2
mrt. 24
1865
1
okt. 23
5304