Subversion Repositories SmartDukaan

Rev

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

Rev 6553 Rev 6561
Line 424... Line 424...
424
            end_date = end_date + datetime.timedelta(days = 1)
424
            end_date = end_date + datetime.timedelta(days = 1)
425
        start_date = start_date + datetime.timedelta(days = 1)
425
        start_date = start_date + datetime.timedelta(days = 1)
426
    
426
    
427
    return delivery_days
427
    return delivery_days
428
 
428
 
-
 
429
def get_business_days_count(start_time, end_time):
-
 
430
    '''
-
 
431
    Returns business dates between two dates
-
 
432
    '''
-
 
433
    start_date = start_time.date()
-
 
434
    end_date  = end_time.date()
-
 
435
    diff = (end_date - start_date).days + 1
-
 
436
    sundays = diff/7 + 1 if (start_date.weekday()==6) else 0 
-
 
437
    '''holidays = __get_holidays(start_time, end_time)'''
-
 
438
    logistics_client = LogisticsClient().get_client()
-
 
439
    #TODO: This list should be cached after the first call.
-
 
440
    #Calling logistics server is also unnecessary.
-
 
441
    holidays = logistics_client.getHolidays(to_java_date(start_time), to_java_date(end_time))
-
 
442
    non_business_days = len(holidays)
-
 
443
    for holiday in holidays:
-
 
444
        if holiday.weekday() == 6:
-
 
445
            sundays = sundays - 1
-
 
446
    return diff - (non_business_days + sundays)
-
 
447
            
-
 
448
 
429
def enqueue_transaction_info_email(transaction_id):
449
def enqueue_transaction_info_email(transaction_id):
430
    transaction = get_transaction(transaction_id)
450
    transaction = get_transaction(transaction_id)
431
    customer_name = "" 
451
    customer_name = "" 
432
    html_header = """
452
    html_header = """
433
<html>
453
<html>
Line 483... Line 503...
483
        
503
        
484
        for lineitem in order.lineitems:
504
        for lineitem in order.lineitems:
485
            lineitem_total_price = round(lineitem.total_price, 2)
505
            lineitem_total_price = round(lineitem.total_price, 2)
486
            
506
            
487
            html_tr += "<td>" + str(lineitem) + "</td>"
507
            html_tr += "<td>" + str(lineitem) + "</td>"
-
 
508
            if order.otg:
-
 
509
                html_tr += "<td align='center'><div>" + store_delivery_date + "</div><br><div>On Time Guarantee<span style=color:red>We pay id we delay</span></div></td>"
-
 
510
            else:
488
            html_tr += "<td align='center'>" + store_delivery_date + "</td>"
511
                html_tr += "<td align='center'>" + store_delivery_date + "</td>"
489
            html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
512
            html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
490
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
513
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
491
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
514
            html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
492
            total_amount += lineitem_total_price
515
            total_amount += lineitem_total_price
493
            html_table += html_tr
516
            html_table += html_tr
Line 692... Line 715...
692
    <body>
715
    <body>
693
    <div>
716
    <div>
694
        <p>
717
        <p>
695
            Dear $customer_name,<br /><br />
718
            Dear $customer_name,<br /><br />
696
    """
719
    """
697
    
720
 
698
    if order.pickupStoreId:
721
    if order.pickupStoreId:
699
        pickup_text = "Pickup Date: " + order.delivery_timestamp.strftime("%A, %d. %B %Y %I:%M%p")
722
        pickup_text = "Pickup Date: " + order.delivery_timestamp.strftime("%A, %d. %B %Y %I:%M%p")
700
        thank_you_html = """
723
        thank_you_html = """
701
        Thank you for shopping with us and picking up your order in Store. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers.<br><br>
724
        Thank you for shopping with us and picking up your order in Store. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers.<br><br>
702
    
725
    
