繁体   English   中英

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

[英]Call Python function in window action odoo

我将此 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>

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

服务器操作的代码应该是这样的:

action = env.ref('hr_holidays.open_allocation_holidays').read()[0]
domain = model._get_holiday_status_id_domain()
action['domain'] = domain

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM