在窗口动作odoo中调用Python函数

问题描述 投票:0回答:1

我将此python函数添加到'hr.holidays'模型中

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'))]

我想在动作id =“ hr_holidays.open_allocation_holidays'中调用此函数,以便在动作运行时仍然执行。

<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>

我将此Python函数添加到hr.holidays模型类InheritHrHolidays(models.Model):_inherit ='hr.holidays'def _get_holiday_status_id_domain(self):如果不是self.env.user.has_group('...] >

python python-3.x xml odoo odoo-11
1个回答
0
投票

您不能在窗口动作中调用函数,而是必须创建例如服务器动作(带有代码),然后应由菜单项调用或使用该动作。在该服务器操作中,您可以使用原始的窗口操作,但可以通过功能中的域进行操作。

服务器操作的代码应如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.