forvas
forvas

Reputation: 10189

How to move server action code from old API to new API?

I'm working with Odoo v8 and I've created a server action which is working OK, but to manage that I had to write it in old API, after a lot of attempts of doing it in new API.

This is my code, the one in old API, which is working now:

Python

def open_action_alt_picking_type_views(self, cr, uid, ids, context=None):
    res = {
        'view_type': 'form',
        'view_mode': 'kanban',
        'res_model': 'stock.picking.type',
        'type': 'ir.actions.act_window',
        'target': 'current',
    }
    return res

XML

<record id="server_action_alt_picking_type_views" model="ir.actions.server">
    <field name="name">Picking types</field>
    <field name="condition">True</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_stock_picking_type"/>
    <field name="state">code</field>
    <field name="code">action = self.open_action_alt_picking_type_views(cr, uid, context.get('active_ids', []), context=context)</field>
</record>

And this is one of the attempts in new API which is not working:

Python

@api.model
def open_action_alt_picking_type_views(self):
    res = {
        'view_type': 'form',
        'view_mode': 'kanban',
        'res_model': 'stock.picking.type',
        'type': 'ir.actions.act_window',
        'target': 'current',
    }
    return res

XML

<record id="server_action_alt_picking_type_views" model="ir.actions.server">
    <field name="name">Picking types</field>
    <field name="condition">True</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_stock_picking_type"/>
    <field name="state">code</field>
    <field name="code">action = self.open_action_alt_picking_type_views()</field>
</record>

I tried with @api.multi, with no decorators, adding a return before de method call in the XML code field, etc.

Does anyone know how to achieve this?

Upvotes: 2

Views: 56

Answers (1)

Lucas
Lucas

Reputation: 894

I believe you need to specify the model on the call to the method like so:

<field name="code">action = env['stock.picking.type'].open_action_alt_picking_type_views()</field>

Upvotes: 2

Related Questions