Changeset 16169
- Timestamp:
- 17 Jul 2020, 19:44:47 (4 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r16157 r16169 4 4 1.6.1.dev0 (unreleased) 5 5 ======================= 6 7 * Implement webservice `get_unpaid_payments`. 6 8 7 9 * Prepare `renderPDFAdmissionLetter` for merging with another pdf document. -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
r16112 r16169 2 2 import xmlrpclib 3 3 import os 4 from time import time 4 5 from cStringIO import StringIO 5 6 from zope.app.testing.xmlrpc import ServerProxy … … 799 800 self.assertEqual(xmlout, response) 800 801 return 802 803 def test_get_unpaid_payments(self): 804 timestamp1 = ("%d" % int((time()-10)*10000))[1:] 805 timestamp2 = ("%d" % int((time()-5)*10000))[1:] 806 timestamp3 = ("%d" % int((time()-(3*86400))*10000))[1:] 807 p_id_1 = ("p%s" % timestamp1) 808 p_id_2 = ("p%s" % timestamp2) 809 p_id_3 = ("p%s" % timestamp3) 810 payment1 = StudentOnlinePayment() 811 payment1.p_id = p_id_1 812 payment1.p_session = 2012 813 payment1.amount_auth = 12.12 814 payment1.p_state = u'unpaid' 815 payment1.p_category = u'schoolfee' 816 payment1.r_company = u'xyz' 817 self.student['payments']['my-payment1'] = payment1 818 payment2 = StudentOnlinePayment() 819 payment2.p_id = p_id_2 820 payment2.p_session = 2012 821 payment2.amount_auth = 12.12 822 payment2.p_state = u'paid' 823 payment2.p_category = u'clearance' 824 self.student['payments']['my-payment2'] = payment2 825 payment3 = StudentOnlinePayment() 826 payment3.p_id = p_id_3 827 payment3.p_session = 2012 828 payment3.amount_auth = 12.12 829 payment3.p_state = u'unpaid' 830 payment3.p_category = u'schoolfee' 831 self.student['payments']['my-payment3'] = payment3 832 server = ServerProxy('http://mgr:mgrpw@localhost/app', allow_none=True) 833 results = server.get_unpaid_payments(1) 834 self.assertEqual( 835 results,[ 836 {'display_item': None, 837 'p_id': '%s' % p_id_1, 838 'p_category': 'schoolfee', 839 'amount_auth': 12.12, 'p_session': 2012, 840 'p_state': 'unpaid', 841 'r_company': 'xyz'} 842 ]) 843 results = server.get_unpaid_payments(4) 844 self.assertEqual( 845 results,[ 846 {'display_item': None, 847 'p_id': '%s' % p_id_1, 848 'p_category': 'schoolfee', 849 'amount_auth': 12.12, 850 'p_session': 2012, 851 'p_state': 'unpaid', 852 'r_company': 'xyz'}, 853 {'display_item': None, 854 'p_id': '%s' % p_id_3, 855 'p_category': 'schoolfee', 856 'amount_auth': 12.12, 857 'p_session': 2012, 858 'p_state': 'unpaid', 859 'r_company': None} 860 ]) 861 results = server.get_unpaid_payments(4,'xyz') 862 self.assertEqual( 863 results,[ 864 {'display_item': None, 865 'p_id': '%s' % p_id_1, 866 'p_category': 'schoolfee', 867 'amount_auth': 12.12, 868 'p_session': 2012, 869 'p_state': 'unpaid', 870 'r_company': 'xyz'}, 871 ]) 872 873 REQUEST_XML = """\ 874 <?xml version="1.0"?> 875 <methodCall> 876 <methodName>get_unpaid_payments</methodName> 877 <params> 878 <param> 879 <value><string>1</string></value> 880 </param> 881 </params> 882 </methodCall>""" 883 RESPONSE_XML = """\ 884 <?xml version='1.0'?> 885 <methodResponse> 886 <params> 887 <param> 888 <value><array><data> 889 <value><struct> 890 <member> 891 <name>display_item</name> 892 <value><nil/></value></member> 893 <member> 894 <name>p_id</name> 895 <value><string>%s</string></value> 896 </member> 897 <member> 898 <name>r_company</name> 899 <value><string>xyz</string></value> 900 </member> 901 <member> 902 <name>p_category</name> 903 <value><string>schoolfee</string></value> 904 </member> 905 <member> 906 <name>amount_auth</name> 907 <value><double>12.12</double></value> 908 </member> 909 <member> 910 <name>p_session</name> 911 <value><int>2012</int></value> 912 </member> 913 <member> 914 <name>p_state</name> 915 <value><string>unpaid</string></value> 916 </member> 917 </struct></value> 918 </data></array></value> 919 </param> 920 </params> 921 </methodResponse> 922 """ % p_id_1 923 xmlout = self.XMLRPC_post(REQUEST_XML) 924 self.assertEqual(xmlout, RESPONSE_XML) 925 return -
main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
r16112 r16169 19 19 import os 20 20 import xmlrpclib 21 from time import time 21 22 from cStringIO import StringIO 22 23 from zope.component import getUtility, queryUtility … … 416 417 ) 417 418 return hitlist 419 420 @grok.require('waeup.xmlrpc') 421 def get_unpaid_payments(self, days=3, company=None): 422 """Returns the p_ids of unpaid payment tickets which have 423 been created during the past days. 424 """ 425 days_in_seconds = 86400 * int(days) 426 timestamp_now = ("%d" % int(time()*10000))[1:] 427 timestamp_now_minus_days = ("%d" % int((time()-days_in_seconds)*10000))[1:] 428 p_id_now = ("p%s" % timestamp_now) 429 p_id_minus_days = ("p%s" % timestamp_now_minus_days) 430 cat = getUtility(ICatalog, name='payments_catalog') 431 payments = list( 432 cat.searchResults(p_id=(p_id_minus_days, p_id_now), 433 p_state=('unpaid', 'unpaid'))) 434 hitlist = [] 435 if company: 436 for payment in payments: 437 if company == getattr(payment, 'r_company', None): 438 hitlist.append(dict( 439 p_id=payment.p_id, 440 amount_auth=payment.amount_auth, 441 p_category=payment.p_category, 442 display_item=payment.display_item, 443 p_session=payment.p_session, 444 p_state=payment.p_state, 445 r_company=getattr(payment, 'r_company', None) 446 ) 447 ) 448 return hitlist 449 for payment in payments: 450 hitlist.append(dict( 451 p_id=payment.p_id, 452 amount_auth=payment.amount_auth, 453 p_category=payment.p_category, 454 display_item=payment.display_item, 455 p_session=payment.p_session, 456 p_state=payment.p_state, 457 r_company=getattr(payment, 'r_company', None) 458 ) 459 ) 460 return hitlist
Note: See TracChangeset for help on using the changeset viewer.