Kit Sunde
Kit Sunde

Reputation: 37095

How do I trigger code on order confirmation in Odoo?

I've setup a ir.server.action that reacts to when the model is saved and is in a manual state. However repeated saves will repeatedly trigger the action, so I have to lock on the database. Currently I have this:

<record id="filter_order_confirm" model="ir.filters">
    <field name="name">By Confirmed Orders</field>
    <field name="model_id">sale.order</field>
    <field name="domain">[('state','=','manual')]</field>
</record>

<record id="action_schedule_emails" model="ir.actions.server">
    <field name="state">code</field>
    <field name="model_id" ref="sale.model_sale_order"/>
    <field name="code">object.schedule_emails()</field>
    <field name="type">ir.actions.server</field>
    <field name="condition">True</field>
    <field name="name">Schedule Emails</field>
</record>

<record id="rule_trigger_email_scheduling" model="base.action.rule">
    <field name="name">Trigger email scheduling when Order is set to confirm.</field>
    <field name="model_id" ref="sale.model_sale_order" />
    <field name="kind">on_create_or_write</field>
    <field name="filter_id" ref="filter_order_confirm" />
    <field name="server_action_ids" eval="[(6,0,[ref('action_schedule_emails')])]" />
</record>

How can I react to the order being confirmed in the workflow instead?

Upvotes: 1

Views: 2396

Answers (1)

hugosantosred
hugosantosred

Reputation: 56

You can modify the workflow activity to trigger any server action when is executed.

In your case you need to modify the act_router activity in sale.wkf_sale this can be done from your addon like this.

<record id="sale.act_router" model="workflow.activity">
    <field name="action_id" ref="action_schedule_emails"/>
</record>

With this modification the code on your server action is triggered when the order is confirmed.

Upvotes: 4

Related Questions