Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5963 มุมมอง

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. 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 21
5310
1
ก.ค. 21
3815
4
มี.ค. 24
3645
2
มี.ค. 24
2091
1
ต.ค. 23
5543