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

        <record id="view_test_workflow_model" model="ir.ui.view">
            <field name="name">Test workflow</field>
            <field name="model">test.workflow.model</field>
            <field name="arch" type="xml">
                <form string="Test workflow">
                    <group col="4">
                        <button name="a-b" string="a-b" type="workflow" icon="gtk-ok" colspan="1"/>
                        <label string="a-b"/>
                        <button name="trigger" string="trigger" type="object" icon="gtk-ok" colspan="1"/>
                        <label string="trigger"/>
                    </group>
                </form>
           </field>
        </record>

        <record id="action_test_workflow" model="ir.actions.act_window">
            <field name="name">Test workflow</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">test.workflow.model</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

        <menuitem icon="STOCK_PREFERENCES" id="base.menu_tests" name="Tests" sequence="1000000"/>

        <menuitem id="menu_test_workflow" parent="base.menu_tests" name="Test workflow"/>

        <menuitem id="menu_test_workflow_leaf"
            name="Test workflow"
            action="action_test_workflow"
            parent="menu_test_workflow"/>


        <record id="test_workflow_trigger_1" model="test.workflow.trigger">
        <!-- A single trigger record, with known ID 1 -->
        </record>

        <!-- A simple workflow:

            a -signal-> b -trigger-> c

        -->
        <record id="test_workflow" model="workflow">
            <field name="name">test.workflow</field>
            <field name="osv">test.workflow.model</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">print_a()</field>
        </record>
        <record id="activity_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow"/>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">print_b()</field>
        </record>
        <record id="activity_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
            <field name="action">print_c()</field>
        </record>

        <record id="trans_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_a"/>
            <field name="act_to" ref="activity_b"/>
            <field name="signal">a-b</field>
        </record>
        <record id="trans_b_c" model="workflow.transition">
            <field name="act_from" ref="activity_b"/>
            <field name="act_to" ref="activity_c"/>
            <field name="condition">condition()</field>
            <field name="trigger_model">test.workflow.trigger</field>
            <field name="trigger_expr_id">[1]</field>
        </record>

        <!-- Workflow A (a single activity):

            a

        -->
        <record id="test_workflow_a" model="workflow">
            <field name="name">test.workflow.a</field>
            <field name="osv">test.workflow.model.a</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_a_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_a"/>
            <field name="flow_start">True</field>
            <field name="flow_stop">True</field>
            <field name="name">a</field>
            <field name="kind">dummy</field>
        </record>

        <!-- Workflow B (a single activity):

            a

        The function is run when the record is created.

        -->
        <record id="test_workflow_b" model="workflow">
            <field name="name">test.workflow.b</field>
            <field name="osv">test.workflow.model.b</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_b_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_b"/>
            <field name="flow_start">True</field>
            <field name="flow_stop">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
        </record>

        <!-- Workflow C (a single activity):

            a

        The function is not run when the kind is dummy and no action_id is provided.
        -->
        <record id="test_workflow_c" model="workflow">
            <field name="name">test.workflow.c</field>
            <field name="osv">test.workflow.model.c</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_c_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_c"/>
            <field name="flow_start">True</field>
            <field name="flow_stop">True</field>
            <field name="name">a</field>
            <field name="kind">dummy</field>
            <field name="action">write({'value': 1})</field>
        </record>

        <!-- Workflow D (a single activity):

            a

        The function is run when the kind is stopall and no action_id is provided.
        -->
        <record id="test_workflow_d" model="workflow">
            <field name="name">test.workflow.d</field>
            <field name="osv">test.workflow.model.d</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_d_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_d"/>
            <field name="flow_start">True</field>
            <field name="flow_stop">True</field>
            <field name="name">a</field>
            <field name="kind">stopall</field>
            <field name="action">write({'value': 1})</field>
        </record>

        <!-- Workflow E:

            a -True-> b

        Both activities are run when the workflow is instanciated.
        -->
        <record id="test_workflow_e" model="workflow">
            <field name="name">test.workflow.e</field>
            <field name="osv">test.workflow.model.e</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_e_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_e"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
        </record>
        <record id="activity_e_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_e"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>

        <record id="trans_e_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_e_a"/>
            <field name="act_to" ref="activity_e_b"/>
        </record>

        <!-- Workflow F:

            a -signal-> b

        Same as E but with a signal on the transition.
        -->
        <record id="test_workflow_f" model="workflow">
            <field name="name">test.workflow.f</field>
            <field name="osv">test.workflow.model.f</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_f_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_f"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
        </record>
        <record id="activity_f_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_f"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>

        <record id="trans_f_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_f_a"/>
            <field name="act_to" ref="activity_f_b"/>
            <field name="signal">a-b</field>
        </record>

        <!-- Workflow G:

            a -False-> b

        -->
        <record id="test_workflow_g" model="workflow">
            <field name="name">test.workflow.g</field>
            <field name="osv">test.workflow.model.g</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_g_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_g"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
        </record>
        <record id="activity_g_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_g"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>

        <record id="trans_g_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_g_a"/>
            <field name="act_to" ref="activity_g_b"/>
            <field name="condition">False</field>
        </record>

        <!-- Workflow H:

            a or  -> b { value: 2 } 
                 `-> c { value: 2 }

        Whether the action of b or c is exectued last is non-deterministic.

        -->
        <record id="test_workflow_h" model="workflow">
            <field name="name">test.workflow.h</field>
            <field name="osv">test.workflow.model.h</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_h_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_h"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
            <field name="split_mode">OR</field>
        </record>
        <record id="activity_h_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_h"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>
        <record id="activity_h_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_h"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>

        <record id="trans_h_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_h_a"/>
            <field name="act_to" ref="activity_h_b"/>
        </record>
        <record id="trans_h_a_c" model="workflow.transition">
            <field name="act_from" ref="activity_h_a"/>
            <field name="act_to" ref="activity_h_c"/>
        </record>

        <!-- Workflow I:

            a or -> b { value: 2 } 
                 `false> c { value: 3 }

        -->
        <record id="test_workflow_i" model="workflow">
            <field name="name">test.workflow.i</field>
            <field name="osv">test.workflow.model.i</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_i_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_i"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
            <field name="split_mode">OR</field>
        </record>
        <record id="activity_i_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_i"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>
        <record id="activity_i_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_i"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 3})</field>
        </record>

        <record id="trans_i_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_i_a"/>
            <field name="act_to" ref="activity_i_b"/>
        </record>
        <record id="trans_i_a_c" model="workflow.transition">
            <field name="act_from" ref="activity_i_a"/>
            <field name="act_to" ref="activity_i_c"/>
            <field name="condition">False</field>
        </record>

        <!-- Workflow J:

            a and -> b { value: 2 } 
                  `False> c { value: 3 }

        This will stay in a because all transitions should be True at the same time.

        -->
        <record id="test_workflow_j" model="workflow">
            <field name="name">test.workflow.j</field>
            <field name="osv">test.workflow.model.j</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_j_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_j"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
            <field name="split_mode">AND</field>
        </record>
        <record id="activity_j_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_j"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>
        <record id="activity_j_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_j"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 3})</field>
        </record>

        <record id="trans_j_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_j_a"/>
            <field name="act_to" ref="activity_j_b"/>
        </record>
        <record id="trans_j_a_c" model="workflow.transition">
            <field name="act_from" ref="activity_j_a"/>
            <field name="act_to" ref="activity_j_c"/>
            <field name="condition">False</field>
        </record>

        <!-- Workflow K:

            a xor -> b { value: 2 } 
                  `> c { value: 2 }

        Only one (truish) transition is taken with a XOR.

        -->
        <record id="test_workflow_k" model="workflow">
            <field name="name">test.workflow.k</field>
            <field name="osv">test.workflow.model.k</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_k_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_k"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
            <field name="split_mode">XOR</field>
        </record>
        <record id="activity_k_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_k"/>
            <field name="flow_stop">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
        </record>
        <record id="activity_k_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_k"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
	    <field name="action">write({'value': 2})</field>
        </record>

        <record id="trans_k_a_b" model="workflow.transition">
            <field name="act_from" ref="activity_k_a"/>
            <field name="act_to" ref="activity_k_b"/>
        </record>
        <record id="trans_k_a_c" model="workflow.transition">
            <field name="act_from" ref="activity_k_a"/>
            <field name="act_to" ref="activity_k_c"/>
        </record>

        <!-- Workflow L:

            a -> xor c { value: 3 }
            b ´
            a -> and d { value: 3 }
            b ´

        c is run for each incoming (and taken) transition.
        d is run once when all its incoming transitions are taken at the same time.

        -->
        <record id="test_workflow_l" model="workflow">
            <field name="name">test.workflow.l</field>
            <field name="osv">test.workflow.model.l</field>
            <field name="on_create">True</field>
        </record>

        <record id="activity_l_a" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_l"/>
            <field name="flow_start">True</field>
            <field name="name">a</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 1})</field>
            <field name="split_mode">OR</field>
        </record>
        <record id="activity_l_b" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_l"/>
            <field name="flow_start">True</field>
            <field name="name">b</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 2})</field>
            <field name="split_mode">OR</field>
        </record>
        <record id="activity_l_c" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_l"/>
            <field name="flow_stop">True</field>
            <field name="name">c</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 3})</field>
            <field name="join_mode">XOR</field>
        </record>
        <record id="activity_l_d" model="workflow.activity">
            <field name="wkf_id" ref="test_workflow_l"/>
            <field name="flow_stop">True</field>
            <field name="name">d</field>
            <field name="kind">function</field>
            <field name="action">write({'value': 3})</field>
            <field name="join_mode">AND</field>
        </record>

        <record id="trans_l_a_c" model="workflow.transition">
            <field name="act_from" ref="activity_l_a"/>
            <field name="act_to" ref="activity_l_c"/>
        </record>
        <record id="trans_l_b_c" model="workflow.transition">
            <field name="act_from" ref="activity_l_b"/>
            <field name="act_to" ref="activity_l_c"/>
        </record>

        <record id="trans_l_a_d" model="workflow.transition">
            <field name="act_from" ref="activity_l_a"/>
            <field name="act_to" ref="activity_l_d"/>
        </record>
        <record id="trans_l_b_d" model="workflow.transition">
            <field name="act_from" ref="activity_l_b"/>
            <field name="act_to" ref="activity_l_d"/>
        </record>
    </data>
</openerp>
