Index: main/waeup.aaue/trunk/CHANGES.txt
===================================================================
--- main/waeup.aaue/trunk/CHANGES.txt	(revision 11621)
+++ main/waeup.aaue/trunk/CHANGES.txt	(revision 11622)
@@ -4,4 +4,9 @@
 1.2dev (unreleased)
 ===================
+
+* Do not create activation code when paying acceptance (= clearance)
+  fee payment tickets.
+
+* Cleared students must pay acceptance fee before paying school fees.
 
 * applicant_student_mapping extended.
Index: main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py	(revision 11621)
+++ main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py	(revision 11622)
@@ -55,11 +55,19 @@
         IWorkflowState(self.student).setState('cleared')
         self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['clearance']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        value = ctrl.options[0]
+        self.student['payments'][value].approve()
+
+        self.browser.open(self.payments_path + '/addop')
         self.browser.getControl(name="form.p_category").value = ['schoolfee']
         self.browser.getControl("Create ticket").click()
         self.assertMatches('...ticket created...',
                            self.browser.contents)
-
         ctrl = self.browser.getControl(name='val_id')
-        value = ctrl.options[0]
+        value = ctrl.options[1]
         self.p_id = value
         self.browser.getLink(value).click()
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/payments.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/payments.py	(revision 11621)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/payments.py	(revision 11622)
@@ -26,4 +26,5 @@
     StudentOnlinePayment, StudentOnlinePaymentFactory)
 from waeup.kofa.utils.helpers import attrs_to_fields
+from waeup.kofa.accesscodes import create_accesscode
 from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
 
@@ -43,7 +44,28 @@
         return
 
-    @property
-    def student(self):
-        return self.__parent__.__parent__
+    def _createActivationCodes(self):
+        student = self.student
+        if self.p_category in ('schoolfee', 'schoolfee_1'):
+            # Create SFE access code
+            pin, error = create_accesscode(
+                'SFE',0,self.amount_auth,student.student_id)
+            if error:
+                return error
+            self.ac = pin
+        elif self.p_category == 'bed_allocation':
+            # Create HOS access code
+            pin, error = create_accesscode(
+                'HOS',0,self.amount_auth,student.student_id)
+            if error:
+                return error
+            self.ac = pin
+        elif self.p_category == 'transcript':
+            # Create TSC access code
+            pin, error = create_accesscode(
+                'TSC',0,self.amount_auth,student.student_id)
+            if error:
+                return error
+            self.ac = pin
+        return None
 
 CustomStudentOnlinePayment = attrs_to_fields(
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py	(revision 11621)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py	(revision 11622)
@@ -136,28 +136,34 @@
         self.app['configuration']['2004'].school_fee = 6666.0
         self.browser.getControl(name="form.p_category").value = ['schoolfee']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
-                           self.browser.contents)
+        # Accepotance fee must be paid first
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...Please pay acceptance fee first...',
+                           self.browser.contents)
+        self.app['configuration']['2004'].clearance_fee = 666.0
+        self.browser.getControl(name="form.p_category").value = ['clearance']
+        self.browser.getControl("Create ticket").click()
         ctrl = self.browser.getControl(name='val_id')
         value = ctrl.options[0]
+        self.student['payments'][value].approveStudentPayment()
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        value = ctrl.options[1]
         self.browser.getLink(value).click()
         self.assertMatches('...Amount Authorized...',
                            self.browser.contents)
-        # Managers can open payment slip
+        # Managers can open school fee payment slip
         self.browser.getLink("Download payment slip").click()
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
         # Set ticket paid
-        ticket = self.student['payments'].items()[0][1]
-        ticket.p_state = 'paid'
+        ticket = self.student['payments'][value].approveStudentPayment()
         self.browser.open(self.payments_path + '/addop')
         self.browser.getControl(name="form.p_category").value = ['schoolfee']
         self.browser.getControl("Create ticket").click()
         self.assertMatches('...This type of payment has already been made...',
-                           self.browser.contents)
-        self.browser.open(self.payments_path + '/addop')
-        self.browser.getControl(name="form.p_category").value = ['clearance']
-        self.browser.getControl("Create ticket").click()
-        self.assertMatches('...ticket created...',
                            self.browser.contents)
 
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_utils.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_utils.py	(revision 11621)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_utils.py	(revision 11622)
@@ -56,4 +56,14 @@
 
         IWorkflowState(self.student).setState('cleared')
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        # Acceptance fee must be paid first.
+        self.assertEqual(error, 'Please pay acceptance fee first.')
+        payment = createObject('waeup.StudentOnlinePayment')
+        payment.p_category = 'clearance'
+        self.student['payments']['any_id'] = payment
+        payment.approveStudentPayment()
+        # No activation code created.
+        self.assertEqual(payment.ac, None)
+        # School fee can be set.
         error, payment = utils.setPaymentDetails('schoolfee',self.student)
         self.assertEqual(payment.p_level, 100)
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py	(revision 11621)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py	(revision 11622)
@@ -109,4 +109,12 @@
         new_session = student['studycourse'].current_session + 1
         return new_session, new_level
+
+    def _acceptanceFeePaid(self, student):
+        if len(student['payments']):
+            for ticket in student['payments'].values():
+                if ticket.p_state == 'paid' and \
+                    ticket.p_category == 'clearance':
+                    return True
+        return False
 
     def setPaymentDetails(self, category, student,
@@ -151,4 +159,6 @@
                 return _('Study course data are incomplete.'), None
             if student.state == CLEARED:
+                if not self._acceptanceFeePaid(student):
+                    return _('Please pay acceptance fee first.'), None
                 if student.faccode == 'FP':
                     amount = 84000.0
