Index: /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 7247)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 7248)
@@ -1080,9 +1080,10 @@
         for key in self.context.keys():
             ticket = self.context[key]
-            if ticket.p_category == p_category and \
+            if ticket.p_state == 'paid' and\
+               ticket.p_category == p_category and \
                ticket.p_item == p_item and \
                ticket.p_session == p_session:
                   self.flash(
-                      'This payment ticket already exists.')
+                      'This type of payment ticket exists and ticket has been paid.')
                   self.redirect(self.url(self.context))
                   return
Index: /main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 7247)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 7248)
@@ -987,11 +987,11 @@
                            self.browser.contents)
 
-        # The same payment ticket (with same p_item, p_session and p_category)
-        # can't be added twice.
+        # The same payment (with same p_item, p_session and p_category)
+        # can be initialized a second time if the former ticket is not yet paid.
         self.browser.open(self.payments_student_path)
         self.browser.getControl("Add online payment ticket").click()
         self.browser.getControl(name="form.p_category").value = ['schoolfee']
         self.browser.getControl("Create ticket").click()
-        self.assertMatches('...This payment ticket already exists...',
+        self.assertMatches('...Payment ticket created...',
                            self.browser.contents)
 
@@ -1008,5 +1008,16 @@
                           self.browser.contents)
 
+        # Now the first ticket is paid and no more ticket of same type
+        # (with same p_item, p_session and p_category) can be added
+        self.browser.open(self.payments_student_path)
+        self.browser.getControl("Add online payment ticket").click()
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches(
+            '...This type of payment ticket exists and ticket has been paid...',
+            self.browser.contents)
+
         # Managers can open the pdf payment receipt
+        self.browser.open(payment_url)
         self.browser.getLink("Download payment receipt").click()
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
@@ -1033,5 +1044,5 @@
         self.assertEqual(len(self.app['accesscodes']['CLR-0']),0)
         ctrl = self.browser.getControl(name='val_id')
-        value = ctrl.options[0]
+        value = ctrl.options[1] # The clearance payment is the second in the table
         self.browser.getLink(value).click()
         self.browser.open(self.browser.url + '/callback')
@@ -1042,4 +1053,5 @@
           Paid
         </td>...'''
+        #import pdb; pdb.set_trace()
         self.assertMatches(expected,self.browser.contents)
         # The new CLR-0 pin has been created
