Zolbayar
Zolbayar

Reputation: 936

A workflow with server action is not working on Odoo 9.1

I've been building an Odoo 9.1 module with this tutorial. But the workflow I created by that instruction is not working (When I click on the Confirm button, nothing happens, no error log etc)

Here's the related code:

models.py (in Session class)

state = fields.Selection([
    ('draft', "Draft"),
    ('confirmed', "Confirmed"),
    ('done', "Done"),
])

@api.multi
def action_draft(self):
    self.state = 'draft'

@api.multi
def action_confirm(self):
    self.state = 'confirmed'

@api.multi
def action_done(self):
    self.state = 'done'

academy.xml (header in the Session form)

<header>
    <button name="action_draft" type="workflow"
            string="Reset to draft"
            states="confirmed,done"/>
    <button name="action_confirm" type="workflow"
            string="Confirm" states="draft"
            class="oe_highlight"/>
    <button name="action_done" type="workflow"
            string="Mark as done" states="confirmed"
            class="oe_highlight"/>
    <field name="state" widget="statusbar"/>
</header>

session_workflow.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record model="workflow" id="wkf_session">
            <field name="name">OpenAcademy sessions workflow</field>
            <field name="osv">academy.session</field>
            <field name="on_create">True</field>
        </record>

        <record model="ir.actions.server" id="set_session_to_draft">
            <field name="name">Set session to Draft</field>
            <field name="model_id" ref="model_academy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_draft()
            </field>
        </record>
        <record model="workflow.activity" id="draft">
            <field name="name">Draft</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="flow_start" eval="True"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_draft"/>
        </record>

        <record model="ir.actions.server" id="set_session_to_confirmed">
            <field name="name">Set session to Confirmed</field>
            <field name="model_id" ref="model_academy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_confirm()
            </field>
        </record>
        <record model="workflow.activity" id="confirmed">
            <field name="name">Confirmed</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_confirmed"/>
        </record>

        <record model="ir.actions.server" id="set_session_to_done">
            <field name="name">Set session to Done</field>
            <field name="model_id" ref="model_academy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_done()
            </field>
        </record>
        <record model="workflow.activity" id="done">
            <field name="name">Done</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_done"/>
        </record>

        <record model="workflow.transition" id="session_draft_to_confirmed">
            <field name="act_from" ref="draft"/>
            <field name="act_to" ref="confirmed"/>
            <field name="signal">confirm</field>
        </record>
        <record model="workflow.transition" id="session_confirmed_to_draft">
            <field name="act_from" ref="confirmed"/>
            <field name="act_to" ref="draft"/>
            <field name="signal">draft</field>
        </record>
        <record model="workflow.transition" id="session_done_to_draft">
            <field name="act_from" ref="done"/>
            <field name="act_to" ref="draft"/>
            <field name="signal">draft</field>
        </record>
        <record model="workflow.transition" id="session_confirmed_to_done">
            <field name="act_from" ref="confirmed"/>
            <field name="act_to" ref="done"/>
            <field name="signal">done</field>
        </record>
        <record model="workflow.transition" id="session_auto_confirm_half_filled">
            <field name="act_from" ref="draft"/>
            <field name="act_to" ref="confirmed"/>
            <field name="condition">taken_seats &gt; 50</field>
        </record>
    </data>
</openerp>

What went wrong?

Upvotes: 2

Views: 266

Answers (1)

Jim
Jim

Reputation: 936

change button name according to the signal value

your code:

<field name="signal">draft</field>
<button name="action_draft"...

change "action_draft" to "draft"

when the button is clicked, it would send button name as a signal, so they must be the same.

Upvotes: 2

Related Questions