| 104 |
ashish |
1 |
'''
|
|
|
2 |
Created on 29-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.model.v1.order.impl import DataService
|
|
|
7 |
from shop2020.model.v1.order.impl.DataAccessors import create_transaction,\
|
| 1382 |
varun.gupt |
8 |
create_order, get_new_transaction, get_transactions_for_customer, get_transaction_status,\
|
|
|
9 |
get_line_items_for_order, get_transaction, get_transactions_for_shopping_cart_id,\
|
|
|
10 |
change_transaction_status, get_orders_for_customer,get_orders_for_transaction, get_order,\
|
|
|
11 |
get_returnable_orders_for_customer, get_cancellable_orders_for_customer, get_orders_by_billing_date,\
|
|
|
12 |
get_all_orders, change_order_status, get_alerts, set_alert, add_billing_details,\
|
|
|
13 |
mark_orders_as_manifested, close_session, accept_order, bill_order, mark_orders_as_picked_up,\
|
| 1208 |
chandransh |
14 |
mark_orders_as_delivered, mark_orders_as_failed, add_jacket_number,\
|
| 1405 |
ankur.sing |
15 |
order_outofstock, batch_orders, update_non_delivery_reason, enqueue_transaction_info_email,\
|
| 1627 |
ankur.sing |
16 |
get_undelivered_orders, get_order_for_customer, get_valid_order_count,\
|
| 1886 |
ankur.sing |
17 |
get_cust_count_with_successful_txn, get_valid_orders_amount_range,\
|
| 2591 |
chandransh |
18 |
get_valid_orders, toggle_doa_flag, request_pickup_number, authorize_pickup,\
|
| 2697 |
chandransh |
19 |
receive_return, validate_doa, reship_order, refund_order, get_return_orders,\
|
| 2819 |
chandransh |
20 |
process_return, get_return_order, mark_doas_as_picked_up,\
|
| 3451 |
chandransh |
21 |
create_purchase_order, verify_order, is_alive, get_orders_by_shipping_date,\
|
| 3956 |
chandransh |
22 |
update_weight, change_warehouse, change_product, add_delay_reason,\
|
| 4008 |
mandeep.dh |
23 |
reconcile_cod_collection, get_transactions_requiring_extra_processing,\
|
|
|
24 |
mark_transaction_as_processed
|
| 1405 |
ankur.sing |
25 |
|
| 104 |
ashish |
26 |
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
|
| 1348 |
chandransh |
27 |
to_t_alert, to_t_order, to_t_lineitem
|
| 483 |
rajveer |
28 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
|
| 2783 |
chandransh |
29 |
LineItem, Order, TransactionServiceException
|
| 738 |
chandransh |
30 |
from shop2020.utils.Utils import to_py_date, get_fdate_tdate
|
| 104 |
ashish |
31 |
|
|
|
32 |
class OrderServiceHandler:
|
|
|
33 |
|
| 3187 |
rajveer |
34 |
def __init__(self, dbname='transaction', db_hostname='localhost'):
|
| 483 |
rajveer |
35 |
"""
|
| 104 |
ashish |
36 |
Constructor
|
| 483 |
rajveer |
37 |
"""
|
| 3187 |
rajveer |
38 |
DataService.initialize(dbname, db_hostname)
|
| 104 |
ashish |
39 |
|
|
|
40 |
def createTransaction(self, transaction):
|
|
|
41 |
"""
|
|
|
42 |
Parameters:
|
|
|
43 |
- transaction
|
|
|
44 |
"""
|
| 766 |
rajveer |
45 |
try:
|
|
|
46 |
return create_transaction(transaction)
|
|
|
47 |
finally:
|
|
|
48 |
close_session()
|
|
|
49 |
|
| 104 |
ashish |
50 |
def getTransaction(self, id):
|
|
|
51 |
"""
|
|
|
52 |
Get transaction methods.
|
|
|
53 |
|
|
|
54 |
Parameters:
|
|
|
55 |
- id
|
|
|
56 |
"""
|
| 766 |
rajveer |
57 |
try:
|
|
|
58 |
transaction = get_transaction(id)
|
|
|
59 |
return to_t_transaction(transaction)
|
|
|
60 |
finally:
|
|
|
61 |
close_session()
|
|
|
62 |
|
| 483 |
rajveer |
63 |
def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
|
| 104 |
ashish |
64 |
"""
|
|
|
65 |
Parameters:
|
| 483 |
rajveer |
66 |
- customerId
|
| 104 |
ashish |
67 |
- from_date
|
|
|
68 |
- to_date
|
| 483 |
rajveer |
69 |
- status
|
| 104 |
ashish |
70 |
"""
|
| 766 |
rajveer |
71 |
try:
|
|
|
72 |
current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
|
|
|
73 |
|
|
|
74 |
transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
|
|
|
75 |
t_transaction = []
|
|
|
76 |
for transaction in transactions:
|
|
|
77 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
78 |
return t_transaction
|
|
|
79 |
finally:
|
|
|
80 |
close_session()
|
| 483 |
rajveer |
81 |
|
|
|
82 |
def getTransactionsForShoppingCartId(self, shoppingCartId):
|
|
|
83 |
"""
|
|
|
84 |
Parameters:
|
|
|
85 |
- shoppingCartId
|
|
|
86 |
"""
|
| 766 |
rajveer |
87 |
try:
|
|
|
88 |
transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
|
|
|
89 |
t_transaction = []
|
|
|
90 |
for transaction in transactions:
|
|
|
91 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
92 |
return t_transaction
|
|
|
93 |
finally:
|
|
|
94 |
close_session()
|
| 104 |
ashish |
95 |
|
| 483 |
rajveer |
96 |
def getTransactionStatus(self, transactionId):
|
| 104 |
ashish |
97 |
"""
|
|
|
98 |
Parameters:
|
| 483 |
rajveer |
99 |
- transactionId
|
|
|
100 |
"""
|
| 766 |
rajveer |
101 |
try:
|
|
|
102 |
return get_transaction_status(transactionId)
|
|
|
103 |
finally:
|
|
|
104 |
close_session()
|
|
|
105 |
|
| 483 |
rajveer |
106 |
def changeTransactionStatus(self, transactionId, status, description):
|
|
|
107 |
"""
|
|
|
108 |
Parameters:
|
|
|
109 |
- transactionId
|
| 104 |
ashish |
110 |
- status
|
| 483 |
rajveer |
111 |
- description
|
|
|
112 |
"""
|
| 766 |
rajveer |
113 |
try:
|
|
|
114 |
return change_transaction_status(transactionId, status, description)
|
|
|
115 |
finally:
|
|
|
116 |
close_session()
|
|
|
117 |
|
| 1528 |
ankur.sing |
118 |
def getOrdersForTransaction(self, transactionId, customerId):
|
| 483 |
rajveer |
119 |
"""
|
| 1528 |
ankur.sing |
120 |
Returns list of orders for given transaction Id. Also filters based on customer Id so that
|
|
|
121 |
only user who owns the transaction can view its order details.
|
|
|
122 |
|
| 483 |
rajveer |
123 |
Parameters:
|
|
|
124 |
- transactionId
|
| 1528 |
ankur.sing |
125 |
- customerId
|
| 483 |
rajveer |
126 |
"""
|
| 766 |
rajveer |
127 |
try:
|
| 1528 |
ankur.sing |
128 |
orders = get_orders_for_transaction(transactionId, customerId)
|
| 766 |
rajveer |
129 |
return [to_t_order(order) for order in orders]
|
|
|
130 |
finally:
|
|
|
131 |
close_session()
|
|
|
132 |
|
| 483 |
rajveer |
133 |
def getAllOrders(self, status, from_date, to_date, warehouse_id):
|
|
|
134 |
"""
|
|
|
135 |
Parameters:
|
|
|
136 |
- status
|
| 104 |
ashish |
137 |
- from_date
|
|
|
138 |
- to_date
|
| 483 |
rajveer |
139 |
- warehouse_id
|
| 104 |
ashish |
140 |
"""
|
| 766 |
rajveer |
141 |
try:
|
|
|
142 |
current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
|
|
|
143 |
orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
|
|
|
144 |
return [to_t_order(order) for order in orders]
|
|
|
145 |
finally:
|
|
|
146 |
close_session()
|
|
|
147 |
|
| 995 |
varun.gupt |
148 |
def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
|
|
|
149 |
"""
|
|
|
150 |
Parameters:
|
|
|
151 |
- status
|
|
|
152 |
- start_billing_date
|
|
|
153 |
- end_billing_date
|
|
|
154 |
- warehouse_id
|
|
|
155 |
"""
|
|
|
156 |
try:
|
|
|
157 |
current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
|
|
|
158 |
orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
|
|
|
159 |
return [to_t_order(order) for order in orders]
|
|
|
160 |
finally:
|
|
|
161 |
close_session()
|
| 1382 |
varun.gupt |
162 |
|
| 3451 |
chandransh |
163 |
def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
|
| 3427 |
chandransh |
164 |
"""
|
|
|
165 |
Returns orders for a particular provider and warehouse which were shipped between the given dates.
|
| 3451 |
chandransh |
166 |
Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
|
|
|
167 |
Pass providerId and warehouseId as -1 to ignore both these parameters.
|
| 3427 |
chandransh |
168 |
|
|
|
169 |
Parameters:
|
|
|
170 |
- fromShippingDate
|
|
|
171 |
- toShippingDate
|
|
|
172 |
- providerId
|
|
|
173 |
- warehouseId
|
| 3451 |
chandransh |
174 |
- cod
|
| 3427 |
chandransh |
175 |
"""
|
|
|
176 |
try:
|
|
|
177 |
from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
|
| 3451 |
chandransh |
178 |
orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
|
| 3427 |
chandransh |
179 |
return [to_t_order(order) for order in orders]
|
|
|
180 |
finally:
|
|
|
181 |
close_session()
|
|
|
182 |
|
| 1382 |
varun.gupt |
183 |
def getReturnableOrdersForCustomer(self, customerId, limit = None):
|
|
|
184 |
"""
|
|
|
185 |
Parameters:
|
|
|
186 |
- customerId
|
|
|
187 |
- limit
|
|
|
188 |
"""
|
|
|
189 |
try:
|
|
|
190 |
return get_returnable_orders_for_customer(customerId, limit)
|
|
|
191 |
finally:
|
|
|
192 |
close_session()
|
| 995 |
varun.gupt |
193 |
|
| 1382 |
varun.gupt |
194 |
def getCancellableOrdersForCustomer(self, customerId, limit = None):
|
|
|
195 |
"""
|
|
|
196 |
Parameters:
|
|
|
197 |
- customerId
|
|
|
198 |
- limit
|
|
|
199 |
"""
|
|
|
200 |
try:
|
|
|
201 |
return get_cancellable_orders_for_customer(customerId, limit)
|
|
|
202 |
finally:
|
|
|
203 |
close_session()
|
|
|
204 |
|
| 483 |
rajveer |
205 |
def changeOrderStatus(self, orderId, status, description):
|
|
|
206 |
"""
|
|
|
207 |
Parameters:
|
|
|
208 |
- orderId
|
|
|
209 |
- status
|
|
|
210 |
- description
|
|
|
211 |
-
|
|
|
212 |
"""
|
| 766 |
rajveer |
213 |
try:
|
|
|
214 |
return change_order_status(self, orderId, status, description)
|
|
|
215 |
finally:
|
|
|
216 |
close_session()
|
| 921 |
rajveer |
217 |
|
| 3064 |
chandransh |
218 |
def verifyOrder(self, orderId):
|
|
|
219 |
"""
|
|
|
220 |
Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
|
|
|
221 |
timestamp. It is intended to be used for COD orders but can be harmlessly
|
|
|
222 |
used for all other orders as well.
|
|
|
223 |
Throws an exception if no such order exists.
|
|
|
224 |
|
|
|
225 |
Parameters:
|
|
|
226 |
- orderId
|
|
|
227 |
"""
|
|
|
228 |
try:
|
|
|
229 |
return verify_order(self, orderId)
|
|
|
230 |
finally:
|
|
|
231 |
close_session()
|
|
|
232 |
|
| 921 |
rajveer |
233 |
def acceptOrder(self, orderId):
|
|
|
234 |
"""
|
| 3064 |
chandransh |
235 |
Marks the given order as ACCEPTED and updates the accepted timestamp. If the
|
|
|
236 |
given order is not a COD order, it also captures the payment if the same has
|
|
|
237 |
not been captured.
|
|
|
238 |
Throws an exception if no such order exists.
|
|
|
239 |
|
| 921 |
rajveer |
240 |
Parameters:
|
|
|
241 |
- orderId
|
|
|
242 |
"""
|
|
|
243 |
try:
|
|
|
244 |
return accept_order(self, orderId)
|
|
|
245 |
finally:
|
|
|
246 |
close_session()
|
|
|
247 |
|
|
|
248 |
def billOrder(self, orderId):
|
|
|
249 |
"""
|
|
|
250 |
Parameters:
|
|
|
251 |
- orderId
|
|
|
252 |
"""
|
|
|
253 |
try:
|
|
|
254 |
return bill_order(self, orderId)
|
|
|
255 |
finally:
|
|
|
256 |
close_session()
|
| 766 |
rajveer |
257 |
|
| 3014 |
chandransh |
258 |
def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
|
| 104 |
ashish |
259 |
"""
|
| 3014 |
chandransh |
260 |
Returns list of orders for the given customer created between the given dates and having the given statuses.
|
|
|
261 |
Pass and empty list to ignore filtering on statuses.
|
|
|
262 |
|
| 104 |
ashish |
263 |
Parameters:
|
|
|
264 |
- customerId
|
|
|
265 |
- from_date
|
|
|
266 |
- to_date
|
| 3014 |
chandransh |
267 |
- statuses
|
| 104 |
ashish |
268 |
"""
|
| 766 |
rajveer |
269 |
try:
|
|
|
270 |
current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
|
|
|
271 |
|
| 3014 |
chandransh |
272 |
orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
|
| 766 |
rajveer |
273 |
return [to_t_order(order) for order in orders]
|
|
|
274 |
finally:
|
|
|
275 |
close_session()
|
| 1528 |
ankur.sing |
276 |
|
|
|
277 |
def getOrderForCustomer(self, orderId, customerId):
|
|
|
278 |
"""
|
|
|
279 |
Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
|
|
|
280 |
Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
|
|
|
281 |
|
|
|
282 |
Parameters:
|
|
|
283 |
- customerId
|
|
|
284 |
- orderId
|
|
|
285 |
"""
|
|
|
286 |
try:
|
|
|
287 |
return to_t_order(get_order_for_customer(orderId, customerId))
|
|
|
288 |
finally:
|
|
|
289 |
close_session()
|
| 766 |
rajveer |
290 |
|
| 483 |
rajveer |
291 |
def getOrder(self, id):
|
|
|
292 |
"""
|
|
|
293 |
Parameters:
|
|
|
294 |
- id
|
|
|
295 |
"""
|
| 766 |
rajveer |
296 |
try:
|
|
|
297 |
return to_t_order(get_order(id))
|
|
|
298 |
finally:
|
|
|
299 |
close_session()
|
|
|
300 |
|
| 483 |
rajveer |
301 |
def getLineItemsForOrder(self, orderId):
|
|
|
302 |
"""
|
|
|
303 |
Parameters:
|
|
|
304 |
- orderId
|
|
|
305 |
"""
|
| 766 |
rajveer |
306 |
try:
|
|
|
307 |
lineitems = get_line_items_for_order(orderId)
|
|
|
308 |
t_lineitems = []
|
|
|
309 |
for lineitem in lineitems:
|
|
|
310 |
t_lineitems.append(to_t_lineitem(lineitem))
|
|
|
311 |
return t_lineitems
|
|
|
312 |
finally:
|
|
|
313 |
close_session()
|
| 1149 |
chandransh |
314 |
|
|
|
315 |
def addBillingDetails(self, orderId, invoice_number, billed_by):
|
| 494 |
rajveer |
316 |
"""
|
| 1149 |
chandransh |
317 |
Add billing details such as the bill number and the biller to the Order.
|
|
|
318 |
|
| 494 |
rajveer |
319 |
Parameters:
|
|
|
320 |
- orderId
|
|
|
321 |
- invoice_number
|
|
|
322 |
- billed_by
|
|
|
323 |
"""
|
| 766 |
rajveer |
324 |
try:
|
| 1149 |
chandransh |
325 |
return add_billing_details(orderId, invoice_number, billed_by)
|
| 766 |
rajveer |
326 |
finally:
|
|
|
327 |
close_session()
|
| 1149 |
chandransh |
328 |
|
| 2842 |
chandransh |
329 |
def addJacketNumber(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy, billingType):
|
| 1149 |
chandransh |
330 |
"""
|
| 2783 |
chandransh |
331 |
Adds jacket number and IMEI no. to the order. Doesn't update the IMEI no. if a -1 is supplied.
|
|
|
332 |
Also marks the order as billed and sets the billing timestamp.
|
|
|
333 |
Return false if it doesn't find the order with the given ID.
|
| 1149 |
chandransh |
334 |
|
|
|
335 |
Parameters:
|
|
|
336 |
- orderId
|
|
|
337 |
- jacketNumber
|
| 2783 |
chandransh |
338 |
- imeiNumber
|
|
|
339 |
- itemNumber
|
|
|
340 |
- billedBy
|
| 1149 |
chandransh |
341 |
"""
|
|
|
342 |
try:
|
| 2842 |
chandransh |
343 |
return add_jacket_number(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy, billingType)
|
| 2783 |
chandransh |
344 |
except TransactionServiceException:
|
|
|
345 |
print "ERROR: Couldn't find the order with the given id"
|
|
|
346 |
return False
|
| 1149 |
chandransh |
347 |
finally:
|
|
|
348 |
close_session()
|
| 1220 |
chandransh |
349 |
|
|
|
350 |
def batchOrders(self, warehouseId):
|
|
|
351 |
"""
|
|
|
352 |
Create a batch of all the pending orders for the given warehouse.
|
|
|
353 |
The returned list is orderd by created_timestamp.
|
|
|
354 |
If there are no pending orders, an empty list is returned.
|
| 1208 |
chandransh |
355 |
|
| 1220 |
chandransh |
356 |
Parameters:
|
|
|
357 |
- warehouseId
|
|
|
358 |
"""
|
|
|
359 |
try:
|
|
|
360 |
pending_orders = batch_orders(warehouseId)
|
|
|
361 |
return [to_t_order(order) for order in pending_orders]
|
|
|
362 |
finally:
|
|
|
363 |
close_session()
|
|
|
364 |
|
| 1208 |
chandransh |
365 |
def markOrderAsOutOfStock(self, orderId):
|
|
|
366 |
"""
|
|
|
367 |
Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
Parameters:
|
|
|
371 |
- orderId
|
|
|
372 |
"""
|
|
|
373 |
try:
|
|
|
374 |
return order_outofstock(orderId)
|
|
|
375 |
finally:
|
|
|
376 |
close_session()
|
|
|
377 |
|
| 3064 |
chandransh |
378 |
def markOrdersAsManifested(self, warehouseId, providerId, cod):
|
| 759 |
chandransh |
379 |
"""
|
| 3064 |
chandransh |
380 |
Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
|
|
|
381 |
given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
|
| 759 |
chandransh |
382 |
|
|
|
383 |
Parameters:
|
|
|
384 |
- warehouseId
|
|
|
385 |
- providerId
|
| 3064 |
chandransh |
386 |
- cod
|
| 759 |
chandransh |
387 |
"""
|
| 766 |
rajveer |
388 |
try:
|
| 3064 |
chandransh |
389 |
return mark_orders_as_manifested(warehouseId, providerId, cod)
|
| 766 |
rajveer |
390 |
finally:
|
|
|
391 |
close_session()
|
| 1113 |
chandransh |
392 |
|
|
|
393 |
def markOrdersAsPickedUp(self, providerId, pickupDetails):
|
|
|
394 |
"""
|
|
|
395 |
Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
|
|
|
396 |
Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
|
|
|
397 |
Raises an exception if we encounter report for an AWB number that we did not ship.
|
|
|
398 |
|
|
|
399 |
Parameters:
|
|
|
400 |
- providerId
|
|
|
401 |
- pickupDetails
|
|
|
402 |
"""
|
|
|
403 |
try:
|
|
|
404 |
orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
|
|
|
405 |
return [to_t_order(order) for order in orders_not_picked_up]
|
|
|
406 |
finally:
|
|
|
407 |
close_session()
|
| 1132 |
chandransh |
408 |
|
|
|
409 |
def markOrdersAsDelivered(self, providerId, deliveredOrders):
|
|
|
410 |
"""
|
|
|
411 |
Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
|
|
|
412 |
the name of the receiver.
|
|
|
413 |
Raises an exception if we encounter report for an AWB number that we did not ship.
|
|
|
414 |
|
|
|
415 |
Parameters:
|
|
|
416 |
- providerId
|
|
|
417 |
- deliveredOrders
|
|
|
418 |
"""
|
|
|
419 |
try:
|
|
|
420 |
mark_orders_as_delivered(providerId, deliveredOrders)
|
|
|
421 |
finally:
|
|
|
422 |
close_session()
|
| 1135 |
chandransh |
423 |
|
|
|
424 |
def markOrdersAsFailed(self, providerId, returnedOrders):
|
|
|
425 |
"""
|
|
|
426 |
Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
|
|
|
427 |
Raises an exception if we encounter report for an AWB number that we did not ship.
|
|
|
428 |
|
|
|
429 |
Parameters:
|
|
|
430 |
- providerId
|
|
|
431 |
- returnedOrders
|
|
|
432 |
"""
|
|
|
433 |
try:
|
|
|
434 |
mark_orders_as_failed(providerId, returnedOrders)
|
|
|
435 |
finally:
|
|
|
436 |
close_session()
|
| 1246 |
chandransh |
437 |
|
|
|
438 |
def updateNonDeliveryReason(self, providerId, undeliveredOrders):
|
|
|
439 |
"""
|
|
|
440 |
Update the status description of orders whose AWB numbers are keys of the Map.
|
|
|
441 |
|
|
|
442 |
Parameters:
|
|
|
443 |
- providerId
|
|
|
444 |
- undelivered_orders
|
|
|
445 |
"""
|
|
|
446 |
try:
|
|
|
447 |
update_non_delivery_reason(providerId, undeliveredOrders)
|
|
|
448 |
finally:
|
|
|
449 |
close_session()
|
| 1405 |
ankur.sing |
450 |
|
|
|
451 |
def getUndeliveredOrders(self, providerId, warehouseId):
|
|
|
452 |
"""
|
|
|
453 |
Returns the list of orders whose delivery time has passed but have not been
|
|
|
454 |
delivered yet for the given provider and warehouse. To get a complete list of
|
|
|
455 |
undelivered orders, pass them as -1.
|
|
|
456 |
Returns an empty list if no such orders exist.
|
|
|
457 |
|
|
|
458 |
Parameters:
|
|
|
459 |
- providerId
|
|
|
460 |
- warehouseId
|
|
|
461 |
"""
|
|
|
462 |
try:
|
|
|
463 |
undelivered_orders = get_undelivered_orders(providerId, warehouseId)
|
|
|
464 |
return [to_t_order(order) for order in undelivered_orders]
|
|
|
465 |
finally:
|
|
|
466 |
close_session()
|
| 1351 |
varun.gupt |
467 |
|
| 1398 |
varun.gupt |
468 |
def enqueueTransactionInfoEmail(self, transactionId):
|
| 1351 |
varun.gupt |
469 |
"""
|
| 1398 |
varun.gupt |
470 |
Save the email containing order details to be sent to customer later by batch job
|
| 1351 |
varun.gupt |
471 |
|
|
|
472 |
Parameters:
|
|
|
473 |
- transactionId
|
|
|
474 |
"""
|
|
|
475 |
try:
|
| 1398 |
varun.gupt |
476 |
return enqueue_transaction_info_email(transactionId)
|
| 1351 |
varun.gupt |
477 |
finally:
|
|
|
478 |
close_session()
|
|
|
479 |
|
| 483 |
rajveer |
480 |
def getAlerts(self, orderId, valid):
|
|
|
481 |
"""
|
|
|
482 |
Parameters:
|
|
|
483 |
- orderId
|
|
|
484 |
- valid
|
|
|
485 |
"""
|
| 766 |
rajveer |
486 |
try:
|
|
|
487 |
alerts = get_alerts(orderId, valid)
|
|
|
488 |
|
|
|
489 |
t_alerts = []
|
|
|
490 |
|
|
|
491 |
for alert in alerts:
|
|
|
492 |
t_alerts.append(to_t_alert(alert))
|
|
|
493 |
|
|
|
494 |
return t_alerts
|
|
|
495 |
finally:
|
|
|
496 |
close_session()
|
|
|
497 |
|
| 483 |
rajveer |
498 |
def setAlert(self, orderId, unset, type, comment):
|
|
|
499 |
"""
|
|
|
500 |
Parameters:
|
|
|
501 |
- orderId
|
|
|
502 |
- unset
|
|
|
503 |
- type
|
|
|
504 |
- comment
|
|
|
505 |
"""
|
| 766 |
rajveer |
506 |
try:
|
|
|
507 |
set_alert(orderId, unset, type, comment)
|
|
|
508 |
finally:
|
|
|
509 |
close_session()
|
| 1596 |
ankur.sing |
510 |
|
|
|
511 |
def getValidOrderCount(self, ):
|
|
|
512 |
"""
|
|
|
513 |
Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
|
|
|
514 |
"""
|
| 1731 |
ankur.sing |
515 |
try:
|
|
|
516 |
return get_valid_order_count()
|
|
|
517 |
finally:
|
|
|
518 |
close_session()
|
| 1627 |
ankur.sing |
519 |
|
|
|
520 |
def getNoOfCustomersWithSuccessfulTransaction(self, ):
|
|
|
521 |
"""
|
|
|
522 |
Returns the number of distinct customers who have done successful transactions
|
|
|
523 |
"""
|
| 1731 |
ankur.sing |
524 |
try:
|
|
|
525 |
return get_cust_count_with_successful_txn()
|
|
|
526 |
finally:
|
|
|
527 |
close_session()
|
| 1627 |
ankur.sing |
528 |
|
| 1731 |
ankur.sing |
529 |
|
|
|
530 |
def getValidOrdersAmountRange(self, ):
|
| 1627 |
ankur.sing |
531 |
"""
|
| 1731 |
ankur.sing |
532 |
Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
|
|
|
533 |
List contains two values, first minimum amount and second maximum amount.
|
| 1627 |
ankur.sing |
534 |
"""
|
| 1731 |
ankur.sing |
535 |
try:
|
|
|
536 |
return get_valid_orders_amount_range()
|
|
|
537 |
finally:
|
|
|
538 |
close_session()
|
| 1627 |
ankur.sing |
539 |
|
| 1886 |
ankur.sing |
540 |
def getValidOrders(self, limit):
|
|
|
541 |
"""
|
|
|
542 |
Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
|
|
|
543 |
If limit is passed as 0, then all valid Orders are returned.
|
|
|
544 |
|
|
|
545 |
Parameters:
|
|
|
546 |
- limit
|
|
|
547 |
"""
|
|
|
548 |
try:
|
|
|
549 |
return [to_t_order(order) for order in get_valid_orders(limit)]
|
|
|
550 |
finally:
|
|
|
551 |
close_session()
|
| 104 |
ashish |
552 |
|
| 2536 |
chandransh |
553 |
def toggleDOAFlag(self, orderId):
|
| 104 |
ashish |
554 |
"""
|
| 2536 |
chandransh |
555 |
Toggle the DOA flag of an order. This should be used to flag an order for follow-up and unflag it when the follow-up is complete.
|
|
|
556 |
Returns the final flag status.
|
|
|
557 |
Throws an exception if the order with the given id couldn't be found or if the order status is not DELVIERY_SUCCESS.
|
| 483 |
rajveer |
558 |
|
| 132 |
ashish |
559 |
Parameters:
|
| 2536 |
chandransh |
560 |
- orderId
|
| 132 |
ashish |
561 |
"""
|
| 2536 |
chandransh |
562 |
try:
|
|
|
563 |
return toggle_doa_flag(orderId)
|
|
|
564 |
finally:
|
|
|
565 |
close_session()
|
| 483 |
rajveer |
566 |
|
| 2536 |
chandransh |
567 |
def requestPickupNumber(self, orderId):
|
| 104 |
ashish |
568 |
"""
|
| 2536 |
chandransh |
569 |
Sends out an email to the account manager of the original courier provider used to ship the order.
|
|
|
570 |
If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUESTED.
|
|
|
571 |
If the order status was DOA_PICKUP_REQUESTED, it is left unchanged.
|
|
|
572 |
For any other status, it returns false.
|
|
|
573 |
Throws an exception if the order with the given id couldn't be found.
|
| 104 |
ashish |
574 |
|
|
|
575 |
Parameters:
|
| 2536 |
chandransh |
576 |
- orderId
|
| 104 |
ashish |
577 |
"""
|
| 2536 |
chandransh |
578 |
try:
|
|
|
579 |
return request_pickup_number(orderId)
|
|
|
580 |
finally:
|
|
|
581 |
close_session()
|
| 483 |
rajveer |
582 |
|
| 2536 |
chandransh |
583 |
def authorizePickup(self, orderId, pickupNumber):
|
| 304 |
ashish |
584 |
"""
|
| 2536 |
chandransh |
585 |
If the order status is DOA_PICKUP_REQUESTED, it does the following
|
|
|
586 |
1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
|
|
|
587 |
2. Changes order status to be DOA_PICKUP_AUTHORIZED.
|
|
|
588 |
3. Returns true
|
|
|
589 |
If the order is any other status, it returns false.
|
|
|
590 |
Throws an exception if the order with the given id couldn't be found.
|
| 304 |
ashish |
591 |
|
|
|
592 |
Parameters:
|
| 2536 |
chandransh |
593 |
- orderId
|
|
|
594 |
- pickupNumber
|
| 304 |
ashish |
595 |
"""
|
| 2536 |
chandransh |
596 |
try:
|
|
|
597 |
return authorize_pickup(orderId, pickupNumber)
|
|
|
598 |
finally:
|
|
|
599 |
close_session()
|
| 2764 |
chandransh |
600 |
|
|
|
601 |
def markDoasAsPickedUp(self, providerId, pickupDetails):
|
|
|
602 |
"""
|
|
|
603 |
Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
|
|
|
604 |
Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
|
|
|
605 |
|
|
|
606 |
Parameters:
|
|
|
607 |
- providerId
|
|
|
608 |
- pickupDetails
|
|
|
609 |
"""
|
|
|
610 |
try:
|
|
|
611 |
orders_not_picked_up = mark_doas_as_picked_up(providerId, pickupDetails)
|
|
|
612 |
return [to_t_order(order) for order in orders_not_picked_up]
|
|
|
613 |
finally:
|
|
|
614 |
close_session()
|
| 2591 |
chandransh |
615 |
|
| 2616 |
chandransh |
616 |
def receiveReturn(self, orderId):
|
| 2591 |
chandransh |
617 |
"""
|
| 2599 |
chandransh |
618 |
If the order status is DOA_RETURN_AUTHORIZED or DOA_RETURN_IN_TRANSIT, marks the order status as DOA_RECEIVED and returns true.
|
| 2591 |
chandransh |
619 |
If the order is in any other state, it returns false.
|
|
|
620 |
Throws an exception if the order with the given id couldn't be found.
|
|
|
621 |
|
|
|
622 |
Parameters:
|
|
|
623 |
- orderId
|
|
|
624 |
"""
|
|
|
625 |
try:
|
| 2616 |
chandransh |
626 |
return receive_return(orderId)
|
| 2591 |
chandransh |
627 |
finally:
|
|
|
628 |
close_session()
|
|
|
629 |
|
|
|
630 |
def validateDoa(self, orderId, isValid):
|
|
|
631 |
"""
|
| 2599 |
chandransh |
632 |
Used to validate the DOA certificate for an order in the DOA_RECEIVED state. If the certificate is valid,
|
| 2609 |
chandransh |
633 |
the order state is changed to DOA_CERT_PENDING.
|
| 2591 |
chandransh |
634 |
If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
|
|
|
635 |
If the order is in any other state, it returns false.
|
|
|
636 |
Throws an exception if the order with the given id couldn't be found.
|
|
|
637 |
|
|
|
638 |
Parameters:
|
|
|
639 |
- orderId
|
|
|
640 |
- isValid
|
|
|
641 |
"""
|
|
|
642 |
try:
|
|
|
643 |
return validate_doa(orderId, isValid)
|
|
|
644 |
finally:
|
|
|
645 |
close_session()
|
| 2628 |
chandransh |
646 |
|
|
|
647 |
def reshipOrder(self, orderId):
|
|
|
648 |
"""
|
|
|
649 |
If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
|
|
|
650 |
1. Creates a new order for processing in the BILLED state. All billing information is saved.
|
|
|
651 |
2. Marks the current order as one of the final states SALES_RET_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
|
|
|
652 |
|
|
|
653 |
If the order is in DOA_CERT_VALID state, it does the following:
|
|
|
654 |
1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
|
|
|
655 |
2. Creates a return order for the warehouse executive to return the DOA material.
|
|
|
656 |
3. Marks the current order as the final DOA_RESHIPPED state.
|
|
|
657 |
|
|
|
658 |
Returns the id of the newly created order.
|
|
|
659 |
|
|
|
660 |
Throws an exception if the order with the given id couldn't be found.
|
|
|
661 |
|
|
|
662 |
Parameters:
|
|
|
663 |
- orderId
|
|
|
664 |
"""
|
|
|
665 |
try:
|
|
|
666 |
return reship_order(orderId)
|
|
|
667 |
finally:
|
|
|
668 |
close_session()
|
|
|
669 |
|
| 3226 |
chandransh |
670 |
def refundOrder(self, orderId, refundedBy, reason):
|
| 2628 |
chandransh |
671 |
"""
|
|
|
672 |
If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
|
|
|
673 |
1. Creates a refund request for batch processing.
|
|
|
674 |
2. Creates a return order for the warehouse executive to return the shipped material.
|
|
|
675 |
3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
|
|
|
676 |
|
|
|
677 |
If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
|
|
|
678 |
1. Creates a refund request for batch processing.
|
| 3226 |
chandransh |
679 |
2. Cancels the reservation of the item in the warehouse.
|
|
|
680 |
3. Marks the current order as the REFUNDED final state.
|
| 2628 |
chandransh |
681 |
|
| 3226 |
chandransh |
682 |
For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
|
|
|
683 |
1. Cancels the reservation of the item in the warehouse.
|
|
|
684 |
2. Marks the current order as CANCELED.
|
|
|
685 |
|
|
|
686 |
In all cases, it updates the reason for cancellation or refund and the person who performed the action.
|
|
|
687 |
|
| 2628 |
chandransh |
688 |
Returns True if it is successful, False otherwise.
|
|
|
689 |
|
|
|
690 |
Throws an exception if the order with the given id couldn't be found.
|
|
|
691 |
|
|
|
692 |
Parameters:
|
|
|
693 |
- orderId
|
| 3226 |
chandransh |
694 |
- refundedBy
|
|
|
695 |
- reason
|
| 2628 |
chandransh |
696 |
"""
|
|
|
697 |
try:
|
| 3226 |
chandransh |
698 |
return refund_order(orderId, refundedBy, reason)
|
| 2628 |
chandransh |
699 |
finally:
|
|
|
700 |
close_session()
|
|
|
701 |
|
| 2697 |
chandransh |
702 |
def getReturnOrders(self, warehouseId, fromDate, toDate):
|
|
|
703 |
"""
|
|
|
704 |
Get all return orders created between the from and to dates for the given warehouse.
|
|
|
705 |
Ignores the warehouse if it is passed as -1.
|
|
|
706 |
|
|
|
707 |
Parameters:
|
|
|
708 |
- warehouseId
|
|
|
709 |
- fromDate
|
|
|
710 |
- toDate
|
|
|
711 |
"""
|
|
|
712 |
try:
|
|
|
713 |
from_date, to_date = get_fdate_tdate(fromDate, toDate)
|
|
|
714 |
return get_return_orders(warehouseId, from_date, to_date)
|
|
|
715 |
finally:
|
|
|
716 |
close_session()
|
|
|
717 |
|
| 2700 |
chandransh |
718 |
def getReturnOrder(self, id):
|
|
|
719 |
"""
|
|
|
720 |
Returns the ReturnOrder corresponding to the given id.
|
|
|
721 |
Throws an exception if the return order with the given id couldn't be found.
|
|
|
722 |
|
|
|
723 |
Parameters:
|
|
|
724 |
- id
|
|
|
725 |
"""
|
|
|
726 |
try:
|
|
|
727 |
return get_return_order(id)
|
|
|
728 |
finally:
|
|
|
729 |
close_session()
|
|
|
730 |
|
| 2697 |
chandransh |
731 |
def processReturn(self, returnOrderId):
|
|
|
732 |
"""
|
|
|
733 |
Marks the return order with the given id as processed. Raises an exception if no such return order exists.
|
|
|
734 |
|
|
|
735 |
Parameters:
|
|
|
736 |
- returnOrderId
|
|
|
737 |
"""
|
|
|
738 |
try:
|
|
|
739 |
process_return(returnOrderId)
|
|
|
740 |
finally:
|
|
|
741 |
close_session()
|
| 2591 |
chandransh |
742 |
|
| 2819 |
chandransh |
743 |
def createPurchaseOrder(self, warehouseId):
|
|
|
744 |
"""
|
|
|
745 |
Creates a purchase order corresponding to all the pending orders of the given warehouse.
|
|
|
746 |
Returns the PO no. of the newly created purchase order.
|
|
|
747 |
|
|
|
748 |
Parameters:
|
|
|
749 |
- warehouseId
|
|
|
750 |
"""
|
|
|
751 |
try:
|
|
|
752 |
return create_purchase_order(warehouseId)
|
|
|
753 |
finally:
|
|
|
754 |
close_session()
|
| 3451 |
chandransh |
755 |
|
|
|
756 |
def updateWeight(self, orderId, weight):
|
|
|
757 |
"""
|
|
|
758 |
Set the weight of the given order to the provided value. Will attempt to update the weight of the item in the catalog as well.
|
|
|
759 |
|
|
|
760 |
Parameters:
|
|
|
761 |
- orderId
|
|
|
762 |
- weight
|
|
|
763 |
"""
|
|
|
764 |
try:
|
|
|
765 |
order = update_weight(orderId, weight)
|
|
|
766 |
return to_t_order(order)
|
|
|
767 |
finally:
|
|
|
768 |
close_session()
|
|
|
769 |
|
| 3469 |
chandransh |
770 |
def changeItem(self, orderId, itemId):
|
|
|
771 |
"""
|
|
|
772 |
Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
|
|
|
773 |
Currently, it also ensures that only a different color of the given item is shipped.
|
|
|
774 |
|
|
|
775 |
Parameters:
|
|
|
776 |
- orderId
|
|
|
777 |
- itemId
|
|
|
778 |
"""
|
|
|
779 |
try:
|
|
|
780 |
order = change_product(orderId, itemId)
|
|
|
781 |
return to_t_order(order)
|
|
|
782 |
finally:
|
|
|
783 |
close_session()
|
|
|
784 |
|
|
|
785 |
def shiftToWarehouse(self, orderId, warehouseId):
|
|
|
786 |
"""
|
|
|
787 |
Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
|
|
|
788 |
|
|
|
789 |
Parameters:
|
|
|
790 |
- orderId
|
|
|
791 |
- warehouseId
|
|
|
792 |
"""
|
|
|
793 |
try:
|
|
|
794 |
order = change_warehouse(orderId, warehouseId)
|
|
|
795 |
return to_t_order(order)
|
|
|
796 |
finally:
|
|
|
797 |
close_session()
|
| 3553 |
chandransh |
798 |
|
| 3986 |
chandransh |
799 |
def addDelayReason(self, orderId, delayReason, furtherDelay):
|
| 3553 |
chandransh |
800 |
"""
|
|
|
801 |
Adds the given delay reason to the given order.
|
| 3986 |
chandransh |
802 |
Increases the expected delivery time of the given order by the given no. of days.
|
| 3553 |
chandransh |
803 |
Raises an exception if no order with the given id can be found.
|
| 3469 |
chandransh |
804 |
|
| 3553 |
chandransh |
805 |
Parameters:
|
|
|
806 |
- orderId
|
|
|
807 |
- delayReason
|
|
|
808 |
"""
|
|
|
809 |
try:
|
| 3986 |
chandransh |
810 |
return add_delay_reason(orderId, delayReason, furtherDelay)
|
| 3553 |
chandransh |
811 |
finally:
|
|
|
812 |
close_session()
|
|
|
813 |
|
| 3956 |
chandransh |
814 |
def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
|
|
|
815 |
"""
|
|
|
816 |
Marks the COD orders with given AWB nos. as having been processed.
|
|
|
817 |
Updates the captured amount for the corresponding payment.
|
|
|
818 |
|
|
|
819 |
Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
|
|
|
820 |
1. There is no order corresponding to an AWB number.
|
|
|
821 |
2. The captured amount for a payment exceeds the total payment.
|
|
|
822 |
3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
|
|
|
823 |
|
|
|
824 |
Parameters:
|
|
|
825 |
- collectedAmountMap
|
|
|
826 |
- xferBy
|
|
|
827 |
- xferTxnId
|
|
|
828 |
- xferDate
|
|
|
829 |
"""
|
|
|
830 |
try:
|
|
|
831 |
return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
|
|
|
832 |
finally:
|
|
|
833 |
close_session()
|
| 4008 |
mandeep.dh |
834 |
|
|
|
835 |
def getTransactionsRequiringExtraProcessing(self, category):
|
|
|
836 |
"""
|
|
|
837 |
Returns the list of transactions that require some extra processing and
|
|
|
838 |
which belong to a particular category. This is currently used by CRM
|
|
|
839 |
application.
|
|
|
840 |
"""
|
|
|
841 |
try:
|
|
|
842 |
return get_transactions_requiring_extra_processing(category)
|
|
|
843 |
finally:
|
|
|
844 |
close_session()
|
|
|
845 |
|
|
|
846 |
def markTransactionAsProcessed(self, transactionId, category):
|
|
|
847 |
"""
|
|
|
848 |
Marks a particular transaction as processed for a particular category.
|
|
|
849 |
It essentially deletes the transaction if it is processed for a particular
|
|
|
850 |
category. This is currently used by CRM application.
|
|
|
851 |
"""
|
|
|
852 |
try:
|
|
|
853 |
return mark_transaction_as_processed(transactionId, category)
|
|
|
854 |
finally:
|
|
|
855 |
close_session()
|
| 3956 |
chandransh |
856 |
|
| 2536 |
chandransh |
857 |
def closeSession(self, ):
|
|
|
858 |
close_session()
|
| 3376 |
rajveer |
859 |
|
|
|
860 |
def isAlive(self, ):
|
|
|
861 |
"""
|
|
|
862 |
For checking weather service is active alive or not. It also checks connectivity with database
|
|
|
863 |
"""
|
|
|
864 |
try:
|
|
|
865 |
return is_alive()
|
|
|
866 |
finally:
|
|
|
867 |
close_session()
|