Read More
Read More
Menu Close

    Creating Automated Server Actions in Odoo

    Odoo-Code-Snippet-banner

    Automated server actions automatically trigger actions for various screens.

    Odoo provide very simple way to create automated server actions.

    Steps to create automated server actions in Odoo ,

    • Install “Automated Action Rules” module at Odoo. This module enable feature to create automated server actions.
    • Create a method using python which will trigger using server action,
    @api.model 
    def automated_action_method(self):
         active_ids = self._context.get('active_ids')
         for active_id in active_ids:
             self.env['model.name'].browse(active_id).name = 'name'
    return True
    • Create a server action using xml which will trigger using automated actions.
    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
      <data noupdate="0">
        <record id="id_server_action" model="ir.actions.server">
          <field name="name">Odoo Server Action</field>
          <field name="model_id" ref="product.model_model_model"/>
          <field name="state">code</field>
          <field name="code">action = env["model.model"].automated_action_method()</field>
        </record>
      </data>
    </openerp>
    • Create a automated server action using xml,
      • There have few attributes which are used for automated server actions,
        • name : Automated Server Action Name
        • active : place ‘1’ to active or place ‘0’  to inactive automated server action
        •  model_id : Format to define model_id
          module.model_model_name

          Searching for an experienced
          Odoo Company ?
          Read More
          • Here module is Module where automated server action is created
          • In model_model_name : “model_” is prefix and “model_name” is model name where automated server action will be triggered.
        • kind :
          1. ‘on_create’ = ‘On Creation’
          2. ‘on_write’ = ‘On Update’
          3. ‘on_create_or_write’ = ‘On Creation & Update’
          4. ‘on_unlink’ = ‘On Deletion’
          5. ‘on_change’ = ‘Based on Form Modification’
          6. ‘on_time’ = ‘Based on Timed Condition’
        • server_action_ids : define server action ids
    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
      <data noupdate="0">
        <record id="id_automated_server_action" model="base.action.rule">
          <field name="name">Odoo Automated Server Action</field>
          <field name="model_id" ref="module.model_model_name"/>
          <field name="active">1</field>
          <field name="kind">on_write</field>
          <field name="server_action_ids" eval="[(6,0,[ref('id_server_action')])]"/>
        </record>
      </data>
    </openerp>

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    8 comments

  • jaleen sheen
    why we use kind here?

    <record id="id_automated_server_action" model="base.action.rule”>
    Odoo Automated Server Action

    1
    on_write
    <field name="server_action_ids" eval="[(6,0,[ref('id_server_action‘)])]”/>

  • mesby
    hi thank for your share, but how which scenario to use it
    • Ashish (Moderator)
      Thanks for sharing your query with us.
      Automated server action is working as a hook(Which runs in the background) in Odoo. For example, you want to perform any action while creating or updating a record then automated server action will help to perform that action without any load or interruption.

      Feel free to ask in case you have any doubts about the above points.

  • Federico Leoni
    And what syntax should I use to replace an odoo 8 self.write?
    self.write(cr, uid, context[‘active_ids’], {‘to_wait’:’No’})
    • Ashish (Moderator)
      Thanks for sharing your query with us.
      Yes, you are write in Odoo8 you need to replace the below line,

      self.env[‘model.name’].browse(active_id).name = ‘name’

      to

      self.pool.get(‘model.name’).write([active_id], {‘name’:’name’})

      Feel free to ask in case you have any other query

      • virk
        self.pool.get(‘model.name’).write([active_id], {‘name’:’name’})

        what is self.pool

        • Ashish Singh (Moderator)
          self.pool is a dictionary object which stores all the instances of the Odoo(Previously know as OpenErp) models (eg: product.product etc.). For example, you want to access the instance of other models from the current model then you can use self.pool.get(‘product.product’).

          In current versions of Odoo, you can use,

          modleObj = self.env[‘model.name’].browse(id)
          modleObj.write({‘name’:’name’})

  • Back to Top