Changeset 12145


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.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
2 edited

Legend:

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

    r12119 r12145  
    3131from zope.component import createObject, queryUtility, getUtility
    3232from zope.component.hooks import setSite, clearSite
     33from zope.schema.interfaces import ConstraintNotSatisfied
    3334from zope.catalog.interfaces import ICatalog
    3435from zope.security.interfaces import Unauthorized
    3536from zope.securitypolicy.interfaces import IPrincipalRoleManager
    3637from zope.testbrowser.testing import Browser
    37 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     38from hurry.workflow.interfaces import (
     39    IWorkflowInfo, IWorkflowState, InvalidTransitionError)
    3840from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    3941from waeup.ikoba.app import Company
     
    12091211        print "Sample contract_slip.pdf written to %s" % path
    12101212
     1213    def test_contract_approval(self):
     1214        # This is not a UI test. It just tests the approval
     1215        # of contracts.
     1216        self.assertRaises(ConstraintNotSatisfied,
     1217            self.contract.document_object, self.document)
     1218        # Document must be at least submitted
     1219        IWorkflowState(self.document).setState('submitted')
     1220        self.contract.document_object = self.document
     1221        IWorkflowState(self.contract).setState('submitted')
     1222        self.assertRaises(InvalidTransitionError,
     1223            IWorkflowInfo(self.contract).fireTransition, 'approve')
     1224        # Document must be verified for the approval of contracts
     1225        IWorkflowState(self.document).setState('verified')
     1226        IWorkflowInfo(self.contract).fireTransition('approve')
     1227        self.assertEqual(IWorkflowState(self.contract).getState(), 'approved')
     1228        return
     1229
  • 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.