source: WAeUP_SRP/base/skins/waeup_epayment/purgePayments.py @ 2966

Last change on this file since 2966 was 2963, checked in by Henrik Bettermann, 17 years ago

purgePayments is obsolete. We need a new function which uses the payments_catalog
and which also purges accommodation payments correctly.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## Script (Python) "purgePayments.py"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: purgePayments.py 2963 2007-12-20 08:23:46Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19
20# purgePayments is obsolete. We need a new function which uses the payments_catalog
21# and which also purges accommodation payments correctly.
22
23return
24
25mtool = context.portal_membership
26member = mtool.getAuthenticatedMember()
27if str(member) not in ('admin','joachim'):
28    return
29
30
31import logging
32import DateTime
33logger = logging.getLogger('Skins.purgePayments')
34from Products.AdvancedQuery import Eq, Between, Le,In
35aq_portal = context.portal_catalog_real.evalAdvancedQuery
36aq_student = context.students_catalog.evalAdvancedQuery
37students_folder = context.portal_url.getPortalObject().campus.students
38
39request = context.REQUEST
40session = request.SESSION
41response = request.RESPONSE
42setheader = request.RESPONSE.setHeader
43#def rwrite(s):
44#    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
45#    response.write("%s<br>\n\r" % s)
46
47count = 1
48d = {}
49l = []
50sum_total = 0.0
51log_after = 100
52logger.info("start")
53query = Eq('portal_type','Payment') & Eq('review_state','opened')
54payments = aq_portal(query,sortSpecs=('container_path',))
55total = len(payments)
56logger.info("found %d payments" % total)
57#return
58sid = "xxx"
59to_del = []
60delete_count = 0
61delete_count_student = 1
62keep_count = 0
63payments_folder = None
64count = 0
65commit_after = 50
66for payment in payments:
67    p_sid = payment.getPath().split('/')[-3]
68    if sid != p_sid:
69        if count and to_del:
70            if not delete_count_student % commit_after:
71                context.waeup_tool.doCommit()
72                logger.info("committing %d total %d" % (commit_after,delete_count_student))
73            msg = "(%d/%d) found %d payments to remove, %d to keep for %s" % (count,
74                                                                              delete_count_student % commit_after,
75                                                                              len(to_del),
76                                                                              student_keep_count,
77                                                                              sid)
78            #rwrite( msg)
79            delete_count_student += 1
80            logger.info(msg)
81            payments_folder = getattr(getattr(students_folder,sid),'payments',None)
82            msg = "deleted %s of %s" % (' '.join(to_del),sid)
83            payments_folder.manage_delObjects(to_del)
84            logger.info(msg)
85        elif count and not to_del:
86            msg = "%d: found %d payments to keep for %s in review_state %s" % (count,
87                                                                  student_keep_count,
88                                                                  sid,
89                                                                  review_state,)
90            #rwrite( msg)
91        sid = p_sid
92        count += 1
93        to_del = []
94        not_del_count = 0
95        student_keep_count = 0
96        res = aq_student(Eq('id',sid))
97        if not res:# or payments_folder is None:
98            logger.info("student_id %s not found" % pin.student)
99            continue
100        student = res[0]
101        review_state = student.review_state
102    if review_state in ("school_fee_paid",
103                        "courses_registered",
104                        "courses_validated",
105                       ):
106        delete_count += 1
107        to_del += payment.getId,
108        # if payment.review_state == "opened":
109        #     #rwrite("%s : %s" % (sid,payment.Title))
110        #     delete_count += 1
111        #     to_del += payment.getId,
112        # else:
113        #     keep_count += 1
114        #     student_keep_count += 1
115    else:
116        keep_count += 1
117        student_keep_count += 1
118
119logger.info("%d of %d to purge %d to keep" % (delete_count,total,keep_count))
Note: See TracBrowser for help on using the repository browser.