Subversion Repositories SmartDukaan

Rev

Rev 5756 | Rev 6185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5756 Rev 6174
Line 13... Line 13...
13
import sys
13
import sys
14
import urllib
14
import urllib
15
import urllib2
15
import urllib2
16
import traceback
16
import traceback
17
from string import Template
17
from string import Template
-
 
18
from shop2020.model.v1.order.impl.DataAccessors import update_amount_in_wallet
18
 
19
 
19
 
20
 
20
if __name__ == '__main__' and __package__ is None:
21
if __name__ == '__main__' and __package__ is None:
21
    import os
22
    import os
22
    sys.path.insert(0, os.getcwd())
23
    sys.path.insert(0, os.getcwd())
Line 42... Line 43...
42
    DataService.initialize(db_hostname=db_hostname, echoOn=True)
43
    DataService.initialize(db_hostname=db_hostname, echoOn=True)
43
    vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
44
    vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
44
    for voucher in vouchers:
45
    for voucher in vouchers:
45
        order = voucher.order
46
        order = voucher.order
46
        if order.status == OrderStatus.DELIVERY_SUCCESS:
47
        if order.status == OrderStatus.DELIVERY_SUCCESS:
-
 
48
            update_amount_in_wallet(order.customer_id, voucher.amount, order.id)
47
            storeVoucher(voucher.amount)
49
            #storeVoucher(voucher.amount)
48
            coupon = issueVoucher(order.customer_id, order.customer_email, voucher.amount)
50
            #coupon = issueVoucher(order.customer_id, order.customer_email, voucher.amount)
49
            voucher.issuedOn = datetime.datetime.now()
51
            voucher.issuedOn = datetime.datetime.now()
50
            voucher.voucherIssued = True
52
            voucher.voucherIssued = True
51
            voucher.voucherCode = coupon
53
            voucher.voucherCode = 'RECHARGE_WALLET'
52
            session.commit()
54
            session.commit()
53
            #sendEmail(order.customer_email, voucher.amount, order.id, coupon)
55
            sendEmail(order.customer_email, voucher.amount, order.id, order.customer_name)
54
            createCrmTicket(voucher)
56
            createCrmTicket(voucher)
55
 
57
 
56
def createCrmTicket(voucher):
58
def createCrmTicket(voucher):
57
    try :
59
    try :
58
        cc = CRMClient().get_client()
60
        cc = CRMClient().get_client()
Line 162... Line 164...
162
        tokens = returnValue.split('#')
164
        tokens = returnValue.split('#')
163
        status = tokens[0]
165
        status = tokens[0]
164
        actualAmount = int(tokens[1])
166
        actualAmount = int(tokens[1])
165
        availableAmount = int(tokens[2])
167
        availableAmount = int(tokens[2])
166
        email = tokens[3]
168
        email = tokens[3]
-
 
169
 
167
def sendEmail(email, amount, orderId, voucherCode):
170
def sendEmail(email, amount, orderId, customer_name):
168
    html = """
171
    html = """
169
        <html>
172
        <html>
170
        <body>
173
        <body>
171
        <div>
174
        <div>
172
        <p>
175
        <p>
173
            Hi,<br /><br />
176
        Hi $customer_name, <br>
174
            Recharge voucher of $amount against order id $orderId is mentioned below. You can use it to recharge mobile through www.spicedeck.com. 
177
        Thanks for your order Id: $orderid placed at Saholic.com. As promised you have received a recharge worth Rs $amount. This amount has been added to your <a href="www.saholic.com/my-wallet">Recharge Wallet</a>.You can use this to  <a href="www.saholic.com/recharge">recharge</a> your mobile or DTH.
175
        </p>
-
 
176
            
178
 
177
        <p>    
-
 
178
        <strong>Product: $voucherCode </strong>
179
        <a href="http://www.saholic.com/static/recharge-faq#Q3">Learn </a> how to use your wallet. In case of any questions please feel free to <a href="www.saholic.com/contact-us>Contact Us </a> 
179
        </p>
-
 
180
        
180
 
181
        
181
 
182
        <p>
-
 
183
        Regards,<br/>
182
        Regards,<br/>
184
        Saholic Customer Support Team<br/>
183
        Saholic Customer Support Team<br/>
185
        www.saholic.com<br/>
184
        www.saholic.com<br/>
186
        Email: help@saholic.com<br/>
185
        Email: help@saholic.com<br/>
187
        </p>
186
        </p>
188
        </div>
187
        </div>
189
        </body>
188
        </body>
190
        </html>
189
        </html>
191
        """
190
        """
192
 
191
        
193
    html = Template(html).substitute(dict(orderId=orderId,amount=amount,voucherCode=voucherCode))
192
    html = Template(html).substitute(dict(orderId=orderId,amount=amount,customer_name=customer_name))
194
    
193
    
195
    try:
194
    try:
196
        helper_client = HelperClient().get_client()
195
        helper_client = HelperClient().get_client()
197
        helper_client.saveUserEmailForSending(email, "", "Recharge voucher against order id " + str(orderId), html, str(orderId), "RechargeVoucher")
196
        helper_client.saveUserEmailForSending(email, "", "Your Free Mobile/DTH Recharge", html, str(orderId), "RechargeVoucher")
198
    except Exception as e:
197
    except Exception as e:
199
        print e
198
        print e
200
 
199
 
201
    
200
    
202
def main():
201
def main():
203
    parser = optparse.OptionParser()
202
    parser = optparse.OptionParser()
204
    #    parser.add_option("-d", "--days", dest="days",
-
 
205
    #                   default=5, type="int",
-
 
206
    #                   help="issue voucher to the delivered orders before NUM days",
-
 
207
    #                   metavar="NUM")
-
 
208
    parser.add_option("-H", "--host", dest="hostname",
203
    parser.add_option("-H", "--host", dest="hostname",
209
                      default="localhost",
204
                      default="localhost",
210
                      type="string", help="The HOST where the DB server is running",
205
                      type="string", help="The HOST where the DB server is running",
211
                      metavar="HOST")
206
                      metavar="HOST")
212
    (options, args) = parser.parse_args()
207
    (options, args) = parser.parse_args()
213
    if len(args) != 0:
208
    if len(args) != 0:
214
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
209
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
215
    #issue_voucher_to_orders(options.days, options.hostname)
-
 
216
    issue_voucher_to_orders(options.hostname)
210
    issue_voucher_to_orders(options.hostname)
217
    #checkVoucherStatus('SHL1340973067027')
-
 
218
    #deactivateVoucher('SHL1340973067027', 'Order not delivered')
-
 
219
 
211
 
220
if __name__ == '__main__':
212
if __name__ == '__main__':
221
    main()
213
    main()
222
214