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