<?xml version="1.0"?>
<terp>
<data>
	<record model="workflow" id="wkf_sale">
		<field name="name">sale.order.basic</field>
		<field name="osv">sale.order</field>
		<field name="on_create">True</field>
	</record>

		#----------------------------------------------
		# Activity
		#----------------------------------------------
		<record model="workflow.activity" id="act_draft">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="flow_start">True</field>
			<field name="name">draft</field>
		</record>
		<record model="workflow.activity" id="act_router">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">router</field>
			<field name="kind">function</field>
			<field name="action">action_wait()</field>
			<field name="split_mode">OR</field>
		</record>
		<record model="workflow.activity" id="act_wait_invoice">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">wait_invoice</field>
		</record>
		<record model="workflow.activity" id="act_wait_ship">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">wait_ship</field>
		</record>

		<record model="workflow.activity" id="act_done">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">done</field>
			<field name="flow_stop">True</field>
			<field name="kind">function</field>
			<field name="action">write({'state':'done'})</field>
			<field name="join_mode">AND</field>
		</record>
		<record model="workflow.activity" id="act_cancel">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">cancel</field>
			<field name="flow_stop">True</field>
			<field name="kind">stopall</field>
			<field name="action">action_cancel()</field>
		</record>
		<record model="workflow.activity" id="act_cancel2">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">cancel2</field>
			<field name="flow_stop">True</field>
			<field name="kind">stopall</field>
			<field name="action">action_cancel()</field>
		</record>
		<record model="workflow.activity" id="act_cancel3">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">cancel3</field>
			<field name="flow_stop">True</field>
			<field name="kind">stopall</field>
			<field name="action">action_cancel()</field>
		</record>

		<record model="workflow.activity" id="act_invoice">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">invoice</field>
			<field name="kind">subflow</field>
			<field name="subflow_id" search="[('name','=','account.invoice.basic')]"/>
			<field name="action">action_invoice_create()</field>
		</record>
		<record model="workflow.activity" id="act_invoice_except">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">invoice_except</field>
			<field name="kind">function</field>
			<field name="action">write({'state':'invoice_except', 'invoice_id':False})</field>
		</record>
		<record model="workflow.activity" id="act_invoice_end">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">invoice_end</field>
			<field name="kind">function</field>
			<field name="action">write({'invoiced':1})</field>
		</record>
		<record model="workflow.activity" id="act_invoice_cancel">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">invoice_cancel</field>
			<field name="flow_stop">True</field>
			<field name="kind">stopall</field>
			<field name="action">action_cancel()</field>
		</record>

		<record model="workflow.activity" id="act_ship">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">ship</field>
			<field name="kind">function</field>
			<!--
			<field name="kind">subflow</field>
			<field name="subflow_id" search="[('osv','=','stock.picking')]"/>
			-->
			<field name="action">action_ship_create()</field>
		</record>
		<record model="workflow.activity" id="act_ship_except">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">ship_except</field>
			<field name="kind">function</field>
			<field name="action">write({'state':'shipping_except'})</field>
		</record>
		<record model="workflow.activity" id="act_ship_end">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">ship_end</field>
			<field name="kind">function</field>
			<field name="action">action_ship_end()</field>
		</record>
		<record model="workflow.activity" id="act_ship_cancel">
			<field name="wkf_id" ref="wkf_sale"/>
			<field name="name">ship_cancel</field>
			<field name="flow_stop">True</field>
			<field name="kind">stopall</field>
			<field name="action">action_cancel()</field>
		</record>

		#----------------------------------------------
		# Transistion
		#----------------------------------------------

		<record model="workflow.transition" id="trans_invoice_end_done">
			<field name="act_from" ref="act_invoice_end"/>
			<field name="act_to" ref="act_done"/>
		</record>

		<record model="workflow.transition" id="trans_draft_router">
			<field name="act_from" ref="act_draft"/>
			<field name="act_to" ref="act_router"/>
			<field name="signal">order_confirm</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">cancel</field>
		</record>

		<record model="workflow.transition" id="trans_router_wait_invoice">
			<field name="act_from" ref="act_router"/>
			<field name="act_to" ref="act_wait_invoice"/>
		</record>

		<record model="workflow.transition" id="trans_router_wait_ship">
			<field name="act_from" ref="act_router"/>
			<field name="act_to" ref="act_wait_ship"/>
		</record>

		<record model="workflow.transition" id="trans_wait_invoice_cancel2">
			<field name="act_from" ref="act_wait_invoice"/>
			<field name="act_to" ref="act_cancel2"/>
			<field name="signal">cancel</field>
		</record>
		
		<record model="workflow.transition" id="trans_wait_ship_cancel3">
			<field name="act_from" ref="act_wait_ship"/>
			<field name="act_to" ref="act_cancel3"/>
			<field name="signal">cancel</field>
		</record>

		<record model="workflow.transition" id="trans_wait_ship_ship">
			<field name="act_from" ref="act_wait_ship"/>
			<field name="act_to" ref="act_ship"/>
			<field name="condition">(order_policy!='prepaid') or invoiced</field>
		</record>
		
		<record model="workflow.transition" id="trans_wait_invoice_invoice">
			<field name="act_from" ref="act_wait_invoice"/>
			<field name="act_to" ref="act_invoice"/>
			<field name="condition">(order_policy=='prepaid') or ((order_policy=='postpaid') and shipped)</field>
		</record>
		
		<record model="workflow.transition" id="trans_wait_invoice_invoice_manual">
			<field name="act_from" ref="act_wait_invoice"/>
			<field name="act_to" ref="act_invoice"/>
			<field name="signal">manual_invoice</field>
		</record>

		<record model="workflow.transition" id="trans_invoice_invoice_end">
			<field name="act_from" ref="act_invoice"/>
			<field name="act_to" ref="act_invoice_end"/>
			<field name="signal">subflow.paid</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_invoice_except">
			<field name="act_from" ref="act_invoice"/>
			<field name="act_to" ref="act_invoice_except"/>
			<field name="signal">subflow.cancel</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_except_invoice">
			<field name="act_from" ref="act_invoice_except"/>
			<field name="act_to" ref="act_invoice"/>
			<field name="signal">invoice_recreate</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_except_invoice_end">
			<field name="act_from" ref="act_invoice_except"/>
			<field name="act_to" ref="act_invoice_end"/>
			<field name="signal">invoice_corrected</field>
		</record>
		<record model="workflow.transition" id="trans_invoice_except_invoice_cancel">
			<field name="act_from" ref="act_invoice_except"/>
			<field name="act_to" ref="act_invoice_cancel"/>
			<field name="signal">invoice_cancel</field>
		</record>
		<record model="workflow.transition" id="trans_ship_end_done">
			<field name="act_from" ref="act_ship_end"/>
			<field name="act_to" ref="act_done"/>
		</record>

		<record model="workflow.transition" id="trans_ship_ship_end">
			<field name="act_from" ref="act_ship"/>
			<field name="act_to" ref="act_ship_end"/>
			<field name="trigger_model">mrp.procurement</field>
			<field name="trigger_expr_id">procurement_lines_get()</field>
			<field name="condition">test_state('finished')</field>
		</record>
		<record model="workflow.transition" id="trans_ship_ship_except">
			<field name="act_from" ref="act_ship"/>
			<field name="act_to" ref="act_ship_except"/>
			<!--
			<field name="trigger_model">mrp.procurement</field>
			<field name="trigger_expr_id">procurement_lines_get()</field>
			-->
			<field name="condition">test_state('canceled')</field>
		</record>
		<record model="workflow.transition" id="trans_ship_except_ship">
			<field name="act_from" ref="act_ship_except"/>
			<field name="act_to" ref="act_ship"/>
			<field name="signal">ship_recreate</field>
		</record>
		<record model="workflow.transition" id="trans_ship_except_ship_end">
			<field name="act_from" ref="act_ship_except"/>
			<field name="act_to" ref="act_ship_end"/>
			<field name="signal">ship_corrected</field>
		</record>
		<record model="workflow.transition" id="trans_ship_except_ship_cancel">
			<field name="act_from" ref="act_ship_except"/>
			<field name="act_to" ref="act_ship_cancel"/>
			<field name="signal">ship_cancel</field>
		</record>

</data>
</terp>
