source: WAeUP_SRP/trunk/skins/waeup_epayment/purgeDefinedPayments.py @ 17952

Last change on this file since 17952 was 5610, checked in by Henrik Bettermann, 14 years ago

Search for substring 'Cumulative total of payment' in resp_desc and remove payment.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1## Script (Python) "purgeDefinedPayments"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=resp_desc=None
8##title=
9##
10# $Id: purgeDefinedPayments.py 5610 2010-12-10 09:28:18Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin'):
22    return
23students_folder = context.portal_url.getPortalObject().campus.students   
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.purgeDefinedPayments')
28from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob,MatchRegexp
29aq_payments = context.payments_catalog.evalAdvancedQuery
30
31commit_after = 100
32counter = 0
33counter_all = 0
34
35payments = context.payments_catalog(status = 'failed')
36#query = In('resp_desc','Invalid*',)
37#payments = aq_payments(query)
38
39logger.info("started, %d failed payments found" % len(payments))
40
41for payment in payments:
42    counter_all += 1
43    if not 'Cumulative total of payment' in payment.resp_desc:
44        continue
45    payments_folder = getattr(getattr(students_folder,payment.student_id),'payments',None)       
46    counter += 1
47    pid = 'p' + payment.order_id[6:]   
48    if getattr(payments_folder,pid,False):
49        logger.info('object deleted: %s , %s, %s, %d of %d' % (payment.student_id, pid, payment.resp_desc, counter, counter_all))
50    else:
51        logger.info('no object: %s, %s' % (payment.student_id, pid))
52    payments_folder.manage_delObjects(pid)
53
54    if not counter % commit_after:
55        context.waeup_tool.doCommit()
56        logger.info("committing %d of total %d" % (commit_after,counter))
57   
58context.waeup_tool.doCommit()
59logger.info("%d committed" % (counter))   
60
61logger.info("finished, %d payment objects removed" % (counter))
62return 'finished!'
63
64
Note: See TracBrowser for help on using the repository browser.