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

        <record id="wkf_prod" model="workflow">
            <field name="name">mrp.production.basic</field>
            <field name="osv">mrp.production</field>
            <field name="on_create">True</field>
        </record>

        <record id="prod_act_draft" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="flow_start">True</field>
            <field name="name">draft</field>
        </record>
        <record id="prod_act_picking" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="name">picking</field>
            <field name="kind">subflow</field>
            <field name="subflow_id" search="[('osv','=','stock.picking')]"/>
            <field name="action">action_confirm()</field>
        </record>
        <record id="prod_act_ready" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="name">ready</field>
            <field name="kind">function</field>
            <field name="action">action_ready()</field>
        </record>
        <record id="prod_act_picking_exception" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="name">picking_exception</field>
            <field name="kind">function</field>
            <field name="action">action_picking_except()</field>
        </record>
        <record id="prod_act_in_production" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="name">in_production</field>
            <field name="kind">function</field>
            <field name="action">action_in_production()</field>
        </record>
        <record id="prod_act_done" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="flow_stop">True</field>
            <field name="kind">function</field>
            <field name="action">action_production_end()</field>            
            <field name="name">done</field>
        </record>
        <record id="prod_act_cancel" model="workflow.activity">
            <field name="wkf_id" ref="wkf_prod"/>
            <field name="flow_stop">True</field>
            <field name="name">cancel</field>
            <field name="kind">function</field>
            <field name="action">action_cancel()</field>
        </record>

        <record id="prod_trans_draft_ready" model="workflow.transition">
            <field name="act_from" ref="prod_act_draft"/>
            <field name="act_to" ref="prod_act_ready"/>
            <field name="signal">button_confirm</field>
            <field name="condition">not test_if_product()</field>
        </record>
        <record id="prod_trans_draft_picking" model="workflow.transition">
            <field name="act_from" ref="prod_act_draft"/>
            <field name="act_to" ref="prod_act_picking"/>
            <field name="signal">button_confirm</field>
            <field name="condition">test_if_product()</field>
        </record>
        <record id="prod_trans_picking_ready" model="workflow.transition">
            <field name="act_from" ref="prod_act_picking"/>
            <field name="act_to" ref="prod_act_ready"/>
            <field name="signal"></field>
            <field name="condition">picking_id and picking_id.state=='done'</field>
        </record>
        <record id="prod_trans_ready_in_production" model="workflow.transition">
            <field name="act_from" ref="prod_act_ready"/>
            <field name="act_to" ref="prod_act_in_production"/>
            <field name="signal">button_produce</field>
        </record>
        <record id="prod_trans_in_production_done" model="workflow.transition">
            <field name="act_from" ref="prod_act_in_production"/>
            <field name="act_to" ref="prod_act_done"/>
            <field name="signal">button_produce_done</field>
            <field name="condition">test_production_done()</field>
        </record>
        <record id="prod_trans_picking_picking_exception" model="workflow.transition">
            <field name="act_from" ref="prod_act_picking"/>
            <field name="act_to" ref="prod_act_picking_exception"/>
            <field name="signal">subflow.cancel</field>
        </record>
        <record id="prod_trans_picking_exception_cancel" model="workflow.transition">
            <field name="act_from" ref="prod_act_picking_exception"/>
            <field name="act_to" ref="prod_act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="prod_trans_picking_exception_picking" model="workflow.transition">
            <field name="act_from" ref="prod_act_picking_exception"/>
            <field name="act_to" ref="prod_act_picking"/>
            <field name="signal">button_recreate</field>
        </record>
        <record id="prod_trans_ready_cancel" model="workflow.transition">
            <field name="act_from" ref="prod_act_ready"/>
            <field name="act_to" ref="prod_act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="prod_trans_in_production_cancel" model="workflow.transition">
            <field name="act_from" ref="prod_act_in_production"/>
            <field name="act_to" ref="prod_act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>
        <record id="prod_trans_draft_cancel" model="workflow.transition">
            <field name="act_from" ref="prod_act_draft"/>
            <field name="act_to" ref="prod_act_cancel"/>
            <field name="signal">button_cancel</field>
        </record>

        <!-- Procurement -->

        <record id="act_produce" model="workflow.activity">
            <field name="wkf_id" ref="procurement.wkf_procurement"/>
            <field name="name">produce</field>
            <field name="kind">subflow</field>
            <field name="subflow_id" search="[('osv','=','mrp.production')]"/>
            <field name="action">action_produce_assign_product()</field>
        </record>
        
        <record id="trans_product_check_produce" model="workflow.transition">
            <field name="act_from" ref="procurement.act_produce_check"/>
            <field name="act_to" ref="act_produce"/>
            <field name="condition">check_product()</field>
        </record>
        
        <record id="trans_produce_cancel" model="workflow.transition">
            <field name="act_from" ref="act_produce"/>
            <field name="act_to" ref="procurement.act_cancel"/>
            <field name="signal">subflow.cancel</field>
        </record>
        
        <record id="trans_produce_make_done" model="workflow.transition">
            <field name="act_from" ref="act_produce"/>
            <field name="act_to" ref="procurement.act_make_done"/>
            <field name="signal">subflow.done</field>
        </record>
        
        <record id="procurement.trans_confirm_confirm_wait" model="workflow.transition">
            <field name="condition">not test_cancel() and not get_phantom_bom_id()</field>
        </record>
        
    </data>
</openerp>