703
        Following are the details of your order for which the pickup has happened. If you have not picked up this product please <a href="$source_url/contact-us" target="_blank">contact us</a> immediately.<br>
726
        Following are the details of your order for which the pickup has happened. If you have not picked up this product please <a href="$source_url/contact-us" target="_blank">contact us</a> immediately.<br>
704
        """
727
        """
705
    else:
728
    else:
706
        pickup_text = ""
729
        pickup_text = ""
-
 
730
        if order.otg:
-
 
731
            
-
 
732
            delayed = False
-
 
733
            fda = False
-
 
734
 
-
 
735
            if order.first_dlvyatmp_timestamp.date() < order.delivery_timestamp.date():
-
 
736
                fda = True
-
 
737
 
-
 
738
            fda_datetime = order.first_dlvyatmp_timestamp            
-
 
739
            fda_date = fda_datetime.date()
-
 
740
            
-
 
741
            if order.expected_delivery_time.date() < fda_date:
-
 
742
                delayed = True
-
 
743
 
-
 
744
            if not delayed and not fda:
-
 
745
                thank_you_html = """As Promised """ + str(order.lineitems[0]) +""" ordered by you has been <b>Delivered On Time.</b>""" 
-
 
746
            elif delayed:
-
 
747
                max_discount = 500
-
 
748
                delayedDays = get_business_days_count(order.expected_delivery_time + datetime.timedelta(days = 1), fda_datetime)
-
 
749
                max_discount = min(max_discount, order.lineitems[0].unit_price/10)
-
 
750
                discount = min(max_discount,delayedDays*50)  
-
 
751
                promotion_client = PromotionClient().get_client()
-
 
752
                endOn =  order.delivery_timestamp + datetime.timedelta(days = 30)
-
 
753
                endOn = to_java_date(endOn)
-
 
754
                otgCoupon = promotion_client.createCouponWithPrefix(27, endOn, order.customer_email, discount, False, 1, "otg")
707
        thank_you_html = """
755
                thank_you_html = '$prodName ordered by you has been delivered. We apologise for a delay of $delayedDays days. As per our <b>On Time Gaurantee</b> you have won a Gift Voucher worth <b>Rs.$discount</b>. Your unique Gift Voucher Code is <b>$otgCoupon</b>. You can use the same to buy any Mobile, Camera, Laptop, Tablet or Accessory from our website.'
-
 
756
                thank_you_html = Template(thank_you_html).substitute(dict(prodName=order.lineitems[0], delayedDays = delayedDays, discount = discount, otgCoupon = otgCoupon))
-
 
757
            elif fda:
-
 
758
                fdaFormattedString = order.first_dlvyatmp_timestamp.strftime("%A, %d. %B %Y")
-
 
759
                thank_you_html = str(order.lineitems[0]) + """ ordered by you has been delivered.  The First Delivery attempt was made on """+ fdaFormattedString +""" , within our commited estimated time for delivery.""" 
-
 
760
            
-
 
761
            thank_you_html = thank_you_html + """If you are happy with our services please join us on <a href="http://www.facebook.com/mysaholic">Facebook</a>/<a href="https://twitter.com/saholic">Twitter</a> and help us spread the word."""  
-
 
762
        
-
 
763
        else :
-
 
764
            thank_you_html = str(order.lineitems[0]) + """ ordered by you has been delivered. 
708
        Thank you for shopping with us. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers. Following are the details of your order.<br>
765
            Thank you for shopping with us. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers. Following are the details of your order.<br>
709
        """ 
766
            """ 
710
    
767
    
711
    html_header = html_header + thank_you_html + """        
768
    html_header = html_header + thank_you_html + """        
712
        </p>
769
        </p>
713
        <div>
770
        <div>
714
            Order Date: $order_date <br>
771
            Order Date: $order_date <br>
Line 1350... Line 1407...
1350
def mark_orders_as_delivered(provider_id, delivered_orders):
1407
def mark_orders_as_delivered(provider_id, delivered_orders):
1351
    for awb, detail in delivered_orders.iteritems():
