Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5795 Lượt xem

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. 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 21
5122
1
thg 7 21
3698
4
thg 3 24
3423
2
thg 3 24
1964
1
thg 10 23
5374