Search code examples
odooodoo-12

Custom ir.actions.server


I am trying to make a custom ir.actions.server for a model like this

<?xml version="1.0"?>
<odoo>
<data>

<record model="ir.actions.server" id="action_recruitment_request_filter">
    <field name="name">Filter</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="fhid_recruitment.model_recruitment_request"/>
    <field name="state">code</field>
    <field name="code">action = model.my_action()</field>
</record>

And in the model like this

class RecruitmentRequest(models.Model):
    _name = 'recruitment.request'

    @api.multi
    def my_action(self):
        # import pdb; pdb.set_trace()
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'recruitment.request',
            'view_type': 'form',
            'view_mode': 'tree,form',
            'target': 'current',
            'context': {
                'search_default_my_requests': 1
            }
        }

But I cannot see this function taking effect to the view. Even if I uncomment the set_trace() I don't see it enter the method. What am I missing here?

Here is the menu with the action

<record model="ir.actions.act_window" id="action_hr_recruitment_request">
    <field name="name">Requests</field>
    <field name="res_model">recruitment.request</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="form_view_id" ref="recruitment_request_form_view" />
    <field name="search_view_id" ref="hr_recruitment_request_view_search" />
    <field name="view_id" ref="hr_recruitment_request_tree" />
    <field name="context"></field>
    <!-- <field name="context" eval="{'search_default_by_responsible': 1}" /> -->
    <field name="help" type="html">
        <p class="o_view_nocontent_smiling_face">
            Create the first recruitment request
        </p><p>

        </p>
    </field>
</record>

<menuitem parent="hr_recruitment.menu_hr_recruitment_root" id="menu_hr_recruitment_request" 
    action="action_hr_recruitment_request" name="Requests" sequence="-1" />

Solution

  • Your server action has to be used in the <menuitem> as action.