1408
    for awb, detail in delivered_orders.iteritems():
1352
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
1409
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
1353
        if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
1410
        if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
1354
            continue
1411
            continue
-
 
1412
        timestamp, receiver = detail.split('|')
-
 
1413
        order.delivery_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
-
 
1414
        if order.first_dlvyatmp_timestamp is None:
1355
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
1415
            order.first_dlvyatmp_timestamp = order.delivery_timestamp
-
 
1416
        order.receiver = receiver
1356
        if order.pickupStoreId:
1417
        if order.pickupStoreId:
1357
            order.status = OrderStatus.DELIVERED_AT_STORE
1418
            order.status = OrderStatus.DELIVERED_AT_STORE
1358
            order.statusDescription = "Order delivered At Store"
1419
            order.statusDescription = "Order delivered At Store"
1359
            try:
1420
            try:
1360
                monitoredEntity = MonitoredEntity();
1421
                monitoredEntity = MonitoredEntity();
Line 1380... Line 1441...
1380
                alert_client = AlertClient().get_client()
1441
                alert_client = AlertClient().get_client()
1381
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
1442
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
1382
            except Exception as e:
1443
            except Exception as e:
1383
                print "Exception in scheduling alert in ShippedFromWarehouse method"
1444
                print "Exception in scheduling alert in ShippedFromWarehouse method"
1384
                print e
1445
                print e
1385
        timestamp, receiver = detail.split('|')
-
 
1386
        if order.first_dlvyatmp_timestamp is None:
-
 
1387
            order.first_dlvyatmp_timestamp = timestamp
-
 
1388
        order.delivery_timestamp = timestamp
-
 
1389
        order.receiver = receiver
-
 
1390
 
1446
 
1391
    session.commit()
1447
    session.commit()
1392
 
1448
 
1393
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
1449
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
1394
    order = Order.get_by(id=orderId)
1450
    order = Order.get_by(id=orderId)
Line 3492... Line 3548...
3492
            pc = PromotionClient().get_client()
3548
            pc = PromotionClient().get_client()
3493
            enddate = datetime.datetime.now() + datetime.timedelta(days=45)
3549
            enddate = datetime.datetime.now() + datetime.timedelta(days=45)
3494
            while totalAmount > 0:
3550
            while totalAmount > 0:
3495
                gvAmount = totalAmount if totalAmount <= 250 else 250
3551
                gvAmount = totalAmount if totalAmount <= 250 else 250
3496
                totalAmount = totalAmount - gvAmount
3552
                totalAmount = totalAmount - gvAmount
3497
                gv = pc.createCoupon(26, to_java_date(enddate), recharge_order.userEmailId, gvAmount, False, 1)
3553
                gv = pc.createCoupon(26, to_java_date(enddate), recharge_order.userEmailId, gvAmount, False, 1, None)
3498
                gvs[gv] = gvAmount  
3554
                gvs[gv] = gvAmount  
3499
        except:
3555
        except:
3500
            print "Not able to create gift voucher for user " + recharge_order.userEmailId
3556
            print "Not able to create gift voucher for user " + recharge_order.userEmailId
3501
    return gvs     
3557
    return gvs     
3502
 
3558
 
Line 3883... Line 3939...
3883
        return False
3939
        return False
3884
 
3940
 
3885
if __name__ == '__main__':
3941
if __name__ == '__main__':
3886
    print 'Inside main'
3942
    print 'Inside main'
3887
    DataService.initialize()
3943
    DataService.initialize()
3888
    a = MobileRechargeOrder()
3944
    '''a = MobileRechargeOrder()
-
 
3945
    session.commit()
3889
    a.mobileNumber = 89564785666
3946
    a.mobileNumber = 89564785666
3890
    session.commit()
3947
    session.commit()
3891
3948