Stefani Johnsson
Stefani Johnsson

Reputation: 431

Call or add function in act_window xml in odoo

I was try to add a new label on report button on tree. The button will display after choose the one of tree data. I did it. And i build a function for executed after click the button. The problem is, i don't how to call the function inside act_windows.

<act_window
id="action_report"
name="Print Report"
res_model="model.report"
key2="client_print_multi"
src_model="model.report"/>

How to call a fucntion (def) in that. thank you.

Upvotes: 3

Views: 3691

Answers (1)

CZoellner
CZoellner

Reputation: 14776

Look into ìr.actions.server and look how they work. A nice example from Odoo itself:

    <record id="hr_expense_submit_action_server" model="ir.actions.server">
        <field name="name">Expense: Submit To Manager</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_hr_expense"/>
        <field name="binding_model_id" ref="model_hr_expense"/>
        <field name="state">code</field>
        <field name="code">
            if records:
                action = records.submit_expenses()
        </field>
    </record>

That's an action for expenses, where a user can submit multiple expenses at once to his manager. Server actions have more than type code, but that should be your option here as well.

You have res_model and src_model in window actions (your example). In server actions res_model is model_id and src_model is binding_model_id.

Upvotes: 3

Related Questions