Subversion Repositories SmartDukaan

Rev

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

Rev 5806 Rev 5807
Line 596... Line 596...
596
        return True
596
        return True
597
    except Exception as e:
597
    except Exception as e:
598
        print e
598
        print e
599
        return False
599
        return False
600
 
600
 
-
 
601
def enqueue_delivery_successe_mail(order):
-
 
602
    html_header = """
-
 
603
    <html>
-
 
604
    <body>
-
 
605
    <div>
-
 
606
        <p>
-
 
607
            Dear $customer_name,<br /><br />
-
 
608
    """
-
 
609
    
-
 
610
    if order.pickupStoreId:
-
 
611
        pickup_text = "Pickup Date: " + order.delivery_timestamp.strftime("%A, %d. %B %Y %I:%M%p")
-
 
612
        thank_you_html = """
-
 
613
        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>
-
 
614
    
-
 
615
        Following are the details of your order for which the pickup has happened. If you have not picked up this product please <a href="http://www.saholic.com/contact-us" target="_blank">contact us</a> immediately.<br>
-
 
616
        """
-
 
617
    else:
-
 
618
        pickup_text = ""
-
 
619
        thank_you_html = """
-
 
620
        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>
-
 
621
        """ 
-
 
622
    
-
 
623
    html_header = html_header + thank_you_html + """        
-
 
624
        </p>
-
 
625
        <div>
-
 
626
            Order Date: $order_date <br>
-
 
627
            $pickup_text
-
 
628
        </div>
-
 
629
        <div>
-
 
630
            <table>
-
 
631
            <tr><td colspan="5"><hr /></td></tr>
-
 
632
            <tr><td colspan="5" align="left"><b>Order Details</b></td></tr>
-
 
633
            <tr><td colspan="5"><hr /></td></tr>
-
 
634
            <tr>
-
 
635
                <th width="100">Order No.</th>
-
 
636
                <th>Product</th>
-
 
637
                <th width="100">Quantity</th>
-
 
638
                <th width="100">Unit Price</th>
-
 
639
                <th width="100">Amount</th>
-
 
640
            </tr>
-
 
641
    """
-
 
642
    total_amount = 0.0
-
 
643
    html_table = ""
-
 
644
 
-
 
645
    customer_name = order.customer_name
-
 
646
    order_date = order.created_timestamp
-
 
647
    user_email = order.customer_email
-
 
648
    html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
-
 
649
    
-
 
650
    for lineitem in order.lineitems:
-
 
651
        lineitem_total_price = round(lineitem.total_price, 2)
-
 
652
        
-
 
653
        html_tr += "<td>" + str(lineitem) + "</td>"
-
 
654
        html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
-
 
655
        html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
-
 
656
        html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
-
 
657
        total_amount += lineitem_total_price
-
 
658
        html_table += html_tr
-
 
659
    
-
 
660
    html_footer = """
-
 
661
        <tr><td colspan=5>&nbsp;</td></tr>
-
 
662
        <tr><td colspan=5><hr /></td></tr>
-
 
663
        <tr>
-
 
664
            <td colspan=4>Total Amount</td>
-
 
665
            <td> Rs. $total_amount</td>
-
 
666
        </tr>
-
 
667
        </table>
-
 
668
    </div>
-
 
669
    <p>
-
 
670
        Best Wishes,<br />
-
 
671
        Saholic Team
-
 
672
    </p>
-
 
673
    </div>
-
 
674
    </body>
-
 
675
    </html>
-
 
676
    """
-
 
677
 
-
 
678
    subject = "Your order for " + str(order.lineitems[0]) + " is now complete"
-
 
679
    dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
-
 
680
    formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
-
 
681
 
-
 
682
    
-
 
683
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name, pickup_text = pickup_text))
-
 
684
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount))
-
 
685
    
-
 
686
    try:
-
 
687
        helper_client = HelperClient().get_client()
-
 
