目前,odoo的窗口只能執(zhí)行窗口的跳轉(zhuǎn)功能,如果我們需要在跳轉(zhuǎn)的同時執(zhí)行某些操作,則需要同時使用服務(wù)器動作。
首先我們來了解以下用法:
ir.actions.server的code字段可以賦值為一小段python代碼,當執(zhí)行該服務(wù)器動作時也會同時執(zhí)行該段python代碼,而如果這段python代碼最后返回了一個窗口動作,則執(zhí)行完服務(wù)器動作后也會執(zhí)行該窗口動作。
例子如下:
<record id="server_logistics_handover" model="ir.actions.server">
<field name="name">混合動作</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_logistics_handover"/>
<field name="state">code</field>
<field name="code">action=env['res.company'].browse(context.get('active_ids')).func_xxx()</field>
</record>
如上,該服務(wù)器動作會執(zhí)行先res.company模型的func_xxx()函數(shù),然后再執(zhí)行func_xxx()返回的action(如窗口跳轉(zhuǎn))。