74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
from odoo import api, fields, models
|
|
from odoo.http import request
|
|
|
|
|
|
class ResGroups(models.Model):
|
|
_inherit = 'res.groups'
|
|
|
|
is_visible_for_master = fields.Boolean(
|
|
compute='_compute_is_visible_for_master',
|
|
search='_search_is_visible_for_master'
|
|
)
|
|
|
|
@api.depends_context('active_master')
|
|
def _compute_is_visible_for_master(self):
|
|
master_code = request.session.active_master
|
|
if not master_code:
|
|
self.update({'is_visible_for_master': True})
|
|
return
|
|
|
|
master_control = self.env['master.control'].sudo().search([
|
|
('code', '=', master_code)
|
|
], limit=1)
|
|
|
|
if not master_control:
|
|
self.update({'is_visible_for_master': True})
|
|
return
|
|
|
|
# If NO access_group_ids -> show ALL groups
|
|
if not master_control.access_group_ids:
|
|
self.update({'is_visible_for_master': True})
|
|
return
|
|
|
|
visible_group_ids = master_control.access_group_ids.filtered(
|
|
lambda line: line.show_group
|
|
).mapped('group_id').ids
|
|
|
|
# If there are no 'show_group = True' -> show ALL groups
|
|
if not visible_group_ids:
|
|
self.update({'is_visible_for_master': True})
|
|
return
|
|
|
|
for group in self:
|
|
group.is_visible_for_master = group.id in visible_group_ids
|
|
|
|
|
|
def _search_is_visible_for_master(self, operator, value):
|
|
if operator != '=' or not value:
|
|
return []
|
|
|
|
master_code = request.session.active_master
|
|
if not master_code:
|
|
return []
|
|
|
|
master_control = self.env['master.control'].sudo().search([
|
|
('code', '=', master_code)
|
|
], limit=1)
|
|
|
|
if not master_control:
|
|
return []
|
|
|
|
# If NO access_group_ids → show ALL groups → no domain filter
|
|
if not master_control.access_group_ids:
|
|
return []
|
|
|
|
visible_group_ids = master_control.access_group_ids.filtered(
|
|
lambda line: line.show_group
|
|
).mapped('group_id').ids
|
|
|
|
# If none of the lines have show_group=True → show ALL
|
|
if not visible_group_ids:
|
|
return []
|
|
|
|
return [('id', 'in', visible_group_ids)]
|