Rev 7127 | Rev 10298 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''It processes the following reports received from Couriersthrough email:1. Pickup Report : contains details of orders that werepicked up from our warehouse, Return orders and DOA orders that werepicked up from our customers.2. Delivery & RTO Report: contains details of orders thatwere either successfully delivered to our customers orwhich are being returned to us.3. Non-delivery Report: contains details of orders whosedelivery date has passed but which have not beendelivered yet.It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,Undelivered orders report and Returned Orders report to cnc.center@shop2020.in@author: Chandranshu'''from shop2020.clients import HelperClientfrom shop2020.model.v1.order.impl.DataService import Order, LineItemfrom shop2020.thriftpy.model.v1.user.ttypes import Userfrom string import Templateimport csvimport datetimeimport optparseimport sysimport timeimport tracebackimport xlrdfrom shop2020.utils.Utils import to_py_dateif __name__ == '__main__' and __package__ is None:import ossys.path.insert(0, os.getcwd())logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 2: {'name': 'Aramex', 'phone': '0124- 39419900'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}}FDASubjectTemplate = Template('First attempt made to deliver your $productName')FDABodyTemplate = Template('<div>'+'<p> Dear $customerName,<br>'+'<br>An attempt was made to deliver the product you ordered. The Courier '+'used was: $courierName and Airway Bill Number: $awbNumber. '+'However, the product could not be delivered due to $delayReason. '+'Please<a target="_blank" href="http://saholic.com/contactus"> Contact us </a>to coordinate the next delivery date.</p>'+'<div> <span>Order</span> Date: $orderDate</div>'+'<div>'+'<table>'+' <tbody>'+' <tr>'+' <td colspan="6">'+' <hr></td>'+' </tr>'+' <tr>'+' <td align="left" colspan="6"><b><span>Order</span> <span>Details</span></b></td>'+' </tr>'+' <tr>'+' <td colspan="6">'+' <hr></td>'+' </tr>'+' <tr>'+' <th width="100"><span>Order</span> No.</th>'+' <th>Product</th>'+' <th width="100">Quantity</th>'+' <td style="vertical-align:top"><span style="font-weight:bold">First Delivery Attempt</span><br>'+' </td>'+'<th width="100">Unit Price</th>'+' <th width="100">Amount</th>'+' </tr>'+' <tr>'+' <td align="center">$orderId</td>'+' <td>$productName</td>'+' <td align="center">$quantity</td>'+' <td style="vertical-align:top">$fdaDate</td>'+'<td align="center"> Rs. $unitPrice</td>'+' <td align="center"> Rs. $total</td>'+' </tr>'+' '+' <tr>'+' <td colspan="6">'+' <hr></td>'+' </tr>'+' <tr>'+' <td colspan="5">Total Amount</td>'+' <td> Rs. $totalAmount</td>'+' </tr>'+' <tr>'+' <td style="vertical-align:top" rowspan="1" colspan="6"><br>'+'</td>'+' </tr>'+'<tr>'+' <td colspan="6">'+' <hr></td>'+' </tr>'+' </tbody>'+'</table>'+'</div>'+'<br>'+'<p>Best Wishes,<br>'+'Saholic Team </p>'+'</div>')def enqueueMailForFDA(order):dt = to_py_date(order.created_timestamp)formatted_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")sdt = to_py_date(order.first_attempt_timestamp)fda_date = sdt.strftime("%d %B %Y")'''order.lineitems[0]'''lineitem = order.lineitems[0]productName = "{0} {1} {2} {3}".format(lineitem.brand or "", lineitem.model_name or "", lineitem.model_number or "", lineitem.color or "")subject = FDASubjectTemplate.substitute(productName=productName)body = FDABodyTemplate.substitute(productName=productName, customerName=order.customer_name, quantity="%.0f" % lineitem.quantity,orderDate=formatted_order_date, orderId=order.id, unitPrice="%.2f" % lineitem.unit_price,total = "%.2f" % lineitem.total_price, totalAmount = "%.2f" % order.total_amount, fdaDate= fda_date,delayReason=order.statusDescription , awbNumber=order.airwaybill_no, courierName = logistics_providers[order.logistics_provider_id]['name'])print bodytry:helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()helper_client.saveUserEmailForSending([order.customer_email], "", subject, body, str(order.id), "FirstDeliveryAttempted", [], ['anupam.singh@shop2020.in', 'rajneesh.arora@shop2020.in', 'pramit.singh@shop2020.in', 'amit.sirohi@shop2020.in', 'rajveer.singh@shop2020.in'], 1)except Exception as e:print "Some problem occurred while enquing mail for user" + str(order.id) +" to inform FIRST_DELIVERY_ATTEMPT_MADE status"print e