1 | ## Script (Python) "ti_167_resolve" |
---|
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: ti_167_resolve.py 2061 2007-07-26 20:57:08Z joachim $ |
---|
11 | """ |
---|
12 | """ |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | import logging |
---|
19 | logger = logging.getLogger('Skins.ti_167_resolve') |
---|
20 | from Products.AdvancedQuery import Eq, Between, Le,In,MatchGlob |
---|
21 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
22 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
23 | |
---|
24 | request = context.REQUEST |
---|
25 | session = request.SESSION |
---|
26 | response = request.RESPONSE |
---|
27 | setheader = request.RESPONSE.setHeader |
---|
28 | students = context.portal_url.getPortalObject().campus.students |
---|
29 | |
---|
30 | #from string import Template |
---|
31 | def rwrite(s): |
---|
32 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
33 | response.write("%s<br>\n\r" % s) |
---|
34 | |
---|
35 | batches = context.portal_catalog(portal_type = "ScratchCardBatch") |
---|
36 | logger.info("starting to insert cost property into pins-catatlog") |
---|
37 | batch_cost = {} |
---|
38 | for batch in batches: |
---|
39 | prefix_batch = ''.join(batch.getId.split('_')) |
---|
40 | cost = batch.getObject().getContent().cost |
---|
41 | batch_cost[prefix_batch] = cost |
---|
42 | query = Eq('prefix_batch',prefix_batch) |
---|
43 | pins = aq_pins(query) |
---|
44 | for pin in pins: |
---|
45 | context.portal_pins.modifyRecord(pin=pin.pin,cost=cost) |
---|
46 | #rwrite("%s, %s" % (prefix_batch,cost)) |
---|
47 | logger.info("Cost %s (for %s) in portal_pins replaced" % (cost,prefix_batch)) |
---|
48 | query = Eq('portal_type',"Payment") |
---|
49 | payments = aq_portal(query) |
---|
50 | count = 0 |
---|
51 | no_cost = 0 |
---|
52 | for payment in payments: |
---|
53 | if payment.Title.find('n/a') > -1: |
---|
54 | #set_trace() |
---|
55 | payment_doc = payment.getObject().getContent() |
---|
56 | prefix_batch = ''.join(str(payment_doc.order_id).split('-')[:2]) |
---|
57 | if batch_cost.has_key(prefix_batch): |
---|
58 | count += 1 |
---|
59 | payment_doc.edit(mapping = {'amount': |
---|
60 | batch_cost[prefix_batch]}) |
---|
61 | #rwrite("%s: %s:%s" % (count,prefix_batch,payment_doc.order_id)) |
---|
62 | logger.info("Cost in payment object %s (%s) replaced (#%s)" % (payment.id,payment_doc.order_id,count)) |
---|
63 | else: |
---|
64 | #rwrite("cost %s:%s not found" % (prefix_batch,payment_doc.order_id)) |
---|
65 | logger.info("Prefix %s (%s) not found" % (prefix_batch,payment_doc.order_id)) |
---|
66 | no_cost +=1 |
---|
67 | if count and not count % 100: |
---|
68 | context.waeup_tool.doCommit() |
---|
69 | logger.info("Committing %s transactions, total %s" % (commit_count,count)) |
---|
70 | logger.info("updated %d payment amounts, %d costs not found" % (count,no_cost)) |
---|
71 | |
---|
72 | |
---|