<?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_bid" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">bid</field>
            <field name="kind">function</field>
            <field name="action">wkf_bid_received()</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')]"/>
            <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">function</field>
            <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>
        </record>
        <record id="act_done" model="workflow.activity">
            <field name="wkf_id" ref="purchase_order"/>
            <field name="name">done</field>
            <field name="action">wkf_po_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_bid_confirmed" model="workflow.transition">
            <field name="act_from" ref="act_bid"/>
            <field name="act_to" ref="act_confirmed"/>
            <field name="signal">purchase_confirm</field>
        </record>
        <record id="trans_sent_bid" model="workflow.transition">
            <field name="act_from" ref="act_sent"/>
            <field name="act_to" ref="act_bid"/>
            <field name="signal">bid_received</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_bid_cancel" model="workflow.transition">
            <field name="act_from" ref="act_bid"/>
            <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">picking_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">picking_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>
        <record id="trans_invoice_end_cancel" model="workflow.transition">
            <field name="act_from" ref="act_invoice_end"/>
            <field name="act_to" ref="act_cancel"/>
            <field name="signal">purchase_cancel</field>
            <field name="condition">invoice_method&lt;&gt;'order'</field>
        </record>

    </data>
</openerp>
