| Line 2055... |
Line 2055... |
| 2055 |
attr.value = attribute.value
|
2055 |
attr.value = attribute.value
|
| 2056 |
session.commit()
|
2056 |
session.commit()
|
| 2057 |
|
2057 |
|
| 2058 |
def mark_orders_as_picked_up(provider_id, pickup_details):
|
2058 |
def mark_orders_as_picked_up(provider_id, pickup_details):
|
| 2059 |
for awb, pickup_timestamp in pickup_details.iteritems():
|
2059 |
for awb, pickup_timestamp in pickup_details.iteritems():
|
| - |
|
2060 |
orders = []
|
| 2060 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2061 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| 2061 |
if order == None or order.status != OrderStatus.SHIPPED_FROM_WH:
|
2062 |
if orders == None or len(orders) ==0:
|
| 2062 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
- |
|
| 2063 |
continue
|
2063 |
continue
|
| - |
|
2064 |
for order in orders:
|
| - |
|
2065 |
if order.status != OrderStatus.SHIPPED_FROM_WH:
|
| - |
|
2066 |
continue
|
| 2064 |
order.status = OrderStatus.SHIPPED_TO_LOGST
|
2067 |
order.status = OrderStatus.SHIPPED_TO_LOGST
|
| 2065 |
order.statusDescription = "Order picked up by Courier Company"
|
2068 |
order.statusDescription = "Order picked up by Courier Company"
|
| 2066 |
order.pickup_timestamp = pickup_timestamp
|
2069 |
order.pickup_timestamp = pickup_timestamp
|
| 2067 |
|
2070 |
|
| 2068 |
try:
|
2071 |
try:
|
| 2069 |
monitoredEntity = MonitoredEntity();
|
2072 |
monitoredEntity = MonitoredEntity();
|
| 2070 |
monitoredEntity.entityType=EntityType.COURIER;
|
2073 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 2071 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_LOGST
|
2074 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_LOGST
|
| 2072 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
2075 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 2073 |
adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 2);
|
2076 |
adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 2);
|
| 2074 |
sec = datetime.datetime.now()
|
2077 |
sec = datetime.datetime.now()
|
| 2075 |
#Warn alert time is taken as 26 hrs
|
2078 |
#Warn alert time is taken as 26 hrs
|
| 2076 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDays-2)) + timedelta(hours=26))
|
2079 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDays-2)) + timedelta(hours=26))
|
| 2077 |
#Critical alert time is taken as 36 hrs
|
2080 |
#Critical alert time is taken as 36 hrs
|
| 2078 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=36))
|
2081 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=36))
|
| 2079 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
2082 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
| 2080 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
2083 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 2081 |
monitoredEntity.description="providerId = " + str(provider_id)
|
2084 |
monitoredEntity.description="providerId = " + str(provider_id)
|
| 2082 |
alert_client = AlertClient().get_client()
|
2085 |
alert_client = AlertClient().get_client()
|
| 2083 |
alert_client.updateMonitoredObject(monitoredEntity)
|
2086 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 2084 |
except Exception as e:
|
2087 |
except Exception as e:
|
| 2085 |
print "Exception in updating alert in MarkOrdersAsPickedUp method"
|
2088 |
print "Exception in updating alert in MarkOrdersAsPickedUp method"
|
| 2086 |
print e
|
2089 |
print e
|
| 2087 |
session.commit()
|
2090 |
session.commit()
|
| 2088 |
|
2091 |
|
| 2089 |
def get_orders_not_picked_up(provider_id):
|
2092 |
def get_orders_not_picked_up(provider_id):
|
| 2090 |
current_time = datetime.datetime.now()
|
2093 |
current_time = datetime.datetime.now()
|
| 2091 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2094 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2092 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.SHIPPED_FROM_WH).filter(Order.shipping_timestamp <= to_datetime).all()
|
2095 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.SHIPPED_FROM_WH).filter(Order.shipping_timestamp <= to_datetime).all()
|
| 2093 |
return orders_not_picked_up
|
2096 |
return orders_not_picked_up
|
| 2094 |
|
2097 |
|
| 2095 |
def mark_orders_as_delivered(provider_id, delivered_orders):
|
2098 |
def mark_orders_as_delivered(provider_id, delivered_orders):
|
| 2096 |
for awb, detail in delivered_orders.iteritems():
|
2099 |
for awb, detail in delivered_orders.iteritems():
|
| - |
|
2100 |
orders = []
|
| 2097 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2101 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| 2098 |
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]:
|
2102 |
if orders == None or len(orders) ==0:
|
| 2099 |
continue
|
2103 |
continue
|
| - |
|
2104 |
for order in orders:
|
| - |
|
2105 |
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]:
|
| - |
|
2106 |
continue
|
| 2100 |
timestamp, receiver = detail.split('|')
|
2107 |
timestamp, receiver = detail.split('|')
|
| 2101 |
order.delivery_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
2108 |
order.delivery_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
| 2102 |
if order.first_dlvyatmp_timestamp is None:
|
2109 |
if order.first_dlvyatmp_timestamp is None:
|
| 2103 |
order.first_dlvyatmp_timestamp = order.delivery_timestamp
|
2110 |
order.first_dlvyatmp_timestamp = order.delivery_timestamp
|
| 2104 |
order.receiver = receiver
|
2111 |
order.receiver = receiver
|
| 2105 |
if order.pickupStoreId:
|
2112 |
if order.pickupStoreId:
|
| 2106 |
order.status = OrderStatus.DELIVERED_AT_STORE
|
2113 |
order.status = OrderStatus.DELIVERED_AT_STORE
|
| 2107 |
order.statusDescription = "Order delivered At Store"
|
2114 |
order.statusDescription = "Order delivered At Store"
|
| 2108 |
try:
|
- |
|
| 2109 |
monitoredEntity = MonitoredEntity();
|
- |
|
| 2110 |
monitoredEntity.entityType=EntityType.COURIER;
|
- |
|
| 2111 |
monitoredEntity.eventType=OrderStatus.DELIVERED_AT_STORE;
|
- |
|
| 2112 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
- |
|
| 2113 |
#adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 1);
|
- |
|
| 2114 |
sec = datetime.datetime.now()
|
- |
|
| 2115 |
#Critical alert time is taken as 26 hrs
|
- |
|
| 2116 |
critical_time = (sec + timedelta(hours=4))
|
- |
|
| 2117 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
- |
|
| 2118 |
monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = " + str(order.id);
|
- |
|
| 2119 |
alert_client = AlertClient().get_client()
|
- |
|
| 2120 |
alert_client.updateMonitoredObject(monitoredEntity)
|
- |
|
| 2121 |
except Exception as e:
|
- |
|
| 2122 |
print e
|
- |
|
| 2123 |
else:
|
- |
|
| 2124 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
- |
|
| 2125 |
order.statusDescription = "Order delivered"
|
- |
|
| 2126 |
update_trust_level(order)
|
- |
|
| 2127 |
if order.insuranceDetails:
|
- |
|
| 2128 |
try:
|
2115 |
try:
|
| 2129 |
update_insurance_details(order)
|
2116 |
monitoredEntity = MonitoredEntity();
|
| - |
|
2117 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
2118 |
monitoredEntity.eventType=OrderStatus.DELIVERED_AT_STORE;
|
| - |
|
2119 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
2120 |
#adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 1);
|
| 2130 |
except:
|
2121 |
sec = datetime.datetime.now()
|
| 2131 |
print "Error generating insurance file for order " + str(order.id)
|
2122 |
#Critical alert time is taken as 26 hrs
|
| - |
|
2123 |
critical_time = (sec + timedelta(hours=4))
|
| - |
|
2124 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| - |
|
2125 |
monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = " + str(order.id);
|
| - |
|
2126 |
alert_client = AlertClient().get_client()
|
| - |
|
2127 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 2132 |
session.rollback()
|
2128 |
except Exception as e:
|
| 2133 |
return
|
2129 |
print e
|
| 2134 |
|
2130 |
else:
|
| - |
|
2131 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
| - |
|
2132 |
order.statusDescription = "Order delivered"
|
| - |
|
2133 |
update_trust_level(order)
|
| 2135 |
if order.dataInsuranceDetails:
|
2134 |
if order.insuranceDetails:
|
| - |
|
2135 |
try:
|
| 2136 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
2136 |
update_insurance_details(order)
|
| - |
|
2137 |
except:
|
| 2137 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
2138 |
print "Error generating insurance file for order " + str(order.id)
|
| - |
|
2139 |
session.rollback()
|
| - |
|
2140 |
return
|
| 2138 |
|
2141 |
|
| - |
|
2142 |
if order.dataInsuranceDetails:
|
| - |
|
2143 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
| - |
|
2144 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
| - |
|
2145 |
|
| 2139 |
if enqueue_delivery_success_mail(order) :
|
2146 |
if enqueue_delivery_success_mail(order) :
|
| 2140 |
session.commit()
|
2147 |
session.commit()
|
| 2141 |
else :
|
2148 |
else :
|
| 2142 |
session.rollback()
|
2149 |
session.rollback()
|
| 2143 |
try:
|
2150 |
try:
|
| 2144 |
alert_client = AlertClient().get_client()
|
2151 |
alert_client = AlertClient().get_client()
|
| 2145 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
2152 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 2146 |
except Exception as e:
|
2153 |
except Exception as e:
|
| 2147 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
2154 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 2148 |
print e
|
2155 |
print e
|
| 2149 |
|
2156 |
|
| 2150 |
def update_insurance_details(order):
|
2157 |
def update_insurance_details(order):
|
| 2151 |
order.insuranceDetails[0].startDate = order.delivery_timestamp
|
2158 |
order.insuranceDetails[0].startDate = order.delivery_timestamp
|
| 2152 |
order.insuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 365)
|
2159 |
order.insuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 365)
|
| 2153 |
filename = "/tmp/" + str(order.id) + "-insurance-policy.pdf"
|
2160 |
filename = "/tmp/" + str(order.id) + "-insurance-policy.pdf"
|
| Line 2158... |
Line 2165... |
| 2158 |
doc.docType = 1
|
2165 |
doc.docType = 1
|
| 2159 |
doc.docSource = order.id
|
2166 |
doc.docSource = order.id
|
| 2160 |
doc.document = pdfFile
|
2167 |
doc.document = pdfFile
|
| 2161 |
|
2168 |
|
| 2162 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
2169 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
| 2163 |
order = Order.get_by(id=orderId)
|
- |
|
| 2164 |
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]:
|
- |
|
| 2165 |
raise TransactionServiceException(101, "Either wrong order id or invalid state " + str(orderId))
|
- |
|
| 2166 |
|
- |
|
| 2167 |
# Provider is 4 is for self pickup and hardcoded. We should figure out a way to not to hard code.
|
- |
|
| 2168 |
if order.status == OrderStatus.BILLED and order.logistics_provider_id != 4:
|
- |
|
| 2169 |
raise TransactionServiceException(101, "Order is not marked for self pickup: " + str(orderId))
|
- |
|
| 2170 |
|
- |
|
| 2171 |
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]:
|
2170 |
singleOrder = Order.get_by(id=orderId)
|
| 2172 |
order.delivery_timestamp = deliveryTimestamp
|
- |
|
| 2173 |
if order.first_dlvyatmp_timestamp is None:
|
- |
|
| 2174 |
order.first_dlvyatmp_timestamp = deliveryTimestamp
|
- |
|
| 2175 |
order.receiver = receiver
|
- |
|
| 2176 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
- |
|
| 2177 |
order.statusDescription = "Order delivered"
|
- |
|
| 2178 |
update_trust_level(order)
|
- |
|
| 2179 |
if order.insuranceDetails:
|
- |
|
| 2180 |
try:
|
- |
|
| 2181 |
update_insurance_details(order)
|
- |
|
| 2182 |
except:
|
- |
|
| 2183 |
print "Error generating insurance file for order " + str(order.id)
|
- |
|
| 2184 |
session.rollback()
|
- |
|
| 2185 |
return
|
- |
|
| 2186 |
if order.dataInsuranceDetails:
|
- |
|
| 2187 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
- |
|
| 2188 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
- |
|
| 2189 |
|
2171 |
|
| 2190 |
if order.source == 2:
|
2172 |
grouppedOrdersList = []
|
| 2191 |
sod = StoreOrderDetail.get_by(orderId = order.id)
|
- |
|
| 2192 |
sod.payStatus = StorePaymentStatus.FULL_PAY_RECEIVED
|
- |
|
| 2193 |
session.commit()
|
- |
|
| 2194 |
|
- |
|
| 2195 |
if order.pickupStoreId and order.cod:
|
2173 |
if singleOrder.logisticsTransactionId:
|
| 2196 |
__push_collection_to_hotspot(order, "SALE")
|
2174 |
grouppedOrdersList = get_group_orders_by_logistics_txn_id(singleOrder.logisticsTransactionId)
|
| 2197 |
|
2175 |
else:
|
| 2198 |
enqueue_delivery_success_mail(order)
|
2176 |
grouppedOrdersList.append(singleOrder)
|
| 2199 |
# if order.pickupStoreId:
|
- |
|
| 2200 |
# payment_client = PaymentClient().get_client()
|
- |
|
| 2201 |
# payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
|
- |
|
| 2202 |
# payment_client = PaymentClient().get_client()
|
- |
|
| 2203 |
# payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
|
- |
|
| 2204 |
# order.cod_reconciliation_timestamp = datetime.datetime.now()
|
- |
|
| 2205 |
# session.commit()
|
- |
|
| 2206 |
|
2177 |
|
| - |
|
2178 |
for order in grouppedOrdersList:
|
| 2207 |
try:
|
2179 |
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]:
|
| - |
|
2180 |
raise TransactionServiceException(101, "Either wrong order id or invalid state " + str(orderId))
|
| - |
|
2181 |
|
| - |
|
2182 |
# Provider is 4 is for self pickup and hardcoded. We should figure out a way to not to hard code.
|
| - |
|
2183 |
if order.status == OrderStatus.BILLED and order.logistics_provider_id != 4:
|
| - |
|
2184 |
raise TransactionServiceException(101, "Order is not marked for self pickup: " + str(orderId))
|
| - |
|
2185 |
|
| - |
|
2186 |
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]:
|
| - |
|
2187 |
order.delivery_timestamp = deliveryTimestamp
|
| - |
|
2188 |
if order.first_dlvyatmp_timestamp is None:
|
| - |
|
2189 |
order.first_dlvyatmp_timestamp = deliveryTimestamp
|
| - |
|
2190 |
order.receiver = receiver
|
| - |
|
2191 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
| - |
|
2192 |
order.statusDescription = "Order delivered"
|
| - |
|
2193 |
update_trust_level(order)
|
| - |
|
2194 |
if order.insuranceDetails:
|
| - |
|
2195 |
try:
|
| - |
|
2196 |
update_insurance_details(order)
|
| - |
|
2197 |
except:
|
| - |
|
2198 |
print "Error generating insurance file for order " + str(order.id)
|
| - |
|
2199 |
session.rollback()
|
| - |
|
2200 |
return
|
| - |
|
2201 |
if order.dataInsuranceDetails:
|
| - |
|
2202 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
| - |
|
2203 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
| - |
|
2204 |
|
| - |
|
2205 |
if order.source == 2:
|
| - |
|
2206 |
sod = StoreOrderDetail.get_by(orderId = order.id)
|
| - |
|
2207 |
sod.payStatus = StorePaymentStatus.FULL_PAY_RECEIVED
|
| - |
|
2208 |
session.commit()
|
| - |
|
2209 |
|
| - |
|
2210 |
if order.pickupStoreId and order.cod:
|
| - |
|
2211 |
__push_collection_to_hotspot(order, "SALE")
|
| - |
|
2212 |
|
| - |
|
2213 |
enqueue_delivery_success_mail(order)
|
| - |
|
2214 |
# if order.pickupStoreId:
|
| - |
|
2215 |
# payment_client = PaymentClient().get_client()
|
| - |
|
2216 |
# payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
|
| - |
|
2217 |
# payment_client = PaymentClient().get_client()
|
| - |
|
2218 |
# payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
|
| - |
|
2219 |
# order.cod_reconciliation_timestamp = datetime.datetime.now()
|
| - |
|
2220 |
# session.commit()
|
| - |
|
2221 |
|
| - |
|
2222 |
try:
|
| 2208 |
alert_client = AlertClient().get_client()
|
2223 |
alert_client = AlertClient().get_client()
|
| 2209 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
2224 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 2210 |
except Exception as e:
|
2225 |
except Exception as e:
|
| 2211 |
print "Exception in ending alert in MarkOrderAsDelivered method"
|
2226 |
print "Exception in ending alert in MarkOrderAsDelivered method"
|
| 2212 |
print e
|
2227 |
print e
|
| 2213 |
|
2228 |
|
| 2214 |
|
2229 |
|
| 2215 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
2230 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
| 2216 |
order = Order.get_by(id=orderId)
|
2231 |
order = Order.get_by(id=orderId)
|
| 2217 |
if order != None or 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.DELIVERED_AT_STORE]:
|
2232 |
if order != None or 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.DELIVERED_AT_STORE]:
|
| Line 2232... |
Line 2247... |
| 2232 |
|
2247 |
|
| 2233 |
|
2248 |
|
| 2234 |
|
2249 |
|
| 2235 |
def mark_orders_as_rto(provider_id, returned_orders):
|
2250 |
def mark_orders_as_rto(provider_id, returned_orders):
|
| 2236 |
for awb, detail in returned_orders.iteritems():
|
2251 |
for awb, detail in returned_orders.iteritems():
|
| - |
|
2252 |
orders = None
|
| 2237 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2253 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| - |
|
2254 |
|
| 2238 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.DELIVERED_AT_STORE, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
2255 |
if orders == None or len(orders)==0:
|
| 2239 |
continue
|
2256 |
continue
|
| - |
|
2257 |
for order in orders:
|
| - |
|
2258 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.DELIVERED_AT_STORE, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
| - |
|
2259 |
continue
|
| 2240 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
2260 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
| 2241 |
order.status = OrderStatus.RTO_IN_TRANSIT
|
2261 |
order.status = OrderStatus.RTO_IN_TRANSIT
|
| 2242 |
order.delivery_timestamp, reason = detail.split('|')
|
2262 |
order.delivery_timestamp, reason = detail.split('|')
|
| 2243 |
order.statusDescription = "Order Returned to Origin:" + reason
|
2263 |
order.statusDescription = "Order Returned to Origin:" + reason
|
| 2244 |
update_trust_level(order)
|
2264 |
update_trust_level(order)
|
| 2245 |
session.commit()
|
2265 |
session.commit()
|
| 2246 |
try:
|
2266 |
try:
|
| 2247 |
alert_client = AlertClient().get_client()
|
2267 |
alert_client = AlertClient().get_client()
|
| 2248 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
2268 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 2249 |
except Exception as e:
|
2269 |
except Exception as e:
|
| 2250 |
print "Exception in ending alert in MarkOrderAsRTO method"
|
2270 |
print "Exception in ending alert in MarkOrderAsRTO method"
|
| 2251 |
print e
|
2271 |
print e
|
| 2252 |
|
2272 |
|
| 2253 |
def get_rto_orders(provider_id):
|
2273 |
def get_rto_orders(provider_id):
|
| 2254 |
current_time = datetime.datetime.now()
|
2274 |
current_time = datetime.datetime.now()
|
| 2255 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2275 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2256 |
rto_orders = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.RTO_IN_TRANSIT).filter(Order.delivery_timestamp <= to_datetime).all()
|
2276 |
rto_orders = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.RTO_IN_TRANSIT).filter(Order.delivery_timestamp <= to_datetime).all()
|
| Line 2292... |
Line 2312... |
| 2292 |
orders_not_delivered = Order.query.filter_by(logistics_provider_id = provider_id).filter(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))).filter(or_(Order.shipping_timestamp <= upto_datetime, Order.pickup_timestamp <= upto_datetime)).all()
|
2312 |
orders_not_delivered = Order.query.filter_by(logistics_provider_id = provider_id).filter(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))).filter(or_(Order.shipping_timestamp <= upto_datetime, Order.pickup_timestamp <= upto_datetime)).all()
|
| 2293 |
return orders_not_delivered
|
2313 |
return orders_not_delivered
|
| 2294 |
|
2314 |
|
| 2295 |
def mark_orders_as_local_connected(provider_id, local_connected_orders):
|
2315 |
def mark_orders_as_local_connected(provider_id, local_connected_orders):
|
| 2296 |
for awb, timestamp in local_connected_orders.iteritems():
|
2316 |
for awb, timestamp in local_connected_orders.iteritems():
|
| - |
|
2317 |
orders = None
|
| 2297 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2318 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| - |
|
2319 |
|
| 2298 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
|
2320 |
if orders == None or len(orders)==0:
|
| 2299 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
- |
|
| 2300 |
continue
|
2321 |
continue
|
| - |
|
2322 |
|
| - |
|
2323 |
for order in orders:
|
| - |
|
2324 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
|
| - |
|
2325 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
| - |
|
2326 |
continue
|
| 2301 |
order.status = OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
2327 |
order.status = OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
| 2302 |
order.statusDescription = "Left Out of Origin City"
|
2328 |
order.statusDescription = "Left Out of Origin City"
|
| 2303 |
current_time = datetime.datetime.now()
|
2329 |
current_time = datetime.datetime.now()
|
| 2304 |
order.local_connected_timestamp = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2330 |
order.local_connected_timestamp = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2305 |
try:
|
2331 |
try:
|
| 2306 |
monitoredEntity = MonitoredEntity();
|
2332 |
monitoredEntity = MonitoredEntity();
|
| 2307 |
monitoredEntity.entityType=EntityType.COURIER;
|
2333 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 2308 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
2334 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
| 2309 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
2335 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 2310 |
|
2336 |
|
| 2311 |
sec = datetime.datetime.now()
|
2337 |
sec = datetime.datetime.now()
|
| 2312 |
#Warn alert time is taken as 14 hrs less than expected delivery time
|
2338 |
#Warn alert time is taken as 14 hrs less than expected delivery time
|
| 2313 |
warn_time1 = (order.expected_delivery_time-timedelta(hours = 14))
|
2339 |
warn_time1 = (order.expected_delivery_time-timedelta(hours = 14))
|
| 2314 |
warn_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time)
|
2340 |
warn_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time)
|
| 2315 |
warn_time = max(warn_time1, warn_time2)
|
2341 |
warn_time = max(warn_time1, warn_time2)
|
| 2316 |
|
2342 |
|
| 2317 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
2343 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
| 2318 |
critical_time1 = (order.expected_delivery_time-timedelta(hours = 10))
|
2344 |
critical_time1 = (order.expected_delivery_time-timedelta(hours = 10))
|
| 2319 |
critical_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time) + timedelta(hours = 5)
|
2345 |
critical_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time) + timedelta(hours = 5)
|
| 2320 |
critical_time = max(critical_time1, critical_time2)
|
2346 |
critical_time = max(critical_time1, critical_time2)
|
| 2321 |
|
2347 |
|
| 2322 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
2348 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
| 2323 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
2349 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 2324 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
2350 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| 2325 |
alert_client = AlertClient().get_client()
|
2351 |
alert_client = AlertClient().get_client()
|
| 2326 |
alert_client.updateMonitoredObject(monitoredEntity)
|
2352 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 2327 |
except Exception as e:
|
2353 |
except Exception as e:
|
| 2328 |
print "Exception in updating alert in MarkOrderAsLocalConnected method"
|
2354 |
print "Exception in updating alert in MarkOrderAsLocalConnected method"
|
| 2329 |
print e
|
2355 |
print e
|
| 2330 |
session.commit()
|
2356 |
session.commit()
|
| 2331 |
|
2357 |
|
| 2332 |
def get_orders_not_local_connected(provider_id):
|
2358 |
def get_orders_not_local_connected(provider_id):
|
| 2333 |
current_time = datetime.datetime.now()
|
2359 |
current_time = datetime.datetime.now()
|
| 2334 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2360 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2335 |
orders_pending_local_connection = Order.query.filter_by(logistics_provider_id = provider_id).filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST))).filter(or_(Order.shipping_timestamp <= to_datetime, Order.pickup_timestamp <= to_datetime)).all()
|
2361 |
orders_pending_local_connection = Order.query.filter_by(logistics_provider_id = provider_id).filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST))).filter(or_(Order.shipping_timestamp <= to_datetime, Order.pickup_timestamp <= to_datetime)).all()
|
| 2336 |
return orders_pending_local_connection
|
2362 |
return orders_pending_local_connection
|
| 2337 |
|
2363 |
|
| 2338 |
def mark_orders_as_destinationCityReached(provider_id, destination_city_reached_orders):
|
2364 |
def mark_orders_as_destinationCityReached(provider_id, destination_city_reached_orders):
|
| 2339 |
for awb, timestamp in destination_city_reached_orders.iteritems():
|
2365 |
for awb, timestamp in destination_city_reached_orders.iteritems():
|
| - |
|
2366 |
orders = None
|
| 2340 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2367 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| - |
|
2368 |
|
| 2341 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY]:
|
2369 |
if orders == None or len(orders)==0:
|
| 2342 |
continue
|
2370 |
continue
|
| - |
|
2371 |
|
| - |
|
2372 |
for order in orders:
|
| - |
|
2373 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY]:
|
| - |
|
2374 |
continue
|
| 2343 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
2375 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
| 2344 |
order.status = OrderStatus.REACHED_DESTINATION_CITY
|
2376 |
order.status = OrderStatus.REACHED_DESTINATION_CITY
|
| 2345 |
order.statusDescription = "Reached Destination City"
|
2377 |
order.statusDescription = "Reached Destination City"
|
| 2346 |
order.reached_destination_timestamp = timestamp
|
2378 |
order.reached_destination_timestamp = timestamp
|
| 2347 |
try:
|
2379 |
try:
|
| 2348 |
monitoredEntity = MonitoredEntity();
|
2380 |
monitoredEntity = MonitoredEntity();
|
| 2349 |
monitoredEntity.entityType=EntityType.COURIER;
|
2381 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 2350 |
monitoredEntity.eventType=OrderStatus.REACHED_DESTINATION_CITY
|
2382 |
monitoredEntity.eventType=OrderStatus.REACHED_DESTINATION_CITY
|
| 2351 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
2383 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 2352 |
|
2384 |
|
| 2353 |
sec = datetime.datetime.now()
|
2385 |
sec = datetime.datetime.now()
|
| 2354 |
#Warn alert time is taken as expected delivery time
|
2386 |
#Warn alert time is taken as expected delivery time
|
| 2355 |
warn_time1 = (order.expected_delivery_time)
|
2387 |
warn_time1 = (order.expected_delivery_time)
|
| 2356 |
warn_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time)
|
2388 |
warn_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time)
|
| 2357 |
warn_time = max(warn_time1, warn_time2)
|
2389 |
warn_time = max(warn_time1, warn_time2)
|
| 2358 |
|
2390 |
|
| 2359 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
2391 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
| 2360 |
critical_time1 = (order.expected_delivery_time + timedelta(hours = 5))
|
2392 |
critical_time1 = (order.expected_delivery_time + timedelta(hours = 5))
|
| 2361 |
critical_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time) + timedelta(hours = 5)
|
2393 |
critical_time2 = sec + timedelta(order.expected_delivery_time - order.expected_shipping_timestamp) - timedelta(sec - order.shipping_time) + timedelta(hours = 5)
|
| 2362 |
critical_time = max(critical_time1, critical_time2)
|
2394 |
critical_time = max(critical_time1, critical_time2)
|
| 2363 |
|
2395 |
|
| 2364 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
2396 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
| 2365 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
2397 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 2366 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
2398 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| 2367 |
alert_client = AlertClient().get_client()
|
2399 |
alert_client = AlertClient().get_client()
|
| 2368 |
alert_client.updateMonitoredObject(monitoredEntity)
|
2400 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 2369 |
except Exception as e:
|
2401 |
except Exception as e:
|
| 2370 |
print "Exception in updating alert in MarkOrderAsDestCityReached method"
|
2402 |
print "Exception in updating alert in MarkOrderAsDestCityReached method"
|
| 2371 |
print e
|
2403 |
print e
|
| 2372 |
session.commit()
|
2404 |
session.commit()
|
| 2373 |
|
2405 |
|
| 2374 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
2406 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
| 2375 |
for awb, detail in first_atdl_orders.iteritems():
|
2407 |
for awb, detail in first_atdl_orders.iteritems():
|
| - |
|
2408 |
orders = None
|
| 2376 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
2409 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| - |
|
2410 |
|
| 2377 |
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]:
|
2411 |
if orders == None or len(orders)==0:
|
| 2378 |
continue
|
2412 |
continue
|
| - |
|
2413 |
|
| - |
|
2414 |
for order in orders:
|
| - |
|
2415 |
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]:
|
| - |
|
2416 |
continue
|
| 2379 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
2417 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
| 2380 |
order.status = OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
2418 |
order.status = OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
| 2381 |
order.first_dlvyatmp_timestamp, reason = detail.split('|')
|
2419 |
order.first_dlvyatmp_timestamp, reason = detail.split('|')
|
| 2382 |
order.statusDescription = reason
|
2420 |
order.statusDescription = reason
|
| 2383 |
try:
|
2421 |
try:
|
| 2384 |
monitoredEntity = MonitoredEntity();
|
2422 |
monitoredEntity = MonitoredEntity();
|
| 2385 |
monitoredEntity.entityType=EntityType.COURIER;
|
2423 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 2386 |
monitoredEntity.eventType=OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
2424 |
monitoredEntity.eventType=OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
| 2387 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
2425 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 2388 |
adjustedDeliveryDaysfor1day = adjust_delivery_time(datetime.datetime.now(), 1);
|
2426 |
adjustedDeliveryDaysfor1day = adjust_delivery_time(datetime.datetime.now(), 1);
|
| 2389 |
adjustedDeliveryDaysfor2days = adjust_delivery_time(datetime.datetime.now(), 2);
|
2427 |
adjustedDeliveryDaysfor2days = adjust_delivery_time(datetime.datetime.now(), 2);
|
| 2390 |
sec = datetime.datetime.now()
|
2428 |
sec = datetime.datetime.now()
|
| 2391 |
#Warn alert time is taken as 16 hrs
|
2429 |
#Warn alert time is taken as 16 hrs
|
| 2392 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDaysfor1day-1)) + timedelta(hours=24))
|
2430 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDaysfor1day-1)) + timedelta(hours=24))
|
| 2393 |
#Critical alert time is taken as 26 hrs
|
2431 |
#Critical alert time is taken as 26 hrs
|
| 2394 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDaysfor2days-2)) + timedelta(hours=48))
|
2432 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDaysfor2days-2)) + timedelta(hours=48))
|
| 2395 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
2433 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
| 2396 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
2434 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 2397 |
monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
|
2435 |
monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
|
| 2398 |
alert_client = AlertClient().get_client()
|
2436 |
alert_client = AlertClient().get_client()
|
| 2399 |
alert_client.updateMonitoredObject(monitoredEntity)
|
2437 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 2400 |
except Exception as e:
|
2438 |
except Exception as e:
|
| 2401 |
print "Exception in updating alert in MarkOrdersAsFirstDeliveryAttempted method"
|
2439 |
print "Exception in updating alert in MarkOrdersAsFirstDeliveryAttempted method"
|
| 2402 |
print e
|
2440 |
print e
|
| 2403 |
session.commit()
|
2441 |
session.commit()
|
| 2404 |
|
2442 |
|
| 2405 |
def get_orders_not_met_expected_delivery_date():
|
2443 |
def get_orders_not_met_expected_delivery_date():
|
| 2406 |
current_time = datetime.datetime.now()
|
2444 |
current_time = datetime.datetime.now()
|
| 2407 |
today_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2445 |
today_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2408 |
orders_not_delivered = Order.query.filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY))).filter(Order.expected_delivery_time <= today_datetime).all()
|
2446 |
orders_not_delivered = Order.query.filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY))).filter(Order.expected_delivery_time <= today_datetime).all()
|
| Line 2697... |
Line 2735... |
| 2697 |
return orders_not_picked_up
|
2735 |
return orders_not_picked_up
|
| 2698 |
|
2736 |
|
| 2699 |
def receive_return(order_id, receiveCondition, receiveFreebie, serialNumbers):
|
2737 |
def receive_return(order_id, receiveCondition, receiveFreebie, serialNumbers):
|
| 2700 |
order = get_order(order_id)
|
2738 |
order = get_order(order_id)
|
| 2701 |
scanFreebie = False
|
2739 |
scanFreebie = False
|
| - |
|
2740 |
grouppedOrdersList = []
|
| - |
|
2741 |
if order.logisticsTransactionId:
|
| - |
|
2742 |
grouppedOrdersList = get_group_orders_by_logistics_txn_id(order.logisticsTransactionId)
|
| - |
|
2743 |
else:
|
| - |
|
2744 |
grouppedOrdersList.append(order)
|
| - |
|
2745 |
orderCurrentStatus = order.status
|
| 2702 |
|
2746 |
|
| 2703 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
2747 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
| 2704 |
if receiveCondition == 0:
|
2748 |
if receiveCondition == 0:
|
| 2705 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
2749 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
| 2706 |
order.statusDescription = "DOA package received"
|
2750 |
order.statusDescription = "DOA package received"
|
| Line 2723... |
Line 2767... |
| 2723 |
elif receiveCondition == 2:
|
2767 |
elif receiveCondition == 2:
|
| 2724 |
order.status = OrderStatus.RET_LOST_IN_TRANSIT
|
2768 |
order.status = OrderStatus.RET_LOST_IN_TRANSIT
|
| 2725 |
order.statusDescription = "RETURN lost in transit"
|
2769 |
order.statusDescription = "RETURN lost in transit"
|
| 2726 |
order.received_return_timestamp = datetime.datetime.now()
|
2770 |
order.received_return_timestamp = datetime.datetime.now()
|
| 2727 |
elif order.status == OrderStatus.RTO_IN_TRANSIT :
|
2771 |
elif order.status == OrderStatus.RTO_IN_TRANSIT :
|
| - |
|
2772 |
for orderObj in grouppedOrdersList:
|
| 2728 |
if receiveCondition == 0:
|
2773 |
if receiveCondition == 0:
|
| 2729 |
order.status = OrderStatus.RTO_RECEIVED_PRESTINE
|
2774 |
orderObj.status = OrderStatus.RTO_RECEIVED_PRESTINE
|
| 2730 |
order.statusDescription = "Returned to origin"
|
2775 |
orderObj.statusDescription = "Returned to origin"
|
| 2731 |
if order.freebieItemId:
|
2776 |
if orderObj.freebieItemId:
|
| 2732 |
scanFreebie = True
|
2777 |
scanFreebie = True
|
| 2733 |
elif receiveCondition == 1:
|
2778 |
elif receiveCondition == 1:
|
| 2734 |
order.status = OrderStatus.RTO_RECEIVED_DAMAGED
|
2779 |
orderObj.status = OrderStatus.RTO_RECEIVED_DAMAGED
|
| 2735 |
order.statusDescription = "RTO received damaged"
|
2780 |
orderObj.statusDescription = "RTO received damaged"
|
| 2736 |
elif receiveCondition == 2:
|
2781 |
elif receiveCondition == 2:
|
| 2737 |
order.status = OrderStatus.RTO_LOST_IN_TRANSIT
|
2782 |
orderObj.status = OrderStatus.RTO_LOST_IN_TRANSIT
|
| 2738 |
order.statusDescription = "RTO lost in transit"
|
2783 |
orderObj.statusDescription = "RTO lost in transit"
|
| 2739 |
order.received_return_timestamp = datetime.datetime.now()
|
2784 |
orderObj.received_return_timestamp = datetime.datetime.now()
|
| 2740 |
|
2785 |
|
| 2741 |
else:
|
2786 |
else:
|
| 2742 |
return False
|
2787 |
return False
|
| 2743 |
|
2788 |
|
| 2744 |
# For OUR warehouses, we need to scan in items for every return
|
2789 |
# For OUR warehouses, we need to scan in items for every return
|
| Line 2751... |
Line 2796... |
| 2751 |
OrderStatus.RTO_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT,
|
2796 |
OrderStatus.RTO_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT,
|
| 2752 |
OrderStatus.DOA_RECEIVED_PRESTINE : ScanType.DOA_IN,
|
2797 |
OrderStatus.DOA_RECEIVED_PRESTINE : ScanType.DOA_IN,
|
| 2753 |
OrderStatus.DOA_RECEIVED_DAMAGED : ScanType.DOA_IN,
|
2798 |
OrderStatus.DOA_RECEIVED_DAMAGED : ScanType.DOA_IN,
|
| 2754 |
OrderStatus.DOA_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT
|
2799 |
OrderStatus.DOA_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT
|
| 2755 |
}
|
2800 |
}
|
| 2756 |
|
- |
|
| - |
|
2801 |
if orderCurrentStatus == OrderStatus.RTO_IN_TRANSIT:
|
| - |
|
2802 |
for orderObj in grouppedOrdersList:
|
| 2757 |
if scanMap.has_key(order.status):
|
2803 |
if scanMap.has_key(orderObj.status):
|
| 2758 |
scanType = scanMap[order.status]
|
2804 |
scanType = scanMap[orderObj.status]
|
| 2759 |
lineitem = order.lineitems[0]
|
2805 |
lineitem = orderObj.lineitems[0]
|
| 2760 |
catalogClient = CatalogClient().get_client()
|
2806 |
catalogClient = CatalogClient().get_client()
|
| 2761 |
item = catalogClient.getItem(lineitem.item_id)
|
2807 |
item = catalogClient.getItem(lineitem.item_id)
|
| 2762 |
warehouseClient = WarehouseClient().get_client()
|
2808 |
warehouseClient = WarehouseClient().get_client()
|
| 2763 |
if warehouse.billingType == BillingType.OURS or scanType != ScanType.SALE_RET:
|
2809 |
if warehouse.billingType == BillingType.OURS or scanType != ScanType.SALE_RET:
|
| 2764 |
if item.type == ItemType.SERIALIZED:
|
2810 |
if item.type == ItemType.SERIALIZED:
|
| 2765 |
if lineitem.quantity > 1:
|
2811 |
if lineitem.quantity > 1:
|
| - |
|
2812 |
serialNoList = lineitem.serial_number.split(',')
|
| 2766 |
if serialNumbers is None or len(serialNumbers)==0:
|
2813 |
for serialNumber in serialNoList:
|
| - |
|
2814 |
warehouseClient.scanSerializedItemForOrder(serialNumber, scanType, orderObj.id, orderObj.fulfilmentWarehouseId, 1, orderObj.warehouse_id)
|
| 2767 |
return False
|
2815 |
else:
|
| - |
|
2816 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, scanType, orderObj.id, orderObj.fulfilmentWarehouseId, lineitem.quantity, orderObj.warehouse_id)
|
| 2768 |
else:
|
2817 |
else:
|
| - |
|
2818 |
warehouseClient.scanForOrder(None, scanType, lineitem.quantity, orderObj.id, orderObj.fulfilmentWarehouseId, orderObj.warehouse_id)
|
| - |
|
2819 |
if warehouse.billingType == BillingType.OURS_EXTERNAL and scanType == ScanType.SALE_RET:
|
| - |
|
2820 |
warehouseClient.scanForOursExternalSaleReturn(orderObj.id, lineitem.transfer_price)
|
| - |
|
2821 |
if scanFreebie:
|
| - |
|
2822 |
warehouseClient.scanfreebie(orderObj.id, orderObj.freebieItemId, 0, scanType)
|
| - |
|
2823 |
else:
|
| - |
|
2824 |
if scanMap.has_key(order.status):
|
| - |
|
2825 |
scanType = scanMap[order.status]
|
| - |
|
2826 |
lineitem = order.lineitems[0]
|
| - |
|
2827 |
catalogClient = CatalogClient().get_client()
|
| - |
|
2828 |
item = catalogClient.getItem(lineitem.item_id)
|
| - |
|
2829 |
warehouseClient = WarehouseClient().get_client()
|
| - |
|
2830 |
if warehouse.billingType == BillingType.OURS or scanType != ScanType.SALE_RET:
|
| - |
|
2831 |
if item.type == ItemType.SERIALIZED:
|
| - |
|
2832 |
if lineitem.quantity > 1:
|
| - |
|
2833 |
if serialNumbers is None or len(serialNumbers)==0:
|
| - |
|
2834 |
return False
|
| - |
|
2835 |
else:
|
| 2769 |
serialNoList = serialNumbers.split(',')
|
2836 |
serialNoList = serialNumbers.split(',')
|
| 2770 |
for serialNumber in serialNoList:
|
2837 |
for serialNumber in serialNoList:
|
| 2771 |
warehouseClient.scanSerializedItemForOrder(serialNumber, scanType, order.id, order.fulfilmentWarehouseId, 1, order.warehouse_id)
|
2838 |
warehouseClient.scanSerializedItemForOrder(serialNumber, scanType, order.id, order.fulfilmentWarehouseId, 1, order.warehouse_id)
|
| - |
|
2839 |
else:
|
| - |
|
2840 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, scanType, order.id, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
| 2772 |
else:
|
2841 |
else:
|
| 2773 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, scanType, order.id, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
- |
|
| 2774 |
else:
|
- |
|
| 2775 |
warehouseClient.scanForOrder(None, scanType, lineitem.quantity, order.id, order.fulfilmentWarehouseId, order.warehouse_id)
|
2842 |
warehouseClient.scanForOrder(None, scanType, lineitem.quantity, order.id, order.fulfilmentWarehouseId, order.warehouse_id)
|
| 2776 |
if warehouse.billingType == BillingType.OURS_EXTERNAL and scanType == ScanType.SALE_RET:
|
2843 |
if warehouse.billingType == BillingType.OURS_EXTERNAL and scanType == ScanType.SALE_RET:
|
| 2777 |
warehouseClient.scanForOursExternalSaleReturn(order.id, lineitem.transfer_price)
|
2844 |
warehouseClient.scanForOursExternalSaleReturn(order.id, lineitem.transfer_price)
|
| 2778 |
if scanFreebie:
|
2845 |
if scanFreebie:
|
| 2779 |
warehouseClient.scanfreebie(order.id, order.freebieItemId, 0, scanType)
|
2846 |
warehouseClient.scanfreebie(order.id, order.freebieItemId, 0, scanType)
|
| 2780 |
|
2847 |
|
| 2781 |
session.commit()
|
2848 |
session.commit()
|
| 2782 |
return True
|
2849 |
return True
|
| 2783 |
|
2850 |
|
| 2784 |
def validate_doa(order_id, is_valid):
|
2851 |
def validate_doa(order_id, is_valid):
|
| Line 7730... |
Line 7797... |
| 7730 |
warehouse_client = WarehouseClient().get_client()
|
7797 |
warehouse_client = WarehouseClient().get_client()
|
| 7731 |
catalog_client = CatalogClient().get_client()
|
7798 |
catalog_client = CatalogClient().get_client()
|
| 7732 |
whStateId = None
|
7799 |
whStateId = None
|
| 7733 |
lineItemSize = 0
|
7800 |
lineItemSize = 0
|
| 7734 |
individualInvoice = True
|
7801 |
individualInvoice = True
|
| - |
|
7802 |
|
| - |
|
7803 |
|
| - |
|
7804 |
orderscansMap = {}
|
| - |
|
7805 |
orderInventoryItemMap = {}
|
| - |
|
7806 |
orderFulfilmentWarehouseMap = {}
|
| 7735 |
for order in ordersList:
|
7807 |
for order in ordersList:
|
| - |
|
7808 |
scanList = []
|
| - |
|
7809 |
inventoryItemList = []
|
| 7736 |
newTaxType = __getOrderTaxType(order)
|
7810 |
newTaxType = __getOrderTaxType(order)
|
| 7737 |
if order.taxType == 2:
|
7811 |
if order.taxType == 2:
|
| 7738 |
if newTaxType == 0:
|
7812 |
if newTaxType == 0:
|
| 7739 |
raise TransactionServiceException(302, "C-Form billing is not allowed for same state for Order" + str(order.id))
|
7813 |
raise TransactionServiceException(302, "C-Form billing is not allowed for same state for Order" + str(order.id))
|
| 7740 |
else:
|
7814 |
else:
|
| Line 7783... |
Line 7857... |
| 7783 |
item = catalog_client.getItem(item_id)
|
7857 |
item = catalog_client.getItem(item_id)
|
| 7784 |
|
7858 |
|
| 7785 |
if ItemType.SERIALIZED == item.type and lineitem.quantity>2:
|
7859 |
if ItemType.SERIALIZED == item.type and lineitem.quantity>2:
|
| 7786 |
individualInvoice=False
|
7860 |
individualInvoice=False
|
| 7787 |
|
7861 |
|
| 7788 |
if order.type== OrderType.B2B:
|
7862 |
if order.orderType== OrderType.B2B:
|
| 7789 |
individualInvoice=False
|
7863 |
individualInvoice=False
|
| 7790 |
|
7864 |
|
| 7791 |
lineItemSize = lineItemSize+1
|
7865 |
lineItemSize = lineItemSize+1
|
| 7792 |
|
7866 |
|
| 7793 |
if order.status == OrderStatus.ACCEPTED:
|
7867 |
if order.status == OrderStatus.ACCEPTED:
|
| Line 7887... |
Line 7961... |
| 7887 |
raise TransactionServiceException(310, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
7961 |
raise TransactionServiceException(310, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
| 7888 |
if order.warehouse_id!= invItem[11]:
|
7962 |
if order.warehouse_id!= invItem[11]:
|
| 7889 |
if warehouseDbConnection.open:
|
7963 |
if warehouseDbConnection.open:
|
| 7890 |
warehouseDbConnection.close()
|
7964 |
warehouseDbConnection.close()
|
| 7891 |
raise TransactionServiceException(311, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
7965 |
raise TransactionServiceException(311, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7966 |
if warehouse.id!= invItem[8]:
|
| - |
|
7967 |
warehouseDbConnection.rollback()
|
| - |
|
7968 |
if warehouseDbConnection.open:
|
| - |
|
7969 |
warehouseDbConnection.close()
|
| - |
|
7970 |
raise TransactionServiceException(311, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" in the vendor warehouse Id"+str(order.fulfilmentWarehouseId)+"and Order Id:- "+str(order.id))
|
| 7892 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
7971 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
| 7893 |
if warehouseDbConnection.open:
|
7972 |
if warehouseDbConnection.open:
|
| 7894 |
warehouseDbConnection.close()
|
7973 |
warehouseDbConnection.close()
|
| 7895 |
raise TransactionServiceException(312, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
7974 |
raise TransactionServiceException(312, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
| 7896 |
if invItem[9]=='MARKED_BAD' or invItem[9]=='DOA_IN' or invItem[9]=='DOA_OUT' or invItem[9]=='DOA_REJECTED' or invItem[9]=='SALE_RET_UNUSABLE' or invItem[9]=='BAD_SALE':
|
7975 |
if invItem[9]=='MARKED_BAD' or invItem[9]=='DOA_IN' or invItem[9]=='DOA_OUT' or invItem[9]=='DOA_REJECTED' or invItem[9]=='SALE_RET_UNUSABLE' or invItem[9]=='BAD_SALE':
|
| Line 7914... |
Line 7993... |
| 7914 |
warehouseDbConnection.close()
|
7993 |
warehouseDbConnection.close()
|
| 7915 |
raise TransactionServiceException(316, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
7994 |
raise TransactionServiceException(316, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
| 7916 |
|
7995 |
|
| 7917 |
current_time = datetime.datetime.now()
|
7996 |
current_time = datetime.datetime.now()
|
| 7918 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
7997 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
| - |
|
7998 |
scanList.append(insertScanSql)
|
| 7919 |
whCursor.execute(insertScanSql)
|
7999 |
#whCursor.execute(insertScanSql)
|
| 7920 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
8000 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
| - |
|
8001 |
inventoryItemList.append(updateInvItemSql)
|
| 7921 |
whCursor.execute(updateInvItemSql)
|
8002 |
#whCursor.execute(updateInvItemSql)
|
| 7922 |
|
8003 |
|
| 7923 |
|
8004 |
|
| 7924 |
lineitem.transfer_price = invItem[13]
|
8005 |
lineitem.transfer_price = invItem[13]
|
| 7925 |
lineitem.nlc = invItem[14]
|
8006 |
lineitem.nlc = invItem[14]
|
| 7926 |
order.vendorId = invItem[12]
|
8007 |
order.vendorId = invItem[12]
|
| 7927 |
|
- |
|
| 7928 |
if warehouse.billingType == BillingType.OURS:
|
- |
|
| 7929 |
if not inventory_client.isAlive():
|
- |
|
| 7930 |
inventory_client = InventoryClient().get_client()
|
- |
|
| 7931 |
inventory_client.addInventory(item.id, warehouse.id, -1)
|
- |
|
| 7932 |
|
8008 |
|
| 7933 |
else:
|
8009 |
else:
|
| 7934 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.itemId = %d AND i.currentQuantity > 0 AND i.currentWarehouseId = %d AND i.physicalWarehouseId = %d AND i.lastScanType not in ('MARKED_BAD','DOA_IN','DOA_REJECTED','DOA_REPLACED') AND (i.transferStatus is NULL or i.transferStatus != 'IN_TRANSIT') AND i.itemNumber ='%s'"%(item.id,order.fulfilmentWarehouseId,order.warehouse_id,itemNumbers[0])
|
8010 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.itemId = %d AND i.currentQuantity > 0 AND i.currentWarehouseId = %d AND i.physicalWarehouseId = %d AND i.lastScanType not in ('MARKED_BAD','DOA_IN','DOA_REJECTED','DOA_REPLACED') AND (i.transferStatus is NULL or i.transferStatus != 'IN_TRANSIT') AND i.itemNumber ='%s'"%(item.id,order.fulfilmentWarehouseId,order.warehouse_id,itemNumbers[0])
|
| 7935 |
whCursor.execute(invItemSql)
|
8011 |
whCursor.execute(invItemSql)
|
| 7936 |
invItems = whCursor.fetchall()
|
8012 |
invItems = whCursor.fetchall()
|
| 7937 |
if invItems is None:
|
8013 |
if invItems is None:
|
| 7938 |
raise TransactionServiceException(317, "No Item in the inventory with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
8014 |
raise TransactionServiceException(317, "No Item in the inventory with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
| - |
|
8015 |
if warehouseDbConnection.open:
|
| 7939 |
warehouseDbConnection.close()
|
8016 |
warehouseDbConnection.close()
|
| 7940 |
totalCurrentQuantity =0
|
8017 |
totalCurrentQuantity =0
|
| 7941 |
for invItem in invItems:
|
8018 |
for invItem in invItems:
|
| 7942 |
totalCurrentQuantity = totalCurrentQuantity + invItem[5]
|
8019 |
totalCurrentQuantity = totalCurrentQuantity + invItem[5]
|
| 7943 |
|
8020 |
|
| 7944 |
orderQuantity = lineitem.quantity
|
8021 |
orderQuantity = lineitem.quantity
|
| Line 7973... |
Line 8050... |
| 7973 |
else:
|
8050 |
else:
|
| 7974 |
break
|
8051 |
break
|
| 7975 |
|
8052 |
|
| 7976 |
current_time = datetime.datetime.now()
|
8053 |
current_time = datetime.datetime.now()
|
| 7977 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
8054 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
| - |
|
8055 |
scanList.append(insertScanSql)
|
| 7978 |
whCursor.execute(insertScanSql)
|
8056 |
#whCursor.execute(insertScanSql)
|
| 7979 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='SALE' where id=%d "%(scanQuantity,invItem[0])
|
8057 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='SALE' where id=%d "%(scanQuantity,invItem[0])
|
| - |
|
8058 |
inventoryItemList.append(updateInvItemSql)
|
| 7980 |
whCursor.execute(updateInvItemSql)
|
8059 |
#whCursor.execute(updateInvItemSql)
|
| 7981 |
|
8060 |
|
| 7982 |
lineitem.transfer_price = invItem[13]
|
8061 |
lineitem.transfer_price = invItem[13]
|
| 7983 |
lineitem.nlc = invItem[14]
|
8062 |
lineitem.nlc = invItem[14]
|
| 7984 |
order.vendorId = invItem[12]
|
8063 |
order.vendorId = invItem[12]
|
| 7985 |
|
8064 |
|
| 7986 |
if warehouse.billingType == BillingType.OURS:
|
- |
|
| 7987 |
if not inventory_client.isAlive():
|
- |
|
| 7988 |
inventory_client = InventoryClient().get_client()
|
- |
|
| 7989 |
inventory_client.addInventory(item.id, warehouse.id, long(-1.0*lineitem.quantity))
|
- |
|
| 7990 |
|
- |
|
| 7991 |
else:
|
8065 |
else:
|
| 7992 |
''' Bad Serialized '''
|
8066 |
''' Bad Serialized '''
|
| 7993 |
if not warehouse.billingWarehouseId:
|
8067 |
if not warehouse.billingWarehouseId:
|
| 7994 |
if not inventory_client.isAlive():
|
8068 |
if not inventory_client.isAlive():
|
| 7995 |
inventory_client = InventoryClient().get_client()
|
8069 |
inventory_client = InventoryClient().get_client()
|
| Line 8016... |
Line 8090... |
| 8016 |
raise TransactionServiceException(110, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
8090 |
raise TransactionServiceException(110, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
| 8017 |
if order.warehouse_id!= invItem[11]:
|
8091 |
if order.warehouse_id!= invItem[11]:
|
| 8018 |
if warehouseDbConnection.open:
|
8092 |
if warehouseDbConnection.open:
|
| 8019 |
warehouseDbConnection.close()
|
8093 |
warehouseDbConnection.close()
|
| 8020 |
raise TransactionServiceException(110, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
8094 |
raise TransactionServiceException(110, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
8095 |
if order.fulfilmentWarehouseId!= invItem[8]:
|
| - |
|
8096 |
warehouseDbConnection.rollback()
|
| - |
|
8097 |
if warehouseDbConnection.open:
|
| - |
|
8098 |
warehouseDbConnection.close()
|
| - |
|
8099 |
raise TransactionServiceException(311, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" in the vendor warehouse Id"+str(order.fulfilmentWarehouseId)+"and Order Id:- "+str(order.id))
|
| 8021 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
8100 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
| 8022 |
if warehouseDbConnection.open:
|
8101 |
if warehouseDbConnection.open:
|
| 8023 |
warehouseDbConnection.close()
|
8102 |
warehouseDbConnection.close()
|
| 8024 |
raise TransactionServiceException(110, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
8103 |
raise TransactionServiceException(110, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
| 8025 |
if invItem[9]!='MARKED_BAD' or invItem[9]!='DOA_IN' or invItem[9]!='DOA_REJECTED' or invItem[9]!='SALE_RET_UNUSABLE':
|
8104 |
if invItem[9]!='MARKED_BAD' or invItem[9]!='DOA_IN' or invItem[9]!='DOA_REJECTED' or invItem[9]!='SALE_RET_UNUSABLE':
|
| Line 8043... |
Line 8122... |
| 8043 |
if warehouseDbConnection.open:
|
8122 |
if warehouseDbConnection.open:
|
| 8044 |
warehouseDbConnection.close()
|
8123 |
warehouseDbConnection.close()
|
| 8045 |
raise TransactionServiceException(110, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
8124 |
raise TransactionServiceException(110, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
| 8046 |
current_time = datetime.datetime.now()
|
8125 |
current_time = datetime.datetime.now()
|
| 8047 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
8126 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
| - |
|
8127 |
scanList.append(insertScanSql)
|
| 8048 |
whCursor.execute(insertScanSql)
|
8128 |
#whCursor.execute(insertScanSql)
|
| 8049 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='BAD_SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
8129 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='BAD_SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
| - |
|
8130 |
inventoryItemList.append(updateInvItemSql)
|
| 8050 |
whCursor.execute(updateInvItemSql)
|
8131 |
#whCursor.execute(updateInvItemSql)
|
| 8051 |
|
8132 |
|
| 8052 |
|
8133 |
|
| 8053 |
lineitem.transfer_price = invItem[13]
|
8134 |
lineitem.transfer_price = invItem[13]
|
| 8054 |
lineitem.nlc = invItem[14]
|
8135 |
lineitem.nlc = invItem[14]
|
| 8055 |
order.vendorId = invItem[12]
|
8136 |
order.vendorId = invItem[12]
|
| Line 8101... |
Line 8182... |
| 8101 |
else:
|
8182 |
else:
|
| 8102 |
break
|
8183 |
break
|
| 8103 |
|
8184 |
|
| 8104 |
current_time = datetime.datetime.now()
|
8185 |
current_time = datetime.datetime.now()
|
| 8105 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
8186 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
| - |
|
8187 |
scanList.append(insertScanSql)
|
| 8106 |
whCursor.execute(insertScanSql)
|
8188 |
#whCursor.execute(insertScanSql)
|
| 8107 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='BAD_SALE' where id=%d "%(scanQuantity,invItem[0])
|
8189 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='BAD_SALE' where id=%d "%(scanQuantity,invItem[0])
|
| 8108 |
whCursor.execute(updateInvItemSql)
|
8190 |
inventoryItemList.append(updateInvItemSql)
|
| - |
|
8191 |
#whCursor.execute(updateInvItemSql)
|
| 8109 |
|
8192 |
|
| 8110 |
lineitem.transfer_price = invItem[13]
|
8193 |
lineitem.transfer_price = invItem[13]
|
| 8111 |
lineitem.nlc = invItem[14]
|
8194 |
lineitem.nlc = invItem[14]
|
| 8112 |
order.vendorId = invItem[12]
|
8195 |
order.vendorId = invItem[12]
|
| 8113 |
|
8196 |
|
| Line 8130... |
Line 8213... |
| 8130 |
else:
|
8213 |
else:
|
| 8131 |
if not warehouse.isAvailabilityMonitored:
|
8214 |
if not warehouse.isAvailabilityMonitored:
|
| 8132 |
if not inventory_client.isAlive():
|
8215 |
if not inventory_client.isAlive():
|
| 8133 |
inventory_client = InventoryClient().get_client()
|
8216 |
inventory_client = InventoryClient().get_client()
|
| 8134 |
inventory_client.addInventory(item.id, warehouse.id, -1 * lineitem.quantity)
|
8217 |
inventory_client.addInventory(item.id, warehouse.id, -1 * lineitem.quantity)
|
| 8135 |
if order.freebieItemId:
|
8218 |
|
| 8136 |
inventoryItem = None
|
8219 |
|
| 8137 |
for freebieWhId in freebieWarehouseIdMap.get(order.id):
|
- |
|
| 8138 |
try:
|
8220 |
orderscansMap[order.id] = scanList
|
| 8139 |
warehouse_client = WarehouseClient().get_client()
|
8221 |
orderInventoryItemMap[order.id] = inventoryItemList
|
| 8140 |
inventoryItem = warehouse_client.scanfreebie(orderId, order.freebieItemId, freebieWhId, ScanType.SALE);
|
- |
|
| 8141 |
except Exception as e:
|
8222 |
orderFulfilmentWarehouseMap[order.id] = warehouse
|
| 8142 |
print e.message
|
8223 |
|
| 8143 |
raise TransactionServiceException(110,'Error in billing freebie for warehouseId ' + str(freebieWarehouseId))
|
- |
|
| 8144 |
|
8224 |
|
| 8145 |
attr = Attribute()
|
8225 |
for order in ordersList:
|
| 8146 |
attr.orderId = orderId
|
8226 |
if billingType == BillingType.OURS:
|
| 8147 |
attr.name = "freebie_tp"
|
8227 |
scanList = orderscansMap.get(order.id)
|
| 8148 |
attr.value = str(inventoryItem.unitPrice)
|
8228 |
inventoryItemList = orderInventoryItemMap.get(order.id)
|
| 8149 |
|
- |
|
| 8150 |
attr1 = Attribute()
|
8229 |
fulfillmentWarehouse = orderFulfilmentWarehouseMap.get(order.id)
|
| 8151 |
attr1.orderId = orderId
|
8230 |
lineItem = order.lineitems[0]
|
| 8152 |
attr1.name = "freebie_vendor"
|
8231 |
|
| 8153 |
attr1.value = str(inventoryItem.supplierId)
|
8232 |
whCursor = warehouseDbConnection.cursor()
|
| 8154 |
|
- |
|
| 8155 |
attr2 = Attribute()
|
8233 |
|
| 8156 |
attr2.orderId = orderId
|
8234 |
for scan in scanList:
|
| 8157 |
attr2.name = "freebie_nlc"
|
8235 |
whCursor.execute(scan)
|
| 8158 |
attr2.value = str(inventoryItem.nlc)
|
8236 |
for invItem in inventoryItemList:
|
| 8159 |
if order.productCondition != ProductCondition.BAD:
|
8237 |
whCursor.execute(invItem)
|
| 8160 |
'''
|
8238 |
|
| 8161 |
Reduce the reservation count for all line items of the given order.
|
8239 |
if order.productCondition != ProductCondition.BAD:
|
| 8162 |
'''
|
- |
|
| 8163 |
try:
|
8240 |
if fulfillmentWarehouse.billingType == BillingType.OURS:
|
| 8164 |
if not inventory_client.isAlive():
|
8241 |
if not inventory_client.isAlive():
|
| 8165 |
inventory_client = InventoryClient().get_client()
|
8242 |
inventory_client = InventoryClient().get_client()
|
| - |
|
8243 |
inventory_client.addInventory(lineItem.item_id, fulfillmentWarehouse.id, long(-1.0*lineItem.quantity))
|
| - |
|
8244 |
if order.freebieItemId:
|
| - |
|
8245 |
inventoryItem = None
|
| - |
|
8246 |
for freebieWhId in freebieWarehouseIdMap.get(order.id):
|
| - |
|
8247 |
try:
|
| - |
|
8248 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
8249 |
inventoryItem = warehouse_client.scanfreebie(orderId, order.freebieItemId, freebieWhId, ScanType.SALE);
|
| - |
|
8250 |
except Exception as e:
|
| - |
|
8251 |
print e.message
|
| - |
|
8252 |
raise TransactionServiceException(110,'Error in billing freebie for warehouseId ' + str(freebieWarehouseId))
|
| - |
|
8253 |
|
| - |
|
8254 |
attr = Attribute()
|
| - |
|
8255 |
attr.orderId = orderId
|
| - |
|
8256 |
attr.name = "freebie_tp"
|
| - |
|
8257 |
attr.value = str(inventoryItem.unitPrice)
|
| - |
|
8258 |
|
| - |
|
8259 |
attr1 = Attribute()
|
| - |
|
8260 |
attr1.orderId = orderId
|
| - |
|
8261 |
attr1.name = "freebie_vendor"
|
| - |
|
8262 |
attr1.value = str(inventoryItem.supplierId)
|
| - |
|
8263 |
|
| - |
|
8264 |
attr2 = Attribute()
|
| - |
|
8265 |
attr2.orderId = orderId
|
| - |
|
8266 |
attr2.name = "freebie_nlc"
|
| - |
|
8267 |
attr2.value = str(inventoryItem.nlc)
|
| - |
|
8268 |
if order.productCondition != ProductCondition.BAD:
|
| - |
|
8269 |
'''
|
| - |
|
8270 |
Reduce the reservation count for all line items of the given order.
|
| - |
|
8271 |
'''
|
| - |
|
8272 |
try:
|
| - |
|
8273 |
if not inventory_client.isAlive():
|
| - |
|
8274 |
inventory_client = InventoryClient().get_client()
|
| 8166 |
for lineitem in order.lineitems:
|
8275 |
for lineitem in order.lineitems:
|
| 8167 |
inventory_client.reduceReservationCount(lineitem.item_id, order.fulfilmentWarehouseId, sourceId, order.id, lineitem.quantity)
|
8276 |
inventory_client.reduceReservationCount(lineitem.item_id, order.fulfilmentWarehouseId, sourceId, order.id, lineitem.quantity)
|
| 8168 |
except:
|
8277 |
except:
|
| 8169 |
print "Unable to reduce reservation count"
|
8278 |
print "Unable to reduce reservation count"
|
| - |
|
8279 |
|
| 8170 |
|
8280 |
|
| 8171 |
warehouseDbConnection.commit()
|
8281 |
warehouseDbConnection.commit()
|
| 8172 |
if warehouseDbConnection.open:
|
8282 |
if warehouseDbConnection.open:
|
| 8173 |
warehouseDbConnection.close()
|
8283 |
warehouseDbConnection.close()
|
| 8174 |
session.commit()
|
8284 |
session.commit()
|
| Line 8177... |
Line 8287... |
| 8177 |
invoiceNumber = get_next_invoice_counter(ordersList[0].orderType, whStateId)
|
8287 |
invoiceNumber = get_next_invoice_counter(ordersList[0].orderType, whStateId)
|
| 8178 |
|
8288 |
|
| 8179 |
invoiceTypeVal = 1
|
8289 |
invoiceTypeVal = 1
|
| 8180 |
if not individualInvoice:
|
8290 |
if not individualInvoice:
|
| 8181 |
invoiceTypeVal = 2
|
8291 |
invoiceTypeVal = 2
|
| 8182 |
if lineItemSize >20:
|
8292 |
if lineItemSize > 1:
|
| 8183 |
invoiceTypeVal = 2
|
8293 |
invoiceTypeVal = 2
|
| 8184 |
if lineItemSize < 20 and invoiceType =="BulkInvoice" :
|
8294 |
if lineItemSize <= 1 and invoiceType =="BulkInvoice" :
|
| 8185 |
invoiceTypeVal = 2
|
8295 |
invoiceTypeVal = 2
|
| 8186 |
|
8296 |
|
| 8187 |
transactionShipSeqValues = ordersList[0].logisticsTransactionId.split('-')
|
8297 |
transactionShipSeqValues = ordersList[0].logisticsTransactionId.split('-')
|
| 8188 |
|
8298 |
|
| 8189 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==int(transactionShipSeqValues[0])).filter(TransactionShipmentSequence.sequence==int(transactionShipSeqValues[1])).order_by(desc(TransactionShipmentSequence.id)).first()
|
8299 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==int(transactionShipSeqValues[0])).filter(TransactionShipmentSequence.sequence==int(transactionShipSeqValues[1])).order_by(desc(TransactionShipmentSequence.id)).first()
|