<?xml version="1.0"?>
<dc-workflow xmlns:i18n="http://xml.zope.org/namespaces/i18n"
             workflow_id="bika_worksheet_workflow"
             title="Bika Worksheet Workflow"
             description=""
             state_variable="review_state"
             initial_state="open"
             manager_bypass="False"
             i18n:domain="senaite.core">

  <permission>BIKA: Add Attachment</permission>
  <permission>BIKA: Assign analyses</permission>
  <permission>BIKA: Edit Worksheet</permission>
  <permission>BIKA: Retract</permission>
  <permission>BIKA: Unassign analyses</permission>
  <permission>BIKA: View Results</permission>
  <permission>Modify portal content</permission>

  <state state_id="attachment_due" title="Attachment due" i18n:attributes="title">
    <exit-transition transition_id="attach" />
    <exit-transition transition_id="retract" />
    <exit-transition transition_id="reject" />
    <permission-map name="BIKA: Add Attachment" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Assign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Edit Worksheet" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Retract" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Unassign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: View Results" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
  </state>

  <state state_id="open" title="Open" i18n:attributes="title">
    <exit-transition transition_id="submit" />
    <permission-map name="BIKA: Add Attachment" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Assign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Edit Worksheet" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Retract" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Unassign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: View Results" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
  </state>

  <state state_id="rejected" title="Rejected" i18n:attributes="title">
    <exit-transition transition_id="" />
    <permission-map name="BIKA: Add Attachment" acquired="False">
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Assign analyses" acquired="False">
    </permission-map>
    <permission-map name="BIKA: Edit Worksheet" acquired="False">
    </permission-map>
    <permission-map name="BIKA: Retract" acquired="False">
    </permission-map>
    <permission-map name="BIKA: Unassign analyses" acquired="False">
    </permission-map>
    <permission-map name="BIKA: View Results" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Manager</permission-role>
    </permission-map>
  </state>

  <state state_id="to_be_verified" title="To be verified" i18n:attributes="title">
    <exit-transition transition_id="verify" />
    <exit-transition transition_id="retract" />
    <exit-transition transition_id="reject" />
    <permission-map name="BIKA: Add Attachment" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Assign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Edit Worksheet" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Retract" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Unassign analyses" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: View Results" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
  </state>

  <state state_id="verified" title="Verified" i18n:attributes="title">
    <exit-transition transition_id="" />
    <permission-map name="BIKA: Add Attachment" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Assign analyses" acquired="False">
    </permission-map>
    <permission-map name="BIKA: Edit Worksheet" acquired="False">
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="BIKA: Retract" acquired="False">
    </permission-map>
    <permission-map name="BIKA: Unassign analyses" acquired="False">
    </permission-map>
    <permission-map name="BIKA: View Results" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Analyst</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>Manager</permission-role>
    </permission-map>
  </state>

  <transition transition_id="attach" title="Attach" new_state="to_be_verified" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Add attachment</action>
    <guard>
      <guard-expression>python:here.guard_attach_transition()</guard-expression>
    </guard>
  </transition>

  <transition transition_id="reject" title="Reject" new_state="rejected" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Reject</action>
    <guard>
      <guard-permission>BIKA: Reject Worksheet</guard-permission>
    </guard>
  </transition>

  <transition transition_id="retract" title="Retract" new_state="open" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Retract worksheet</action>
    <guard>
      <guard-expression>python:here.guard_retract_transition()</guard-expression>
    </guard>
  </transition>

  <transition transition_id="submit" title="Submit" new_state="attachment_due" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Submit for verification</action>
    <guard>
      <guard-expression>python:here.guard_submit_transition()</guard-expression>
    </guard>
  </transition>

  <transition transition_id="verify" title="Verify" new_state="verified" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Verify</action>
    <guard>
      <guard-expression>python:here.guard_verify_transition()</guard-expression>
    </guard>
  </transition>

  <variable variable_id="action" for_catalog="False" for_status="True" update_always="True">
    <description>Previous transition</description>
    <default>
      <expression>transition/getId|nothing</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="actor" for_catalog="False" for_status="True" update_always="True">
    <description>The ID of the user who performed the last transition</description>
    <default>
      <expression>user/getId</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="comments" for_catalog="False" for_status="True" update_always="True">
    <description>Comment about the last transition</description>
    <default>
      <expression>python:state_change.kwargs.get('comment', '')</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="review_history" for_catalog="False" for_status="False" update_always="False">
    <description>Provides access to workflow history</description>
    <default>
      <expression>state_change/getHistory</expression>
    </default>
    <guard>
      <guard-permission>Request review</guard-permission>
      <guard-permission>Review portal content</guard-permission>
    </guard>
  </variable>

  <variable variable_id="time" for_catalog="False" for_status="True" update_always="True">
    <description>When the previous transition was performed</description>
    <default>
      <expression>state_change/getDateTime</expression>
    </default>
    <guard>
    </guard>
  </variable>

</dc-workflow>
