Subversion Repositories SmartDukaan

Rev

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

Rev 5776 Rev 5778
Line 31... Line 31...
31
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
31
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
32
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
32
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
33
from shop2020.thriftpy.payments.ttypes import PaymentException
33
from shop2020.thriftpy.payments.ttypes import PaymentException
34
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
34
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
35
    WarehouseServiceException
35
    WarehouseServiceException
36
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part,\
36
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
37
    mail_html
-
 
38
from shop2020.utils.Utils import to_py_date, to_java_date
37
from shop2020.utils.Utils import to_py_date, to_java_date
39
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
38
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
40
from sqlalchemy.sql import func
39
from sqlalchemy.sql import func
41
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, select
40
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, select
42
from string import Template
41
from string import Template
Line 337... Line 336...
337
    
336
    
338
    return delivery_days
337
    return delivery_days
339
 
338
 
340
def enqueue_transaction_info_email(transaction_id):
339
def enqueue_transaction_info_email(transaction_id):
341
    transaction = get_transaction(transaction_id)
340
    transaction = get_transaction(transaction_id)
342
    customer_name = "" 
341
    
343
    html_header = """
342
    html_header = """
344
<html>
343
<html>
345
<body>
344
<body>
346
<div>
345
<div>
347
    <p>
346
    <p>
348
        Hello $customer_name,<br /><br />
347
        Hello,<br /><br />
349
        Thanks for placing order with us. Following are the details of your order:
348
        Thanks for placing order with us. Following are the details of your order:
350
    </p>
349
    </p>
351
    <div>
350
    <div>
352
        Order Date: $order_date
351
        Order Date: $order_date
353
    </div>
352
    </div>
Line 371... Line 370...
371
 
370
 
372
    orders = transaction.orders
371
    orders = transaction.orders
373
    html_pickup_text = ""
372
    html_pickup_text = ""
374
    random_text = ""
373
    random_text = ""
375
    if orders[0].pickupStoreId:
374
    if orders[0].pickupStoreId:
376
        random_text = str(randrange(100000, 999999)) 
375
        random_text = str(randrange(100000, 999999))
-
 
376
        html_pickup_text =  "Secret code for your order is " + random_text + ". Please tell store manager this secret code to get the order. " 
377
                
377
                
378
    for order in orders:
378
    for order in orders:
379
        customer_name = order.customer_name
-
 
380
        order_date = order.created_timestamp
379
        order_date = order.created_timestamp
381
        user_email = order.customer_email
380
        user_email = order.customer_email
382
        html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
381
        html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
383
 
382
 
384
        if order.pickupStoreId:
383
        if order.pickupStoreId:
Line 406... Line 405...
406
            <td> Rs. $total_amount</td>
405
            <td> Rs. $total_amount</td>
407
        </tr>
406
        </tr>
408
        </table>
407
        </table>
409
    </div>
408
    </div>
410
    """
409
    """
411
    
-
 
412
    store_address = ""
-
 
413
    if orders[0].pickupStoreId:
-
 
414
        store = LogisticsClient().get_client().getPickupStore(orders[0].pickupStoreId)
-
 
415
        store_address = __get_store_address_html(store)
-
 
416
 
-
 
417
        html_pickup_text = html_pickup_text + """
-
 
418
        <h3>Steps to Pickup In Store</h3>
-
 
419
        1) Estimated arrival date of your product(s) is $store_delivery_date at your selected Store.<br>
-
 
420
        2) You will receive a confirmation email from us when your product(s) reaches the store. Once you receive the same, please visit the following store selected by you.<br>
-
 
421
        <br><i>$store_address</i><br>
-
 
422
        """
-
 
423
 
-
 
424
        if orders[0].cod:
-
 
425
            html_pickup_text = html_pickup_text + """
-
 
426
            3) Pay Rs. $total_amount, present a valid Photo Identity Proof* and use your Secret Code <b><i>$secret_code</i></b> to claim your Product(s).<br><br>
-
 
427
            *Valid Photo Identity Proof are Driving License, Passport, PAN Card, Voter ID, Company Issued ID Card, College issued Student ID Card Or any other Government approved Photo Id.<br>
-
 
428
            <br>
-
 
429
            In case you have any questions please visit <a href="www.saholic.com/static/buy-online-pickup-in-store">Details on Pickup in Store</a>. If you still have more questions feel free to contact us 24/7 via <a href="http://www.saholic.com/contact-us">http://www.saholic.com/contact-us</a>
-
 
430
            </br><hr />
-
 
431
            """
-
 
432
        else:
-
 
433
            html_pickup_text = html_pickup_text + """
-
 
434
            3) Present a valid Photo Identity Proof* and use your Secret Code <b><i>$secret_code</i></b> to claim your Product(s).<br><br>
-
 
435
            *Valid Photo Identity Proof are Driving License, Passport, PAN Card, Voter ID, Company Issued ID Card, College issued Student ID Card Or any other Government approved Photo Id.<br>
-
 
436
            <br>
-
 
437
            In case you have any questions please visit <a href="www.saholic.com/static/buy-online-pickup-in-store">Details on Pickup in Store</a>. If you still have more questions feel free to contact us 24/7 via <a href="http://www.saholic.com/contact-us">http://www.saholic.com/contact-us</a>
-
 
438
            </br><hr />
-
 
439
            """
-
 
440
            
-
 
441
    html_footer = html_footer + html_pickup_text + """
410
    html_footer = html_footer + html_pickup_text + """
442
    <p>
411
    <p>
443
        Best Wishes,<br />
412
        Best Wishes,<br />
444
        Saholic Team
413
        Saholic Team
445
    </p>
414
    </p>
Line 448... Line 417...
448
</html>
417
</html>
449
    """
418
    """
450
 
419
 
451
    dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
420
    dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
452
    formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
421
    formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
453
 
-
 
454
    sdt = datetime.datetime.strptime(str(orders[0].expected_delivery_time), "%Y-%m-%d %H:%M:%S")
-
 
455
    store_delivery_date = sdt.strftime("%A, %d %B %Y")
-
 
456
 
422
    
457
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name))
423
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date))
458
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, secret_code = random_text, store_address = store_address, store_delivery_date = store_delivery_date))
424
    email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount))
459
    
425
    
460
    try:
426
    try:
461
        helper_client = HelperClient().get_client()
427
        helper_client = HelperClient().get_client()
462
        helper_client.saveUserEmailForSending(user_email, "", "Saholic - Order Details", email_header + html_table + email_footer, str(transaction_id), "TransactionInfo")
428
        helper_client.saveUserEmailForSending(user_email, "", "Saholic - Order Details", email_header + html_table + email_footer, str(transaction_id), "TransactionInfo")
463
        return True
429
        return True
Line 874... Line 840...
874
                    monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
840
                    monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
875
                    monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = "  + str(order.id);
841
                    monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = "  + str(order.id);
876
                    alert_client = AlertClient().get_client()
842
                    alert_client = AlertClient().get_client()
877
                    alert_client.scheduleAlert(monitoredEntity)
843
                    alert_client.scheduleAlert(monitoredEntity)
878
                except Exception as e:
844
                except Exception as e:
-
 
845
                    print "Exception in scheduling alert in ShippedFromWarehouse method"
879
                    print e
846
                    print e
880
        session.commit()
847
        session.commit()
881
        
848
        
882
        try:
849
        try:
883
            enqueue_shipping_confirmation_email(orders)
850
            enqueue_shipping_confirmation_email(orders)
Line 938... Line 905...
938
            monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
905
            monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
939
            monitoredEntity.description="providerId = " + str(provider_id) + "   " + pickup_details
906
            monitoredEntity.description="providerId = " + str(provider_id) + "   " + pickup_details
940
            alert_client = AlertClient().get_client()
907
            alert_client = AlertClient().get_client()
941
            alert_client.updateMonitoredObject(monitoredEntity)
908
            alert_client.updateMonitoredObject(monitoredEntity)
942
        except Exception as e:
909
        except Exception as e:
-
 
910
            print "Exception in updating alert in MarkOrdersAsPickedUp method"
943
            print e
911
            print e
944
    session.commit()
912
    session.commit()
945
 
913
 
946
def get_orders_not_picked_up(provider_id):
914
def get_orders_not_picked_up(provider_id):
947
    current_time = datetime.datetime.now()
915
    current_time = datetime.datetime.now()
Line 970... Line 938...
970
                monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
938
                monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
971
                monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = "  + str(order.id);
939
                monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = "  + str(order.id);
972
                alert_client = AlertClient().get_client()
940
                alert_client = AlertClient().get_client()
973
                alert_client.updateMonitoredObject(monitoredEntity)
941
                alert_client.updateMonitoredObject(monitoredEntity)
974
            except Exception as e:
942
            except Exception as e:
-
 
943
                print "Exception in updating alert in MarkOrdersAsDelivered method"
975
                print e
944
                print e
976
        else:
945
        else:
977
            order.status = OrderStatus.DELIVERY_SUCCESS
946
            order.status = OrderStatus.DELIVERY_SUCCESS
978
            order.statusDescription = "Order delivered"
947
            order.statusDescription = "Order delivered"
979
            update_trust_level(order)
948
            update_trust_level(order)
980
            try:
949
            try:
981
                alert_client = AlertClient().get_client()
950
                alert_client = AlertClient().get_client()
982
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
951
                alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
983
            except Exception as e:
952
            except Exception as e:
-
 
953
                print "Exception in scheduling alert in ShippedFromWarehouse method"
984
                print e
954
                print e
985
        timestamp, receiver = detail.split('|')
955
        timestamp, receiver = detail.split('|')
986
        if order.first_dlvyatmp_timestamp is None:
956
        if order.first_dlvyatmp_timestamp is None:
987
            order.first_dlvyatmp_timestamp = timestamp
957
            order.first_dlvyatmp_timestamp = timestamp
988
        order.delivery_timestamp = timestamp
958
        order.delivery_timestamp = timestamp
Line 1017... Line 987...
1017
        
987
        
1018
    try:
988
    try:
1019
        alert_client = AlertClient().get_client()
989
        alert_client = AlertClient().get_client()
1020
        alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
990
        alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
1021
    except Exception as e:
991
    except Exception as e:
-
 
992
        print "Exception in ending alert in MarkOrderAsDelivered method"
1022
        print e
993
        print e
1023
 
994
 
1024
    
995
    
1025
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
996
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
1026
    order = Order.get_by(id=orderId)
997
    order = Order.get_by(id=orderId)
Line 1101... Line 1072...
1101
    session.commit()
1072
    session.commit()
1102
    try:
1073
    try:
1103
        alert_client = AlertClient().get_client()
1074
        alert_client = AlertClient().get_client()
1104
        alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
1075
        alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
1105
    except Exception as e:
1076
    except Exception as e:
-
 
1077
        print "Exception in ending alert in MarkOrderAsRTO method"
1106
        print e
1078
        print e
1107
 
1079
 
1108
def get_rto_orders(provider_id):
1080
def get_rto_orders(provider_id):
1109
    current_time = datetime.datetime.now()
1081
    current_time = datetime.datetime.now()
1110
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
1082
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
Line 1170... Line 1142...
1170
            monitoredEntity.criticalExpiryTime = critical_time
1142
            monitoredEntity.criticalExpiryTime = critical_time
1171
            monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city 
1143
            monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city 
1172
            alert_client = AlertClient().get_client()
1144
            alert_client = AlertClient().get_client()
1173
            alert_client.updateMonitoredObject(monitoredEntity)
1145
            alert_client.updateMonitoredObject(monitoredEntity)
1174
        except Exception as e:
1146
        except Exception as e:
-
 
1147
            print "Exception in updating alert in MarkOrderAsLocalConnected method"
1175
            print e
1148
            print e
1176
        session.commit()
1149
        session.commit()
1177
 
1150
 
1178
def get_orders_not_local_connected(provider_id):
1151
def get_orders_not_local_connected(provider_id):
1179
    current_time = datetime.datetime.now()
1152
    current_time = datetime.datetime.now()
Line 1201... Line 1174...
1201
            monitoredEntity.criticalExpiryTime = critical_time
1174
            monitoredEntity.criticalExpiryTime = critical_time
1202
            monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city 
1175
            monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city 
1203
            alert_client = AlertClient().get_client()
1176
            alert_client = AlertClient().get_client()
1204
            alert_client.updateMonitoredObject(monitoredEntity)
1177
            alert_client.updateMonitoredObject(monitoredEntity)
1205
        except Exception as e:
1178
        except Exception as e:
-
 
1179
            print "Exception in updating alert in MarkOrderAsDestCityReached method"
1206
            print e
1180
            print e
1207
    session.commit()
1181
    session.commit()
1208
 
1182
 
1209
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
1183
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
1210
    for awb, detail in first_atdl_orders.iteritems():
1184
    for awb, detail in first_atdl_orders.iteritems():
Line 1231... Line 1205...
1231
            monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
1205
            monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
1232
            monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
1206
            monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
1233
            alert_client = AlertClient().get_client()
1207
            alert_client = AlertClient().get_client()
1234
            alert_client.updateMonitoredObject(monitoredEntity)
1208
            alert_client.updateMonitoredObject(monitoredEntity)
1235
        except Exception as e:
1209
        except Exception as e:
-
 
1210
            print "Exception in updating alert in MarkOrdersAsFirstDeliveryAttempted method"
1236
            print e
1211
            print e
1237
    session.commit()
1212
    session.commit()
1238
 
1213
 
1239
def get_orders_not_met_expected_delivery_date():
1214
def get_orders_not_met_expected_delivery_date():
1240
    current_time = datetime.datetime.now()
1215
    current_time = datetime.datetime.now()
Line 2046... Line 2021...
2046
    if store.line2:
2021
    if store.line2:
2047
        address = address + store.line2 + "\n"
2022
        address = address + store.line2 + "\n"
2048
    address = address + store.city + "\n"
2023
    address = address + store.city + "\n"
2049
    address = address + store.state + "\n"
2024
    address = address + store.state + "\n"
2050
    address = address + "PIN " + store.pin + "\n"
2025
    address = address + "PIN " + store.pin + "\n"
2051
    if store.phone:
-
 
2052
        address = address + "Phone: " + store.phone
2026
    address = address + "Phone: " + store.phone
2053
    return address
-
 
2054
 
-
 
2055
def __get_store_address_html(store):
-
 
2056
    address = store.name + "<br>" + store.line1 + "<br>"
-
 
2057
    if store.line2:
-
 
2058
        address = address + store.line2 + "<br>"
-
 
2059
    address = address + store.city + "<br>"
-
 
2060
    address = address + store.state + "<br>"
-
 
2061
    address = address + "PIN " + store.pin + "<br>"
-
 
2062
    if store.phone:
-
 
2063
        address = address + "Phone: " + store.phone
-
 
2064
    return address
2027
    return address
2065
 
2028
 
2066
def __generate_return_advice(order, warehouse, provider, filename):
2029
def __generate_return_advice(order, warehouse, provider, filename):
2067
    if warehouse.id == 7:
2030
    if warehouse.id == 7:
2068
        executive = 'Amit Kumar'
2031
        executive = 'Amit Kumar'