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

        <record id="wkf_procurement" model="workflow">
            <field name="name">procurement.order.basic</field>
            <field name="osv">procurement.order</field>
            <field name="on_create">True</field>
        </record>

        <record id="act_draft" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="flow_start">True</field>
            <field name="name">draft</field>
        </record>
        <record id="act_cancel" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">cancel</field>
            <field name="kind">function</field>
            <field name="action">action_cancel()</field>
            <field name="flow_stop">True</field>
        </record>
        <record id="act_confirm" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">confirm</field>
            <field name="kind">function</field>
            <field name="action">action_confirm()</field>
        </record>
        <record id="act_confirm_wait" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">confirm_wait</field>
            <field name="kind">function</field>
            <field name="action">write({'state':'exception'})</field>
        </record>
        <record id="act_confirm_mts" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">confirm_mts</field>
        </record>
        <record id="act_confirm_mto" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">confirm_mto</field>
        </record>
        <record id="act_make_to_stock" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">make_to_stock</field>
            <field name="kind">function</field>
            <field name="action">action_move_assigned()</field>
        </record>

        <record id="act_make_done" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">ready</field>
            <field name="kind">function</field>
            <field name="action">action_ready()</field>
        </record>
        <record id="act_wait_done" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="name">wait_done</field>
            <field name="kind">function</field>
            <field name="action">write({'state':'waiting'})</field>
        </record>

        <record id="act_done" model="workflow.activity">
            <field name="wkf_id" ref="wkf_procurement"/>
            <field name="flow_stop">True</field>
            <field name="name">done</field>
            <field name="kind">function</field>
            <field name="action">action_done()</field>
        </record>

        <record id="trans_draft_confirm" model="workflow.transition">
            <field name="act_from" ref="act_draft"/>
            <field name="act_to" ref="act_confirm"/>
            <field name="signal">button_confirm</field>
        </record>
        <record id="trans_confirm_cancel2" model="workflow.transition">
            <field name="act_from" ref="act_confirm"/>
            <field name="act_to" ref="act_wait_done"/>
            <field name="signal">button_wait_done</field>
            <field name="condition">True</field>
        </record>
        <record id="trans_confirm_wait_done" model="workflow.transition">
            <field name="act_from" ref="act_wait_done"/>
            <field name="act_to" ref="act_done"/>
            <field name="condition">check_move_done()</field>
            <field name="trigger_model">stock.move</field>
            <field name="trigger_expr_id">[move_id.id]</field>
        </record>

        <record id="trans_confirm_cancel" model="workflow.transition">
            <field name="act_from" ref="act_confirm"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">button_check</field>
            <field name="condition">test_cancel()</field>
        </record>
        <record id="trans_confirm_confirm_wait" model="workflow.transition">
            <field name="act_from" ref="act_confirm"/>
            <field name="act_to" ref="act_confirm_wait"/>
            <field name="signal">button_check</field>
            <field name="condition">check_conditions_confirm2wait()</field>
        </record>
        <record id="trans_confirm_wait_confirm_mto" model="workflow.transition">
            <field name="act_from" ref="act_confirm_wait"/>
            <field name="act_to" ref="act_confirm_mto"/>
            <field name="condition">procure_method=='make_to_order'</field>
        </record>
        <record id="trans_confirm_wait_confirm_mts" model="workflow.transition">
            <field name="act_from" ref="act_confirm_wait"/>
            <field name="act_to" ref="act_confirm_mts"/>
            <field name="condition">procure_method=='make_to_stock'</field>
        </record>
        <record id="trans_confirm_mts_cancel" model="workflow.transition">
            <field name="act_from" ref="act_confirm_mts"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="trans_confirm_waiting_cancel" model="workflow.transition">
            <field name="act_from" ref="act_wait_done"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="trans_confirm_mts_confirm" model="workflow.transition">
            <field name="act_from" ref="act_confirm_mts"/>
            <field name="act_to" ref="act_confirm"/>
            <field name="signal">button_restart</field>
        </record>
        <record id="trans_confirm_mto_cancel" model="workflow.transition">
            <field name="act_from" ref="act_confirm_mto"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="trans_confirm_mto_confirm" model="workflow.transition">
            <field name="act_from" ref="act_confirm_mto"/>
            <field name="act_to" ref="act_confirm"/>
            <field name="signal">button_restart</field>
        </record>
        <record id="trans_draft_cancel" model="workflow.transition">
            <field name="act_from" ref="act_draft"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="trans_confirm_mts_make_to_stock" model="workflow.transition">
            <field name="act_from" ref="act_confirm_mts"/>
            <field name="act_to" ref="act_make_to_stock"/>
            <field name="condition">check_make_to_stock()</field>
        </record>

        <record id="trans_confirm_mto_make_done" model="workflow.transition">
            <!-- This transition is there to unblock products that would be in MTO with a supply method that would be
                 produce or buy, and without MRP or Purchase modules installed. These modules overwrite the check_produce()
                 and check_buy() methods -so that it invalidates their part of this 'bypass transition'-,  and define
                 their own workflow paths.
                 The stock_location module also introduces a check_move() alternative, for pulled flows that are
                 satisfied with an internal product move. This yields a threefold test for the bypass transition. 
            -->
            <field name="act_from" ref="act_confirm_mto"/>
            <field name="act_to" ref="act_make_done"/>
            <field name="condition">not check_produce() and not check_buy() and not check_move()</field>
        </record>

        <record id="trans_make_to_stock_make_done" model="workflow.transition">
            <field name="act_from" ref="act_make_to_stock"/> <!-- TOFIX: If product is service product and procure method is 'make_to_stock', procurement is closed without generated service -->
            <field name="act_to" ref="act_make_done"/>
            <field name="condition">True</field>
            <field name="trigger_model" eval="False"/>
            <field name="trigger_expr_id" eval="False"/>
        </record>

        <record id="trans_make_done_done" model="workflow.transition">
            <field name="act_from" ref="act_make_done"/>
            <field name="act_to" ref="act_done"/>
            <field name="condition">action_check_finished()</field>
            <field name="trigger_model">stock.move</field>
            <field name="trigger_expr_id">move_id and [move_id.id] or []</field>
        </record>
        <record id="trans_make_done_confirm" model="workflow.transition">
            <field name="act_from" ref="act_make_done"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="condition">check_move_cancel()</field>
        </record>

    </data>
</openerp>
