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

  <state state_id="active" title="Active" i18n:attributes="title">
    <exit-transition transition_id="cancel" />
  </state>

  <state state_id="cancelled" title="Cancelled" i18n:attributes="title">
    <exit-transition transition_id="reinstate" />
  </state>

  <transition transition_id="cancel" title="Cancel" new_state="cancelled" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Cancel</action>
    <guard>
      <guard-permission>BIKA: Cancel and reinstate</guard-permission>
      <guard-expression>python:here.guard_cancel_transition()</guard-expression>
    </guard>
  </transition>

  <transition transition_id="reinstate" title="Reinstate" new_state="active" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Reinstate</action>
    <guard>
      <guard-permission>BIKA: Cancel and reinstate</guard-permission>
      <guard-expression>python:here.guard_reinstate_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>
