<?xml version="1.0" ?>
<openerp>


    <data>

        <record id="sales_workflow" model="process.process">
            <field name="name">Sales Workflow</field>
            <field name="note">Sales flow for services companies.</field>
        </record>

        <!-- Nodes -->

        <record id="node_quotation" model="process.node">
            <field name="name">Quotation</field>
            <field name="note">Quotations are sale orders in draft mode</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Sale Order')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'My Quotations')]"></field>
            <field name="kind">state</field>
            <field name="model_states">object.state == 'draft'</field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_sale_order" model="process.node">
            <field name="name">Sale Order</field>
            <field name="note">Manages the delivery in invoicing process</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Sale Order')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'All Sales Order')]"></field>
            <field name="kind">state</field>
            <field name="model_states">object.state == 'manual'</field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_invoice_on_sale" model="process.node">
            <field name="name">Invoice</field>
            <field name="note">In case you invoiced on Sale Order</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Invoice')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'Invoices')]"></field>
            <field name="kind">state</field>
            <field name="model_states"></field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_tasks" model="process.node">
            <field name="name">Tasks</field>
            <field name="note">In case you sale services on order</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Task')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'All Tasks')]"></field>
            <field name="kind">subflow</field>
            <field name="model_states"></field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_packing" model="process.node">
            <field name="name">Picking List</field>
            <field name="note">The workers pack the requested items</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Packing list')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'Packing to Process')]"></field>
            <field name="kind">state</field>
            <field name="model_states"></field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_delivery_order" model="process.node">
            <field name="name">Delivery Order</field>
            <field name="note">The transporter take the box and deliver it</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Stock Move')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'Waiting Delivery Orders')]"></field>
            <field name="kind">state</field>
            <field name="model_states"></field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <record id="node_invoice_on_delivery" model="process.node">
            <field name="name">Invoice</field>
            <field name="note">In case you invoice based on deliveries</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Invoice')]"></field>
            <field name="menu_id" model="ir.ui.menu" search="[('name', '=', 'Invoices')]"></field>
            <field name="kind">subflow</field>
            <field name="model_states"></field>
            <field name="process_id" ref="sales_workflow"/>
        </record>

        <!-- Node conditions (Gray nodes) -->

        <record id="node_condition_invoice_on_order" model="process.condition">
            <field name="name">Invoice on order</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Sale Order')]"></field>
            <field name="model_states">object.order_policy != 'picking'</field>
            <field name="node_id" ref="node_invoice_on_sale"/>
        </record>

        <record id="node_condition_invoice_on_delivery" model="process.condition">
            <field name="name">Invoice on delivery</field>
            <field name="model_id" model="ir.model" search="[('name', '=', 'Sale Order')]"></field>
            <field name="model_states">object.order_policy == 'picking'</field>
            <field name="node_id" ref="node_invoice_on_delivery"/>
        </record>

        <!-- Transitions -->

        <record id="transition_confirm_quotation" model="process.transition">
            <field name="name">Confirm Quotation</field>
            <field name="source_node_id" ref="node_quotation"></field>
            <field name="target_node_id" ref="node_sale_order"></field>
        </record>

        <record id="transition_packing" model="process.transition">
            <field name="name">Picking</field>
            <field name="source_node_id" ref="node_sale_order"></field>
            <field name="target_node_id" ref="node_packing"></field>
        </record>

        <record id="transition_invoce_on_sale" model="process.transition">
            <field name="name">Invoice on order</field>
            <field name="source_node_id" ref="node_sale_order"></field>
            <field name="target_node_id" ref="node_invoice_on_sale"></field>
        </record>

        <record id="transition_traks" model="process.transition">
            <field name="name">Create Tasks</field>
            <field name="source_node_id" ref="node_sale_order"></field>
            <field name="target_node_id" ref="node_tasks"></field>
        </record>

        <record id="transition_delivery" model="process.transition">
            <field name="name">Deliver Goods</field>
            <field name="source_node_id" ref="node_packing"></field>
            <field name="target_node_id" ref="node_delivery_order"></field>
        </record>

        <record id="transition_invoice_on_delivery" model="process.transition">
            <field name="name">Invoice or delivery</field>
            <field name="source_node_id" ref="node_delivery_order"></field>
            <field name="target_node_id" ref="node_invoice_on_delivery"></field>
        </record>

        <!-- TODO: Transition actions (Buttons) -->

        <record id="action_confirm_quotation" model="process.transition.action">
            <field name="name">Confirm</field>
            <field name="state">workflow</field>
            <field name="action">order_confirm</field>
            <field name="transition_id" ref="transition_confirm_quotation"/>
        </record>

        <record id="action_cancel_quotation" model="process.transition.action">
            <field name="name">Cancel</field>
            <field name="state">workflow</field>
            <field name="action">cancel</field>
            <field name="transition_id" ref="transition_confirm_quotation"/>
        </record>

    </data>

</openerp>
