Saturday, 12 November 2016

How to create server actions in Odoo 10?

Below is example of server actions in Odoo 8.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <data>
        <record id="action" model="ir.actions.server">
            <field name="name">My Action</field>
            <field name="model_id" ref="model_module_model"/>
            <field name="code">self.action(cr, uid, context=context)</field>
       </record>
    </data>
</odoo>

Following is example for Server actions in Odoo 10.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>

    <data>
        <record id="action" model="ir.actions.server">
            <field name="name">My Action</field>
            <field name="model_id" ref="model_module_model"/>
            <field name="code">
           
            if context.get('active_model') == 'your.module.model' and context.get('active_ids'):
                    action = env['module.model'].browse(context['active_ids']).action()
          
            </field>
       </record>
    </data>
</odoo>


There is no need of self variable to declare server action in Odoo 10.

3 comments:

  1. Upgrading to Odoo 10 right now. I didn't figure out how to change my Server Actions like

    self.write(cr, uid, context['active_ids'], {'to_wait':'No'})

    any clue for me?
    Thanks.

    ReplyDelete
  2. I reply myself:

    pos_obj = env['pos.order'].browse(context.get('active_ids'))
    pos_obj.write({'to_wait': 'No'})

    ReplyDelete
  3. But how to call a method like

    @api.Multi
    def my_stuff(self):
    my_code_here

    ReplyDelete

ImportError: cannot import name 'utils' from 'PyPDF2'

Odoo 15: Traceback (most recent call last):   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner     self...