Last active
February 17, 2020 06:23
-
-
Save sehrishnaz/fca1ac801f4c48ee795276ea93cf14c7 to your computer and use it in GitHub Desktop.
OdooServerAction Python Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@api.multi | |
def get_filtered_record(self): | |
if self._context.get('params', False): | |
params = self._context.get('params', False) | |
if params.get('menu_id', False): | |
raise ValidationError( | |
"Attention:You are not allowed to access this page due to Security Policy. In case of any query, please contact ERP Admin or Configuration Manager.") | |
else: | |
return False | |
view_id_form = self.env['ir.ui.view'].search([('name', '=', 'your.form.view.name')]) | |
view_id_tree = self.env['ir.ui.view'].search([('name', '=', 'your.tree.view.name')]) | |
group_pool = self.env['res.groups'] | |
user = self.env['res.users'].browse(self._uid) | |
employee_pool = self.env['hr.employee'] | |
employee = employee_pool.search([('user_id', '=', user.id)]) | |
if user.has_group('base.group_erp_manager'): | |
record_ids = self.env['your.model.name'].search([]).ids | |
if user.has_group('base.group_hr_user'): | |
record_ids = self.env['your.model.name'].search([('company_id', '=', employee.company_id.id)]).ids | |
else: | |
record_ids = employee.ids | |
return { | |
'type': 'ir.actions.act_window', | |
# 'name': _('Product'), | |
'res_model': 'your.model.name', | |
'view_type': 'form', | |
'view_mode': 'tree,form', | |
# 'view_id': view_id_tree.id, | |
'views': [(view_id_tree.id, 'tree'), (view_id_form.id, 'form')], | |
'target': 'current', | |
'domain': [('id', 'in', record_ids)] | |
# 'res_id': your.model.id, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more in detail:
Odoo Server Action
Show Records in Tree View related to active user