| Line 26... |
Line 26... |
| 26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
| 27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 28 |
InventoryServiceException
|
28 |
InventoryServiceException
|
| 29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 31 |
HotspotAction, TimeoutSummary
|
31 |
HotspotAction, TimeoutSummary, OrderStatusGroups
|
| 32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 33 |
from shop2020.thriftpy.purchase.ttypes import PurchaseOrder, LineItem as POLineItem
|
33 |
from shop2020.thriftpy.purchase.ttypes import PurchaseOrder, LineItem as POLineItem
|
| 34 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, WarehouseServiceException
|
34 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, WarehouseServiceException
|
| 35 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
35 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 36 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
36 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| Line 462... |
Line 462... |
| 462 |
return order_ids
|
462 |
return order_ids
|
| 463 |
|
463 |
|
| 464 |
def get_cancellable_orders_for_customer(customer_id, limit = None):
|
464 |
def get_cancellable_orders_for_customer(customer_id, limit = None):
|
| 465 |
if not customer_id:
|
465 |
if not customer_id:
|
| 466 |
raise TransactionServiceException(101, "bad customer id")
|
466 |
raise TransactionServiceException(101, "bad customer id")
|
| 467 |
|
- |
|
| - |
|
467 |
cancellableOrderStatuses = OrderStatusGroups().codCancellable
|
| 468 |
query = Order.query.filter(Order.customer_id == customer_id)
|
468 |
query = Order.query.filter(Order.customer_id == customer_id)
|
| 469 |
query = query.filter(Order.status != OrderStatus.PAYMENT_FAILED)
|
- |
|
| 470 |
query = query.filter(Order.status != OrderStatus.REJECTED)
|
- |
|
| 471 |
query = query.filter(Order.status <= OrderStatus.BILLED)
|
469 |
query = query.filter(Order.status.in_(cancellableOrderStatuses))
|
| 472 |
orders = query.all()
|
470 |
orders = query.all()
|
| 473 |
return [order.id for order in orders]
|
471 |
return [order.id for order in orders]
|
| 474 |
|
472 |
|
| 475 |
def get_orders_by_billing_date(status, start_billing_date, end_billing_date, warehouse_id):
|
473 |
def get_orders_by_billing_date(status, start_billing_date, end_billing_date, warehouse_id):
|
| 476 |
if not warehouse_id:
|
474 |
if not warehouse_id:
|
| Line 1036... |
Line 1034... |
| 1036 |
order.status = OrderStatus.RET_PICKUP_REQUEST_RAISED
|
1034 |
order.status = OrderStatus.RET_PICKUP_REQUEST_RAISED
|
| 1037 |
order.statusDescription = "Pick up requested for RETURN"
|
1035 |
order.statusDescription = "Pick up requested for RETURN"
|
| 1038 |
else:
|
1036 |
else:
|
| 1039 |
order.status = OrderStatus.DOA_PICKUP_REQUEST_RAISED
|
1037 |
order.status = OrderStatus.DOA_PICKUP_REQUEST_RAISED
|
| 1040 |
order.statusDescription = "Pick up requested for DOA"
|
1038 |
order.statusDescription = "Pick up requested for DOA"
|
| - |
|
1039 |
order.doa_logistics_provider_id = providerId
|
| 1041 |
session.commit()
|
1040 |
session.commit()
|
| 1042 |
return True
|
1041 |
return True
|
| 1043 |
except Exception as e:
|
1042 |
except Exception as e:
|
| 1044 |
print sys.exc_info()[0]
|
1043 |
print sys.exc_info()[0]
|
| 1045 |
return False
|
1044 |
return False
|
| 1046 |
|
1045 |
|
| 1047 |
def authorize_pickup(order_id, pickup_number, providerId):
|
1046 |
def authorize_pickup(order_id, pickup_number, providerId):
|
| 1048 |
order = get_order(order_id)
|
1047 |
order = get_order(order_id)
|
| 1049 |
if order.status not in [OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.RET_PICKUP_REQUEST_RAISED]:
|
1048 |
if order.status not in [OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.RET_PICKUP_REQUEST_RAISED]:
|
| 1050 |
return False
|
1049 |
return False
|
| - |
|
1050 |
if order.doa_logistics_provider_id is not None:
|
| - |
|
1051 |
providerId = order.doa_logistics_provider_id #previously we are not storing this so data is taken from omdashboarduser
|
| 1051 |
from_user = 'help@shop2020.in'
|
1052 |
from_user = 'help@shop2020.in'
|
| 1052 |
from_pwd = '5h0p2o2o'
|
1053 |
from_pwd = '5h0p2o2o'
|
| 1053 |
subject = 'Pickup details'
|
1054 |
subject = 'Pickup details'
|
| 1054 |
filename = "/tmp/" + str(order.id) +".pdf"
|
1055 |
filename = "/tmp/" + str(order.id) +".pdf"
|
| 1055 |
try:
|
1056 |
try:
|
| Line 1064... |
Line 1065... |
| 1064 |
today = date.today().strftime("%d-%B-%Y (%A)")
|
1065 |
today = date.today().strftime("%d-%B-%Y (%A)")
|
| 1065 |
|
1066 |
|
| 1066 |
raw_message = '''
|
1067 |
raw_message = '''
|
| 1067 |
Dear Mr. %(customer_name)s,
|
1068 |
Dear Mr. %(customer_name)s,
|
| 1068 |
|
1069 |
|
| 1069 |
In reference to the return of order ID %(order_id)d. We request you to kindly pack the box properly with bubble wrap, and send it along with the original "DOA" certificate (in case of DOA) and the invoice.
|
1070 |
In reference to the return of order ID %(order_id)d, ''' + __generate_mail_body_for_authorize_pickup(order)
|
| - |
|
1071 |
raw_message = raw_message + '''
|
| 1070 |
Take a printout of the attachment in this mail which contains the delivery address and paste it on the packed parcel.
|
1072 |
Take a printout of the attachment in this mail which contains the delivery address and paste it on the packed parcel.
|
| 1071 |
We have instructed %(provider_name)s to pick up the material from the below mentioned address on %(date)s. %(provider_name)s pickup request number is %(pickup_request_no)s. Kindly keep the parcel ready.
|
1073 |
We have instructed %(provider_name)s to pick up the material from the below mentioned address on %(date)s. %(provider_name)s pickup request number is %(pickup_request_no)s. Kindly keep the parcel ready.
|
| 1072 |
|
1074 |
|
| 1073 |
Pickup will happen from the below mentioned address:-
|
1075 |
Pickup will happen from the below mentioned address:-
|
| 1074 |
|
1076 |
|
| Line 1104... |
Line 1106... |
| 1104 |
return False
|
1106 |
return False
|
| 1105 |
finally:
|
1107 |
finally:
|
| 1106 |
if os.path.exists(filename):
|
1108 |
if os.path.exists(filename):
|
| 1107 |
os.remove(filename)
|
1109 |
os.remove(filename)
|
| 1108 |
|
1110 |
|
| - |
|
1111 |
def __generate_mail_body_for_authorize_pickup(order):
|
| - |
|
1112 |
brand_msgbody_map = {'Nokia' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the all original accessories, original handset and the invoice.',
|
| - |
|
1113 |
'Micromax' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the all original accessories, original handset and the invoice.',
|
| - |
|
1114 |
'Karbonn' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the all original accessories, original handset and the invoice.',
|
| - |
|
1115 |
'Sony Ericsson' : 'we request you to kindly pack the original DOA certificate and the invoice.',
|
| - |
|
1116 |
'Others Handsets' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the original "DOA" certificate and the invoice. Please paste the original DOA on the sealed box. Kindly ensure that the product is properly sealed. If we receive open sealed products, we will not be able to accept.',
|
| - |
|
1117 |
'Handsets Return' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the all original accessories, original handset and the invoice.',
|
| - |
|
1118 |
'Accessories' : 'we request you to kindly pack the box properly with bubble wrap, and send it along with the original product and the invoice.'}
|
| - |
|
1119 |
categories = ["Handsets", "Tablets", "Laptops"]
|
| - |
|
1120 |
lineitem = order.lineitems[0]
|
| - |
|
1121 |
brand = lineitem.brand
|
| - |
|
1122 |
productGroup = lineitem.productGroup
|
| - |
|
1123 |
searchkey = None
|
| - |
|
1124 |
if productGroup not in categories:
|
| - |
|
1125 |
searchkey = 'Accessories'
|
| - |
|
1126 |
elif order.status == OrderStatus.RET_PICKUP_REQUEST_RAISED:
|
| - |
|
1127 |
searchkey = 'Handsets Return'
|
| - |
|
1128 |
elif brand == 'Nokia':
|
| - |
|
1129 |
searchkey = 'Nokia'
|
| - |
|
1130 |
elif brand == 'Micromax':
|
| - |
|
1131 |
searchkey = 'Micromax'
|
| - |
|
1132 |
elif brand == 'Karbonn':
|
| - |
|
1133 |
searchkey = 'Karbonn'
|
| - |
|
1134 |
elif brand == 'Sony Ericsson':
|
| - |
|
1135 |
searchkey = 'Sony Ericsson'
|
| - |
|
1136 |
else:
|
| - |
|
1137 |
searchkey = 'Others Handsets'
|
| - |
|
1138 |
return brand_msgbody_map.get(searchkey)
|
| - |
|
1139 |
|
| 1109 |
def mark_doas_as_picked_up(provider_id, pickup_details):
|
1140 |
def mark_doas_as_picked_up(provider_id, pickup_details):
|
| 1110 |
for pickupNo, doa_pickup_timestamp in pickup_details.iteritems():
|
1141 |
for pickupNo, doa_pickup_timestamp in pickup_details.iteritems():
|
| 1111 |
order = Order.query.filter_by(pickupRequestNo=pickupNo, logistics_provider_id = provider_id).first()
|
1142 |
order = Order.query.filter_by(pickupRequestNo=pickupNo, doa_logistics_provider_id = provider_id).first()
|
| 1112 |
if order == None or order.status != OrderStatus.DOA_PICKUP_CONFIRMED:
|
1143 |
if order == None or order.status != OrderStatus.DOA_PICKUP_CONFIRMED:
|
| 1113 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
1144 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
| 1114 |
continue
|
1145 |
continue
|
| 1115 |
order.status = OrderStatus.DOA_RETURN_IN_TRANSIT
|
1146 |
order.status = OrderStatus.DOA_RETURN_IN_TRANSIT
|
| 1116 |
order.statusDescription = "DOA picked up by Courier Company"
|
1147 |
order.statusDescription = "DOA picked up by Courier Company"
|
| 1117 |
order.doa_pickup_timestamp = doa_pickup_timestamp
|
1148 |
order.doa_pickup_timestamp = doa_pickup_timestamp
|
| 1118 |
session.commit()
|
1149 |
session.commit()
|
| 1119 |
|
1150 |
|
| 1120 |
current_time = datetime.datetime.now()
|
1151 |
current_time = datetime.datetime.now()
|
| 1121 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1152 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 1122 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.DOA_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
1153 |
orders_not_picked_up = Order.query.filter_by(doa_logistics_provider_id = provider_id).filter_by(status=OrderStatus.DOA_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
| 1123 |
return orders_not_picked_up
|
1154 |
return orders_not_picked_up
|
| 1124 |
|
1155 |
|
| 1125 |
def mark_return_orders_as_picked_up(provider_id, pickup_details):
|
1156 |
def mark_return_orders_as_picked_up(provider_id, pickup_details):
|
| 1126 |
for pickupNo, return_order_pickup_timestamp in pickup_details.iteritems():
|
1157 |
for pickupNo, return_order_pickup_timestamp in pickup_details.iteritems():
|
| 1127 |
order = Order.query.filter_by(pickupRequestNo=pickupNo, logistics_provider_id = provider_id).first()
|
1158 |
order = Order.query.filter_by(pickupRequestNo=pickupNo, doa_logistics_provider_id = provider_id).first()
|
| 1128 |
if order == None or order.status != OrderStatus.RET_PICKUP_CONFIRMED:
|
1159 |
if order == None or order.status != OrderStatus.RET_PICKUP_CONFIRMED:
|
| 1129 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
1160 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
| 1130 |
continue
|
1161 |
continue
|
| 1131 |
order.status = OrderStatus.RET_RETURN_IN_TRANSIT
|
1162 |
order.status = OrderStatus.RET_RETURN_IN_TRANSIT
|
| 1132 |
order.statusDescription = "Return order picked up by Courier Company"
|
1163 |
order.statusDescription = "Return order picked up by Courier Company"
|
| 1133 |
order.doa_pickup_timestamp = return_order_pickup_timestamp
|
1164 |
order.doa_pickup_timestamp = return_order_pickup_timestamp
|
| 1134 |
session.commit()
|
1165 |
session.commit()
|
| 1135 |
|
1166 |
|
| 1136 |
current_time = datetime.datetime.now()
|
1167 |
current_time = datetime.datetime.now()
|
| 1137 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1168 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 1138 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.RET_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
1169 |
orders_not_picked_up = Order.query.filter_by(doa_logistics_provider_id = provider_id).filter_by(status=OrderStatus.RET_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
| 1139 |
return orders_not_picked_up
|
1170 |
return orders_not_picked_up
|
| 1140 |
|
1171 |
|
| 1141 |
def receive_return(order_id, receiveCondition):
|
1172 |
def receive_return(order_id, receiveCondition):
|
| 1142 |
order = get_order(order_id)
|
1173 |
order = get_order(order_id)
|
| 1143 |
|
1174 |
|
| Line 1579... |
Line 1610... |
| 1579 |
address = address + order.customer_state + "\n"
|
1610 |
address = address + order.customer_state + "\n"
|
| 1580 |
address = address + "PIN " + order.customer_pincode + "\n"
|
1611 |
address = address + "PIN " + order.customer_pincode + "\n"
|
| 1581 |
address = address + "Phone: " + order.customer_mobilenumber
|
1612 |
address = address + "Phone: " + order.customer_mobilenumber
|
| 1582 |
return address
|
1613 |
return address
|
| 1583 |
|
1614 |
|
| 1584 |
def __generate_return_advice(order, warehouse, provider, filename):
|
1615 |
def __generate_return_advice(order, warehouse, provider, filename):
|
| - |
|
1616 |
if warehouse.id == 7:
|
| - |
|
1617 |
executive = 'Amit Kumar'
|
| - |
|
1618 |
executive_phone = 'Phone: 9911122634'
|
| - |
|
1619 |
else:
|
| - |
|
1620 |
executive = 'Prashant Sharma'
|
| - |
|
1621 |
executive_phone = 'Phone: 8826894193'
|
| 1585 |
pdf = Canvas(filename)
|
1622 |
pdf = Canvas(filename)
|
| 1586 |
pdf.setFont('Times-Bold',16)
|
1623 |
pdf.setFont('Times-Bold',16)
|
| 1587 |
address_text = pdf.beginText(inch, PAGE_HEIGHT - inch)
|
1624 |
address_text = pdf.beginText(inch, PAGE_HEIGHT - inch)
|
| 1588 |
address_text.textLine("To")
|
1625 |
address_text.textLine("To")
|
| 1589 |
address_text.textLine("Parmod Kumar")
|
1626 |
address_text.textLine(executive)
|
| 1590 |
for line in warehouse.location.split("\n"):
|
1627 |
for line in warehouse.location.split("\n"):
|
| 1591 |
address_text.textLine(line)
|
1628 |
address_text.textLine(line)
|
| 1592 |
address_text.textLine("PIN " + warehouse.pincode)
|
1629 |
address_text.textLine("PIN " + warehouse.pincode)
|
| 1593 |
address_text.textLine("")
|
1630 |
address_text.textLine("")
|
| 1594 |
address_text.textLine("Phone: 9971573026")
|
1631 |
address_text.textLine(executive_phone)
|
| 1595 |
pdf.drawText(address_text)
|
1632 |
pdf.drawText(address_text)
|
| 1596 |
|
1633 |
|
| 1597 |
pdf.setFont('Times-Roman',12)
|
1634 |
pdf.setFont('Times-Roman',12)
|
| 1598 |
order_text = pdf.beginText(inch, PAGE_HEIGHT - 4 * inch)
|
1635 |
order_text = pdf.beginText(inch, PAGE_HEIGHT - 4 * inch)
|
| 1599 |
order_text.textLine("Pickup CODE: " + provider.details[DeliveryType.PREPAID].accountNo)
|
1636 |
order_text.textLine("Pickup CODE: " + provider.details[DeliveryType.PREPAID].accountNo)
|
| Line 2164... |
Line 2201... |
| 2164 |
return order
|
2201 |
return order
|
| 2165 |
|
2202 |
|
| 2166 |
def get_orders_for_provider_for_status(provider_id, order_status):
|
2203 |
def get_orders_for_provider_for_status(provider_id, order_status):
|
| 2167 |
if not provider_id or not order_status:
|
2204 |
if not provider_id or not order_status:
|
| 2168 |
raise TransactionServiceException(101, "bad provider id or order status")
|
2205 |
raise TransactionServiceException(101, "bad provider id or order status")
|
| - |
|
2206 |
if order_status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.RET_PICKUP_CONFIRMED]:
|
| - |
|
2207 |
query = Order.query.filter_by(doa_logistics_provider_id = provider_id, status = order_status)
|
| - |
|
2208 |
else:
|
| 2169 |
query = Order.query.filter_by(logistics_provider_id = provider_id, status = order_status)
|
2209 |
query = Order.query.filter_by(logistics_provider_id = provider_id, status = order_status)
|
| 2170 |
return query.all()
|
2210 |
return query.all()
|
| 2171 |
|
2211 |
|
| 2172 |
def get_billed_orders_for_vendor(vendor_id, billing_date_from, billing_date_to):
|
2212 |
def get_billed_orders_for_vendor(vendor_id, billing_date_from, billing_date_to):
|
| 2173 |
query = Order.query.filter_by(vendorId = vendor_id)
|
2213 |
query = Order.query.filter_by(vendorId = vendor_id)
|
| 2174 |
query = query.filter(Order.status != OrderStatus.PAYMENT_PENDING)
|
2214 |
query = query.filter(Order.status != OrderStatus.PAYMENT_PENDING)
|