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

        <record id="purchase_order" model="workflow">
            <field name="name">Purchase Order Basic Workflow</field>
            <field name="osv">purchase.order</field>
            <field name="on_create">True</field>
        </record>

        <record id="act_draft" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="flow_start">True</field>
            <field name="name">draft</field>
        </record>
        <record id="act_sent" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">sent</field>
            <field name="kind">function</field>
            <field name="action">write({'state':'sent'})</field>
        </record>
        <record id="act_confirmed" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">confirmed</field>
            <field name="split_mode">OR</field>
            <field name="kind">function</field>
            <field name="action">wkf_confirm_order()</field>
        </record>
        <record id="act_cancel" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">cancel</field>
            <field name="kind">function</field>
            <field name="flow_stop">True</field>
            <field name="action">wkf_action_cancel()</field>
        </record>
        <record id="act_except_invoice" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">except_invoice</field>
            <field name="kind">function</field>
            <field name="action">write({'state':'except_invoice'})</field>
        </record>
        <record id="act_except_picking" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">except_picking</field>
            <field name="kind">function</field>
            <field name="action">write({'state':'except_picking'})</field>
        </record>
        <record id="act_router" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">router</field>
            <field name="split_mode">OR</field>
            <field name="kind">function</field>
            <field name="join_mode">AND</field>
            <field name="action">wkf_approve_order()</field>
        </record>
        <record id="act_invoice" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">invoice</field>
            <field name="kind">subflow</field>
            <field name="subflow_id" search="[('osv','=','account.invoice')]" type="int"/>
            <field name="action">action_invoice_create()</field>
        </record>
        <record id="act_invoice_done" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">invoice_done</field>
            <field name="action">invoice_done()</field>
            <field name="kind">function</field>
        </record>
        <record id="act_invoice_end" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">invoice_end</field>
        </record>
        <record id="act_picking" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">picking</field>
            <field name="kind">subflow</field>
            <field name="subflow_id" search="[('osv','=','stock.picking')]"/>
            <field name="action">action_picking_create()</field>
        </record>
        <record id="act_picking_done" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">picking_done</field>
            <field name="action">picking_done()</field>
            <field name="kind">function</field>
            <field name="signal_send">subflow.delivery_done</field>
        </record>
        <record id="act_done" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">done</field>
            <field name="action">write({'state':'done'})</field>
            <field name="kind">function</field>
            <field name="flow_stop">True</field>
            <field name="join_mode">AND</field>
        </record>

        <record id="trans_draft_confirmed" model="workflow.transition">
            <field name="act_from" ref="act_draft"/>
            <field name="act_to" ref="act_confirmed"/>
            <field name="signal">purchase_confirm</field>
        </record>
         <record id="trans_draft_sent" model="workflow.transition">
            <field name="act_from" ref="act_draft"/>
            <field name="act_to" ref="act_sent"/>
            <field name="signal">send_rfq</field>
        </record>
        <record id="trans_sent_confirmed" model="workflow.transition">
            <field name="act_from" ref="act_sent"/>
            <field name="act_to" ref="act_confirmed"/>
            <field name="signal">purchase_confirm</field>
        </record>
        <record id="trans_sent_cancel" model="workflow.transition">
            <field name="act_from" ref="act_sent"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">purchase_cancel</field>
        </record>
        
        <record id="trans_confirmed_cancel" model="workflow.transition">
            <field name="act_from" ref="act_confirmed"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">purchase_cancel</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">purchase_cancel</field>
        </record>
        <record id="trans_confirmed_router" model="workflow.transition">
            <field name="act_from" ref="act_confirmed"/>
            <field name="act_to" ref="act_router"/>
            <!-- <field name="signal">purchase_approve</field> removed from simplification/useability -->
        </record>
        <record id="trans_router_picking" model="workflow.transition">
            <field name="act_from" ref="act_router"/>
            <field name="act_to" ref="act_picking"/>
            <field name="condition">has_stockable_product()</field>
        </record>
        <record id="trans_router_picking_done" model="workflow.transition">
            <field name="act_from" ref="act_router"/>
            <field name="act_to" ref="act_picking_done"/>
            <field name="condition">not has_stockable_product()</field>
        </record>
        <record id="trans_router_invoice" model="workflow.transition">
            <field name="act_from" ref="act_router"/>
            <field name="act_to" ref="act_invoice"/>
            <field name="condition">invoice_method=='order'</field>
        </record>
        <record id="trans_router_invoice_no_order" model="workflow.transition">
            <field name="act_from" ref="act_router"/>
            <field name="act_to" ref="act_invoice_end"/>
            <field name="condition">invoice_method&lt;&gt;'order'</field>
        </record>
        <record id="trans_except_picking_picking_done" model="workflow.transition">
            <field name="act_from" ref="act_except_picking"/>
            <field name="act_to" ref="act_picking_done"/>
            <field name="signal">picking_ok</field>
        </record>
        <record id="trans_except_invoice_invoice_done" model="workflow.transition">
            <field name="act_from" ref="act_except_invoice"/>
            <field name="act_to" ref="act_invoice_done"/>
            <field name="signal">invoice_ok</field>
        </record>
        <record id="trans_except_picking" model="workflow.transition">
            <field name="act_from" ref="act_except_picking"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">purchase_cancel</field>
        </record>
        <record id="trans_except_invoice" model="workflow.transition">
            <field name="act_from" ref="act_except_invoice"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">purchase_cancel</field>
        </record>
        <record id="trans_picking_except_picking" model="workflow.transition">
            <field name="act_from" ref="act_picking"/>
            <field name="act_to" ref="act_except_picking"/>
            <field name="signal">subflow.cancel</field>
        </record>
        <record id="trans_invoice_except_invoice" model="workflow.transition">
            <field name="act_from" ref="act_invoice"/>
            <field name="act_to" ref="act_except_invoice"/>
            <field name="signal">subflow.cancel</field>
        </record>
        <record id="trans_picking_picking_done" model="workflow.transition">
            <field name="act_from" ref="act_picking"/>
            <field name="act_to" ref="act_picking_done"/>
            <field name="signal">subflow.done</field>
        </record>
        <record id="trans_invoice_invoice_done" model="workflow.transition">
            <field name="act_from" ref="act_invoice"/>
            <field name="act_to" ref="act_invoice_done"/>
            <field name="signal">subflow.paid</field>
        </record>
        <record id="trans_picking_done_done" model="workflow.transition">
            <field name="act_from" ref="act_picking_done"/>
            <field name="act_to" ref="act_done"/>
        </record>
        <record id="trans_invoice_done_done" model="workflow.transition">
            <field name="act_from" ref="act_invoice_done"/>
            <field name="act_to" ref="act_invoice_end"/>
        </record>
        <record id="trans_invoice_end_done" model="workflow.transition">
            <field name="act_from" ref="act_invoice_end"/>
            <field name="act_to" ref="act_done"/>
            <field name="condition">invoiced</field>
        </record>

    <!-- Procurement -->
        <record id="act_buy" model="workflow.activity">
            <field name="wkf_id" ref="procurement.wkf_procurement"/>
            <field name="name">buy</field>
            <field name="kind">subflow</field>
            <field name="subflow_id" search="[('osv','=','purchase.order')]"/>
            <field name="action">action_po_assign()</field>
        </record>

        <record id="trans_confirm_mto_purchase" model="workflow.transition">
            <field name="act_from" ref="procurement.act_confirm_mto"/>
            <field name="act_to" ref="act_buy"/>
            <field name="condition">check_buy() and check_supplier_info()</field>
        </record>

        <record id="trans_buy_make_done" model="workflow.transition">
            <field name="act_from" ref="act_buy"/>
            <field name="act_to" ref="procurement.act_make_done"/>
            <field name="signal">subflow.delivery_done</field>
        </record>

        <record id="trans_buy_cancel" model="workflow.transition">
            <field name="act_from" ref="act_buy"/>
            <field name="act_to" ref="procurement.act_cancel"/>
            <field name="signal">subflow.cancel</field>
        </record>

    </data>
</openerp>
