Ignore:
Timestamp:
4 Dec 2014, 18:11:12 (10 years ago)
Author:
Henrik Bettermann
Message:

Undo the approval of contract and raise an exception if contract
does not meet the requirements for approval.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/workflow.py

    r12097 r12145  
    2222from zope.component import getUtility
    2323from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
    24 from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
     24from hurry.workflow.interfaces import (
     25    IWorkflowState, IWorkflowTransitionEvent, InvalidTransitionError)
    2526from waeup.ikoba.interfaces import (
    2627    IObjectHistory, IIkobaWorkflowInfo, IIkobaUtils,
     
    2829    SUBMITTED, VERIFIED, REJECTED, EXPIRED)
    2930from waeup.ikoba.interfaces import MessageFactory as _
    30 from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo
     31from waeup.ikoba.workflow import (
     32    IkobaWorkflow, IkobaWorkflowInfo)
    3133from waeup.ikoba.customers.interfaces import (
    3234    ICustomer, ICustomersUtils,
     
    238240
    239241@grok.subscribe(IContract, IWorkflowTransitionEvent)
    240 def handle_document_transition_event(obj, event):
    241     """Append message to contract history and log file and update
     242def handle_contract_transition_event(obj, event):
     243    """Append message to contract history and log file, also update
    242244    last_transition_date when transition happened.
    243     """
     245
     246    Undo the approval of contract and raise an exception if contract
     247    does not meet the requirements for approval.
     248    """
     249    if event.transition.destination == APPROVED:
     250        if not obj.is_approvable:
     251            # Undo transition and raise an exception.
     252            IWorkflowState(obj).setState(event.transition.source)
     253            raise InvalidTransitionError(
     254                "Documents must be verified first.")
    244255    msg = event.transition.user_data['msg']
    245256    history = IObjectHistory(obj)
Note: See TracChangeset for help on using the changeset viewer.