Skip to Content
Menu
This question has been flagged
10678 Views

I added this python function to 'hr.holidays' model

class InheritHrHolidays(models.Model):
_inherit = 'hr.holidays'

def _get_holiday_status_id_domain(self):
if not self.env.user.has_group('hr_holidays.group_hr_holidays_user'):
allocate_type = self.env['hr.holidays.status'].search([('name', '=', 'Compensatory Days')], limit=1)
return [('id', '=', allocate_type.id)]
elif self.env.user.has_group('hr_holidays.group_hr_holidays_user') and not self.env.user.has_group(
'hr_holidays.group_hr_holidays_manager'):
allocation_types = self.env['hr.holidays.status'].search([('name', '!=', 'Unpaid')])
return [('id', 'in', allocation_types.mapped('id'))]

I want to inherit this action and call this function in it


<record id="open_allocation_holidays" model="ir.actions.act_window">
<field name="name">Allocation Request</field>
<field name="res_model">hr.holidays</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,form</field>
<field name="context">{
'default_type':'add',
'search_default_my_leaves': 1,
'needaction_menu_ref':
[
'hr_holidays.menu_open_company_allocation',
]
}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click here to create a new leave allocation request.
</p>
</field>
<field name="domain">[('type','=','add')]</field>
<field name="view_id" ref="edit_holiday_new"/>
<field name="search_view_id" ref="view_hr_holidays_filter"/>
</record>
Avatar
Discard

You can execute python code only in server action.

You could use a controller to generate an URL, then generate a url action to call that URL and in that controller you call your method. Or if you need pass a domain for a field, you could return something like this " return {'domain': {'field_name': [('id', 'in', array_of_ids)]}} "

Why do you need to execute the method in an action??

You can pass the domain direct to a field in a model.

Related Posts Replies Views Activity
0
Sep 18
2171
0
Nov 23
749
2
Feb 24
13186
1
Dec 22
3859
2
Dec 22
12723