688
        helper_client.saveUserEmailForSending(user_email, "", subject, email_header + html_table + email_footer, str(order.id), "DeliverySuccess")
-
 
689
        return True
-
 
690
    except Exception as e:
-
 
691
        print e
-
 
692
        return False
601
 
693
 
602
def __get_secret_code(order_id):
694
def __get_secret_code(order_id):
603
    __get_order_attribute_value(order_id, 'SECRET_CODE')
695
    __get_order_attribute_value(order_id, 'SECRET_CODE')
604
 
696
 
605
def __get_order_attribute_value(order_id, attribute_name):
697
def __get_order_attribute_value(order_id, attribute_name):
Line 1129... Line 1221...
1129
                print e
1221
                print e
1130
        else:
1222
        else:
1131
            order.status = OrderStatus.DELIVERY_SUCCESS
1223
            order.status = OrderStatus.DELIVERY_SUCCESS
1132
            order.statusDescription = "Order delivered"
1224
            order.statusDescription = "Order delivered"
1133
            update_trust_level(order)
1225
            update_trust_level(order)
-
 
1226
            enqueue_delivery_successe_mail(order)
1134
            try:
1227
            try:
1135
                alert_client = AlertClient().get_client()
1228
                alert_client = AlertClient().get_client()
1136
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
1229
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
1137
            except Exception as e:
1230
            except Exception as e:
1138
                print "Exception in scheduling alert in ShippedFromWarehouse method"
1231
                print "Exception in scheduling alert in ShippedFromWarehouse method"
Line 1150... Line 1243...
1150
    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, OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_RECEIVED, OrderStatus.RET_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_AUTHORIZED, OrderStatus.RET_PICKUP_REQUEST_RAISED, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
1243
    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, OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_RECEIVED, OrderStatus.RET_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_AUTHORIZED, OrderStatus.RET_PICKUP_REQUEST_RAISED, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
1151
        raise TransactionServiceException(101, "Either wrond order id or invalid state " + str(orderId))
1244
        raise TransactionServiceException(101, "Either wrond order id or invalid state " + str(orderId))
1152
   
1245
   
1153
    # Provider is 4 is for self pickup and hardcoded. We should figure out a way to not to hard code.   
1246
    # Provider is 4 is for self pickup and hardcoded. We should figure out a way to not to hard code.   
1154
    if order.status == OrderStatus.BILLED and order.logistics_provider_id != 4:
1247
    if order.status == OrderStatus.BILLED and order.logistics_provider_id != 4:
1155
            raise TransactionServiceException(101, "Order is not marked for self pickup: " + str(orderId))
1248
        raise TransactionServiceException(101, "Order is not marked for self pickup: " + str(orderId))
1156
         
1249
         
1157
    if order.status in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
1250
    if order.status in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
1158
        order.delivery_timestamp = deliveryTimestamp
1251
        order.delivery_timestamp = deliveryTimestamp
1159
        order.receiver = receiver
1252
        order.receiver = receiver
1160
    order.status = OrderStatus.DELIVERY_SUCCESS
1253
    order.status = OrderStatus.DELIVERY_SUCCESS
Line 1163... Line 1256...
1163
    session.commit()
1256
    session.commit()
1164
    
1257
    
1165
    if order.pickupStoreId:
1258
    if order.pickupStoreId:
1166
        __push_collection_to_hotspot(order, "SALE")
1259
        __push_collection_to_hotspot(order, "SALE")
1167
    
1260
    
-
 
1261
    enqueue_delivery_successe_mail(order)
1168
#    if order.pickupStoreId:
1262
#    if order.pickupStoreId:
1169
#        payment_client = PaymentClient().get_client()
1263
#        payment_client = PaymentClient().get_client()
1170
#        payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
1264
#        payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
1171
#        payment_client = PaymentClient().get_client()
1265
#        payment_client = PaymentClient().get_client()
1172
#        payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
1266
#        payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())