Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
Last active February 17, 2020 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sehrishnaz/fca1ac801f4c48ee795276ea93cf14c7 to your computer and use it in GitHub Desktop.
Save sehrishnaz/fca1ac801f4c48ee795276ea93cf14c7 to your computer and use it in GitHub Desktop.
OdooServerAction Python Code
@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,
}
@sehrishnaz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment