Subversion Repositories SmartDukaan

Rev

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

Rev 4572 Rev 4615
Line 107... Line 107...
107
 
107
 
108
def process_non_delivery_report(provider):
108
def process_non_delivery_report(provider):
109
    try:
109
    try:
110
        filename = fetch_report(provider.name.upper() + ' UNDELIVERED REPORT')
110
        filename = fetch_report(provider.name.upper() + ' UNDELIVERED REPORT')
111
        undelivered_orders = read_undelivered_report(filename)
111
        undelivered_orders = read_undelivered_report(filename)
112
        update_reason_of_undelivered_orders(provider.id, undelivered_orders)
112
        orders_not_delivered = update_reason_of_undelivered_orders(provider.id, undelivered_orders)
-
 
113
        try:
-
 
114
            if orders_not_delivered:
-
 
115
                print "Undelivered Orders:"
-
 
116
                print orders_not_delivered
-
 
117
                mismatch_file = "/tmp/UndeliveredOrders.csv"
-
 
118
                print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
-
 
119
                print_undelivered_orders_report(mismatch_file, orders_not_delivered)
-
 
120
                pickup_mismatch_part = [get_attachment_part(mismatch_file)]
-
 
121
                mail(from_user, from_pwd, to,\
-
 
122
                     "Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
-
 
123
                     "This is a system generated email.Please don't reply to it.",\
-
 
124
                     pickup_mismatch_part)
-
 
125
        except:
-
 
126
                print "Some issue sending the undelivered orders report"
-
 
127
                traceback.print_exc()
113
    except:
128
    except:
114
        print "Some issue while processing the Non-delivery Report"
129
        print "Some issue while processing the Non-delivery Report"
115
        traceback.print_exc()
130
        traceback.print_exc()
116
    finally:
131
    finally:
117
        os.remove(filename)
132
        os.remove(filename)
118
 
133
 
119
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
134
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
120
    txnClient = TransactionClient().get_client()
135
    txnClient = TransactionClient().get_client()
121
    try:
136
    try:
122
        txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
137
        orders_not_delivered = txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
-
 
138
        return orders_not_delivered
123
    except TransactionServiceException as tex:
139
    except TransactionServiceException as tex:
124
        print tex.message
140
        print tex.message
125
 
141
 
126
def get_provider_by_name(provider_name):
142
def get_provider_by_name(provider_name):
127
    logistics_client = LogisticsClient().get_client()
143
    logistics_client = LogisticsClient().get_client()
Line 243... Line 259...
243
    writer.writerow(['AWB No', 'Return date', 'Reason'])
259
    writer.writerow(['AWB No', 'Return date', 'Reason'])
244
    for awb, date_reason in returned_orders.iteritems():
260
    for awb, date_reason in returned_orders.iteritems():
245
        date, reason = date_reason.split('|')
261
        date, reason = date_reason.split('|')
246
        writer.writerow([awb, date, reason])
262
        writer.writerow([awb, date, reason])
247
 
263
 
-
 
264
def print_undelivered_orders_report(filename, orders):
-
 
265
    writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
-
 
266
    writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
-
 
267
    for order in orders:
-
 
268
        writer.writerow([order.id, order.airwaybill_no, order.status, order.statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
-
 
269
 
248
def todays_date_string():
270
def todays_date_string():
249
    today_date = time.strftime("%d-%b-%Y")
271
    today_date = time.strftime("%d-%b-%Y")
250
    return '"' + today_date + '"'
272
    return '"' + today_date + '"'
251
 
273
 
252
def get_py_datetime(date, timeval):
274
def get_py_datetime(date, timeval):