<?xml version="1.0"?>
<terp>
<data>

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

		<record model="workflow.activity" id="act_draft">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="flow_start">True</field>
			<field name="name">draft</field>
		</record>
		<record model="workflow.activity" id="act_confirmed">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="name">confirmed</field>
			<field name="kind">function</field>
			<field name="action">wkf_confirm_order()</field>
		</record>
		<record model="workflow.activity" id="act_cancel">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="name">cancel</field>
			<field name="action">write({'state':'cancel'})</field>
			<field name="kind">stopall</field>
			<field name="flow_stop">True</field>
		</record>
		<record model="workflow.activity" id="act_except_invoice">
			<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 model="workflow.activity" id="act_except_picking">
			<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 model="workflow.activity" id="act_router">
			<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="action">wkf_approve_order()</field>
		</record>
		<record model="workflow.activity" id="act_invoice">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="name">invoice</field>
			<field name="kind">subflow</field>
			<field name="subflow_id" type="int" search="[('osv','=','account.invoice')]"/>
			<field name="action">action_invoice_create()</field>
		</record>
		<record model="workflow.activity" id="act_invoice_done">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="name">invoice_done</field>
			<field name="action">write({'invoiced':1})</field>
			<field name="kind">function</field>
		</record>
		<record model="workflow.activity" id="act_picking">
			<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 model="workflow.activity" id="act_picking_done">
			<field name="wkf_id" ref="purchase_order"/>
			<field name="name">picking_done</field>
			<field name="action">write({'shipped':1})</field>
			<field name="kind">function</field>
			<field name="signal_send">subflow.delivery_done</field>
		</record>
		<record model="workflow.activity" id="act_done">
			<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 model="workflow.transition" id="trans_draft_confirmed">
			<field name="act_from" ref="act_draft"/>
			<field name="act_to" ref="act_confirmed"/>
			<field name="signal">purchase_confirm</field>
		</record>
		<record model="workflow.transition" id="trans_confirmed_cancel">
			<field name="act_from" ref="act_confirmed"/>
			<field name="act_to" ref="act_cancel"/>
			<field name="signal">purchase_cancel</field>
		</record>
		<record model="workflow.transition" id="trans_draft_cancel">
			<field name="act_from" ref="act_draft"/>
			<field name="act_to" ref="act_cancel"/>
			<field name="signal">purchase_cancel</field>
		</record>
		<record model="workflow.transition" id="trans_confirmed_router">
			<field name="act_from" ref="act_confirmed"/>
			<field name="act_to" ref="act_router"/>
			<field name="signal">purchase_approve</field>
		</record>
		<record model="workflow.transition" id="trans_router_picking">
			<field name="act_from" ref="act_router"/>
			<field name="act_to" ref="act_picking"/>
			<field name="condition">has_stockable_product()</field>
		</record>
		<record model="workflow.transition" id="trans_router_picking_done">
			<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 model="workflow.transition" id="trans_router_invoice">
			<field name="act_from" ref="act_router"/>
			<field name="act_to" ref="act_invoice"/>
			<field name="condition">invoice_method=='order'</field>
		</record>
		<record model="workflow.transition" id="trans_router_invoice_no_order">
			<field name="act_from" ref="act_router"/>
			<field name="act_to" ref="act_invoice_done"/>
			<field name="condition">invoice_method&lt;&gt;'order'</field>
		</record>
		<record model="workflow.transition" id="trans_except_picking_picking_done">
			<field name="act_from" ref="act_except_picking"/>
			<field name="act_to" ref="act_picking_done"/>
			<field name="signal">picking_ok</field>
		</record>
		<record model="workflow.transition" id="trans_except_invoice_invoice_done">
			<field name="act_from" ref="act_except_invoice"/>
			<field name="act_to" ref="act_invoice_done"/>
			<field name="signal">invoice_ok</field>
		</record>
		<record model="workflow.transition" id="trans_except_picking">
			<field name="act_from" ref="act_except_picking"/>
			<field name="act_to" ref="act_cancel"/>
			<field name="signal">cancel</field>
		</record>
		<record model="workflow.transition" id="trans_except_invoice">
			<field name="act_from" ref="act_except_invoice"/>
			<field name="act_to" ref="act_cancel"/>
			<field name="signal">cancel</field>
		</record>
		<record model="workflow.transition" id="trans_picking_except_picking">
			<field name="act_from" ref="act_picking"/>
			<field name="act_to" ref="act_except_picking"/>
			<field name="signal">subflow.cancel</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_except_invoice">
			<field name="act_from" ref="act_invoice"/>
			<field name="act_to" ref="act_except_invoice"/>
			<field name="signal">subflow.cancel</field>
		</record>
		<record model="workflow.transition" id="trans_picking_picking_done">
			<field name="act_from" ref="act_picking"/>
			<field name="act_to" ref="act_picking_done"/>
			<field name="signal">subflow.done</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_invoice_done">
			<field name="act_from" ref="act_invoice"/>
			<field name="act_to" ref="act_invoice_done"/>
			<field name="signal">subflow.paid</field>
		</record>
		<record model="workflow.transition" id="trans_picking_done_done">
			<field name="act_from" ref="act_picking_done"/>
			<field name="act_to" ref="act_done"/>
		</record>
		<record model="workflow.transition" id="trans_invoice_done_done">
			<field name="act_from" ref="act_invoice_done"/>
			<field name="act_to" ref="act_done"/>
		</record>
	</data>
</terp>
