<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <menuitem id="menu_workflow_root" name="Workflows" parent="base.menu_custom" groups="base.group_no_one"/>

    <!--
        ================================
        Workflows
        ================================
    -->

    <record id="view_workflow_form" model="ir.ui.view">
      <field name="name">workflow.form</field>
      <field name="model">workflow</field>
      <field name="arch" type="xml">
          <form string="Workflow" version="7.0">
              <group col="4">
                  <field name="name"/>
                  <field name="osv"/>
                  <field name="on_create"/>
              </group>
              <field name="activities"/>
          </form>
      </field>
    </record>

    <record id="view_workflow_search" model="ir.ui.view">
        <field name="name">workflow.search</field>
        <field name="model">workflow</field>
        <field name="arch" type="xml">
            <search string="Workflow">
                <field name="name" filter_domain="['|', ('name','ilike',self), ('osv','ilike',self)]" string="Workflow"/>
            </search>
        </field>
    </record>

    <record id="view_workflow_diagram" model="ir.ui.view">
      <field name="name">workflow.diagram</field>
      <field name="model">workflow</field>
      <field name="arch" type="xml">
        <diagram string="Workflow Editor">
          <node object="workflow.activity" shape="rectangle:subflow_id!=False" bgcolor="gray:flow_start==True;grey:flow_stop==True">
            <field name="name"/>
            <field name="kind"/>
            <field name="action"/>
            <field name="flow_start" invisible="1"/>
            <field name="flow_stop" invisible="1"/>
            <field name="subflow_id" invisible="1"/>
          </node>
          <arrow object="workflow.transition" source="act_from" destination="act_to" label="['signal','condition']">
            <field name="act_from"/>
            <field name="act_to"/>
            <field name="signal"/>
          </arrow>
          <label string="When customizing a workflow, be sure you do not modify an existing node or arrow, but rather add new nodes or arrows. If you absolutly need to modify a node or arrow, you can only change fields that are empty or set to the default value. If you don't do that, your customization will be overwrited at the next update or upgrade to a future version of OpenERP."/>
        </diagram>
      </field>
    </record>
    <record id="view_workflow_tree" model="ir.ui.view">
      <field name="name">workflow.tree</field>
      <field name="model">workflow</field>
      <field name="arch" type="xml">
        <tree string="Workflow">
          <field name="name"/>
          <field name="osv"/>
          <field name="on_create"/>
        </tree>
      </field>
    </record>

    <record id="action_workflow_form" model="ir.actions.act_window">
      <field name="name">Workflows</field>
      <field name="res_model">workflow</field>
      <field name="view_type">form</field>
      <field name="view_id" ref="view_workflow_tree"/>
      <field name="view_mode">tree,form,diagram</field>
    </record>
    <menuitem action="action_workflow_form" id="menu_workflow" parent="base.menu_workflow_root"/>

    <!--
        ================================
        Activities
        ================================
    -->

    <record id="view_workflow_activity_form" model="ir.ui.view">
      <field name="name">workflow.activity.form</field>
      <field name="model">workflow.activity</field>
      <field name="arch" type="xml">
        <form string="Activity" version="7.0">
           <sheet>
            <group>
                <group>
                    <field name="name"/>
                    <field name="wkf_id"/>
                    <field name="kind"/>
                </group>
                <group>
                    <field name="flow_start"/>
                    <field name="flow_stop"/>
                </group>
            </group>
            <notebook>
            <page string="Properties">
              <group>
                <group string="Subflow">
                  <field name="subflow_id" attrs="{'readonly':[('kind','&lt;&gt;','subflow')]}"/>
                  <field name="signal_send"/>
                </group>
                <group string="Conditions">
                  <field name="split_mode"/>
                  <field name="join_mode"/>
                </group>
                <group string="Actions">
                  <field name="action_id"/>
                  <field name="action" attrs="{'readonly':[('kind','=','dummy')]}"/>
                </group>
              </group>
            </page>
            <page string="Transitions">
                <field name="in_transitions">
                  <tree string="Incoming Transitions">
                    <field name="act_from"/>
                    <field name="signal"/>
                    <field name="condition"/>
                  </tree>
                </field>
                <field name="out_transitions">
                  <tree string="Outgoing Transitions">
                    <field name="act_to"/>
                    <field name="signal"/>
                    <field name="condition"/>
                  </tree>
                </field>
            </page>
          </notebook>
         </sheet> 
        </form>
      </field>
    </record>
    <record id="view_workflow_activity_tree" model="ir.ui.view">
      <field name="name">workflow.activity.tree</field>
      <field name="model">workflow.activity</field>
      <field name="arch" type="xml">
        <tree string="Activity">
          <field name="name"/>
          <field name="wkf_id"/>
          <field name="kind"/>
          <field name="flow_start"/>
          <field name="flow_stop"/>
        </tree>
      </field>
    </record>

    <record id="view_workflow_activity_search" model="ir.ui.view">
        <field name="name">workflow.activity.search</field>
        <field name="model">workflow.activity</field>
        <field name="arch" type="xml">
            <search string="Workflow Activity">
                <field name="name" string="Workflow Activity"/>
                <filter icon="terp-camera_test" string="Flow Start"
                domain="[('flow_start', '=',True)]" />
                <filter icon="terp-gtk-stop" string="Flow Stop"
                domain="[('flow_stop', '=',True)]" />
                <field name="wkf_id"/>
                <field name="action_id"/>
                <field name="kind"/>
                <group expand="0" string="Group By...">
                    <filter string="Workflow" icon="terp-stage" domain="[]" context="{'group_by':'wkf_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="action_workflow_activity_form" model="ir.actions.act_window">
      <field name="name">Activities</field>
      <field name="res_model">workflow.activity</field>
      <field name="view_type">form</field>
      <field name="view_id" ref="view_workflow_activity_tree"/>
      <field name="search_view_id" ref="view_workflow_activity_search"/>
    </record>
    <menuitem action="action_workflow_activity_form" id="menu_workflow_activity" parent="base.menu_workflow_root"/>


    <!--
        ================================
        Transitions
        ================================
    -->

    <record id="view_workflow_transition_form" model="ir.ui.view">
      <field name="name">workflow.transition.form</field>
      <field name="model">workflow.transition</field>
      <field name="arch" type="xml">
        <form string="Transition" version="7.0">
          <sheet>
            <group>
                <group>
                    <field name="act_from"/>
                    <field name="act_to"/>
                    <field name="signal"/>
                    <field name="condition"/>
                </group>
                <group>
                    <field name="group_id"/>
                    <field name="trigger_model"/>
                    <field name="trigger_expr_id"/>
                </group>
            </group>
          </sheet>
        </form>
      </field>
    </record>
    <record id="view_workflow_transition_tree" model="ir.ui.view">
      <field name="name">workflow.transition.tree</field>
      <field name="model">workflow.transition</field>
      <field name="arch" type="xml">
        <tree string="Transition">
          <field name="act_from"/>
          <field name="act_to"/>
          <field name="signal"/>
          <field name="condition"/>
        </tree>
      </field>
    </record>

    <record id="view_workflow_transition_search" model="ir.ui.view">
        <field name="name">workflow.transition.search</field>
        <field name="model">workflow.transition</field>
        <field name="arch" type="xml">
            <search string="Transition">
                <field name="signal" filter_domain="['|', ('signal','ilike',self), ('condition','ilike',self)]" string="Workflow Transition"/>
                <field name="act_from"/>
                <field name="act_to"/>
            </search>
        </field>
    </record>

    <record id="action_workflow_transition_form" model="ir.actions.act_window">
      <field name="name">Transitions</field>
      <field name="res_model">workflow.transition</field>
      <field name="view_type">form</field>
      <field name="view_id" ref="view_workflow_transition_tree"/>
      <field name="search_view_id" ref="view_workflow_transition_search"/>
    </record>
    <menuitem action="action_workflow_transition_form" id="menu_workflow_transition" parent="base.menu_workflow_root"/>

    <!--
        ================================
        Instances
        ================================
    -->

    <record id="view_workflow_instance_form" model="ir.ui.view">
      <field name="name">workflow.instance.form</field>
      <field name="model">workflow.instance</field>
      <field name="arch" type="xml">
        <form string="Workflow Instances" version="7.0">
         <sheet>
          <group col="4">
              <field name="wkf_id"/>
              <field name="res_id"/>
              <field name="res_type"/>
              <field name="state"/>
          </group>
         </sheet> 
        </form>
      </field>
    </record>
    <record id="view_workflow_instance_tree" model="ir.ui.view">
      <field name="name">workflow.instance.tree</field>
      <field name="model">workflow.instance</field>
      <field name="arch" type="xml">
        <tree string="Workflow Instances">
          <field name="wkf_id"/>
          <field name="res_id"/>
          <field name="res_type"/>
          <field name="state"/>
        </tree>
      </field>
    </record>
    <record id="view_workflow_instance_search" model="ir.ui.view">
        <field name="name">workflow.instance.search</field>
        <field name="model">workflow.instance</field>
        <field name="arch" type="xml">
            <search string="Workflow Instances">
                <field name="res_type" string="Resource Object"/>
                <filter icon="terp-camera_test" string="Active" domain="[('state','=','active')]" name="active"/>
                <field name="wkf_id"/>
                <field name="res_id"/>
                <field name="state"/>
        </search>
      </field>
    </record>

    <record id="action_workflow_instance_form" model="ir.actions.act_window">
      <field name="name">Instances</field>
      <field name="res_model">workflow.instance</field>
      <field name="view_type">form</field>
      <field name="view_id" ref="view_workflow_instance_tree"/>
      <field name="context">{'search_default_active':1}</field>
      <field name="search_view_id" ref="view_workflow_instance_search"/>
    </record>
    <menuitem action="action_workflow_instance_form" id="menu_workflow_instance" parent="base.menu_workflow_root"/>

    <!--
        ================================
        Workitems
        ================================
    -->

    <record id="view_workflow_workitem_form" model="ir.ui.view">
      <field name="name">workflow.workitem.form</field>
      <field name="model">workflow.workitem</field>
      <field name="arch" type="xml">
        <form string="Workflow Workitems" version="7.0">
         <sheet>
          <group col="4">
              <field name="wkf_id"/>
              <field name="act_id"/>
              <field name="subflow_id"/>
              <field name="inst_id"/>
              <field name="state"/>
          </group>
         </sheet> 
        </form>
      </field>
    </record>
    <record id="view_workflow_workitem_tree" model="ir.ui.view">
      <field name="name">workflow.workitem.tree</field>
      <field name="model">workflow.workitem</field>
      <field name="arch" type="xml">
        <tree string="Workflow Workitems">
          <field name="wkf_id"/>
          <field name="act_id"/>
          <field name="subflow_id"/>
          <field name="inst_id"/>
          <field name="state"/>
        </tree>
      </field>
    </record>
    <record id="view_workflow_workitem_search" model="ir.ui.view">
        <field name="name">workflow.workitem.search</field>
        <field name="model">workflow.workitem</field>
        <field name="arch" type="xml">
            <search string="Workflow Workitems">
                <field name="state" string="Status"/>
                <filter icon="terp-camera_test" string="Active" name="active" domain="[('state','=','active')]"/>
                <field name="wkf_id"/>
                <field name="act_id"/>
                <field name="subflow_id"/>
                <field name="inst_id"/>
            </search>
        </field>
    </record>

    <record id="action_workflow_workitem_form" model="ir.actions.act_window">
      <field name="name">Workitems</field>
      <field name="res_model">workflow.workitem</field>
      <field name="view_type">form</field>
      <field name="view_id" ref="view_workflow_workitem_tree"/>
      <field name="context">{'search_default_active':1}</field>
      <field name="search_view_id" ref="view_workflow_workitem_search"/>
    </record>
    <menuitem action="action_workflow_workitem_form" id="menu_workflow_workitem" parent="base.menu_workflow_root"/>

  </data>
</openerp>
