Subversion Repositories SmartDukaan

Rev

Rev 5833 | Rev 6000 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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,\
4394 rajveer 12
    get_all_orders, change_order_status, get_alerts, add_alert, add_billing_details,\
4910 phani.kuma 13
    close_session, accept_order, mark_orders_as_picked_up,\
14
    mark_orders_as_delivered, mark_orders_as_rto,\
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,\
4905 varun.gupt 20
    process_return, get_return_order, mark_doas_as_picked_up, verify_order, is_alive, get_orders_by_shipping_date,\
3956 chandransh 21
    update_weight, change_warehouse, change_product, add_delay_reason,\
4008 mandeep.dh 22
    reconcile_cod_collection, get_transactions_requiring_extra_processing,\
5593 mandeep.dh 23
    mark_transaction_as_processed, get_item_wise_risky_orders_count, accept_order_for_item, \
4905 varun.gupt 24
    get_orders_in_batch, get_order_count, get_ebs_settlement_summaries, mark_order_cancellation_request_received,\
25
    mark_order_cancellation_request_denied, refund_transaction, mark_order_cancellation_request_confirmed,\
4303 rajveer 26
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id,\
4905 varun.gupt 27
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated, mark_orders_as_not_available, update_shipment_address,\
28
    mark_orders_as_timeout, get_order_for_awb, mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
4488 rajveer 29
    mark_order_doa_request_received, mark_order_doa_request_authorized,\
4715 varun.gupt 30
    mark_order_return_request_received, mark_order_return_request_authorized, add_invoice_number, get_reshipped_order_ids, \
4600 varun.gupt 31
    validate_return_product, get_orders_for_provider_for_status, save_ebs_settlement_summary, get_ebs_settlement_date, \
5386 phani.kuma 32
    save_payment_settlements, mark_ebs_settlement_uploaded, get_billed_orders_for_vendor, get_settlement_for_Prepaid, \
4715 varun.gupt 33
    get_settlements_by_date, get_slipped_sipping_date_orders, mark_order_as_lost_in_transit,\
4783 phani.kuma 34
    get_cancelled_orders, mark_order_as_delivered, mark_return_orders_as_picked_up, update_orders_as_PORaised,\
5481 phani.kuma 35
    get_order_distribution_by_status, get_orders_not_met_expected_delivery_date,\
4910 phani.kuma 36
    mark_orders_as_local_connected, mark_orders_as_destinationCityReached,\
37
    mark_orders_as_firstDeliveryAttempted, get_non_delivered_orders_by_courier, get_orders_not_local_connected,\
5067 varun.gupt 38
    get_doas_not_picked_up, get_return_orders_not_picked_up, get_orders_not_picked_up, get_rto_orders, get_order_list,\
5349 anupam.sin 39
    get_order_ids_for_status, update_orders_as_paid_to_vendor, update_COD_agent,\
5447 anupam.sin 40
    get_refunded_orders_marked_paid, get_settlement_for_Cod, get_order_list_for_vendor, update_order_only_as_paid_to_vendor,\
5555 rajveer 41
    get_all_verification_agents, get_all_attributes_for_order_id, set_order_attribute_for_transaction, get_billed_orders, get_all_return_orders,\
42
    mark_order_as_received_at_store, get_receive_pending_orders,\
5713 rajveer 43
    get_received_at_store_orders, mark_orders_as_returned_from_store, set_order_attributes,\
5833 rajveer 44
    get_orders_collection_at_store, get_order_attribute_value
1405 ankur.sing 45
 
5527 anupam.sin 46
 
104 ashish 47
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
5527 anupam.sin 48
    to_t_alert, to_t_order, to_t_lineitem, to_t_payment_settlement, to_t_verification_agent, to_t_attribute
483 rajveer 49
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
2783 chandransh 50
    LineItem, Order, TransactionServiceException
4600 varun.gupt 51
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
104 ashish 52
 
53
class OrderServiceHandler:
54
 
3187 rajveer 55
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 56
        """
104 ashish 57
        Constructor
483 rajveer 58
        """
3187 rajveer 59
        DataService.initialize(dbname, db_hostname)
104 ashish 60
 
61
    def createTransaction(self, transaction):
62
        """
63
        Parameters:
64
         - transaction
65
        """
766 rajveer 66
        try:
67
            return create_transaction(transaction)
68
        finally:
69
            close_session()
70
 
104 ashish 71
    def getTransaction(self, id):
72
        """
73
            Get transaction methods.
74
 
75
        Parameters:
76
         - id
77
        """
766 rajveer 78
        try:
79
            transaction = get_transaction(id)
80
            return to_t_transaction(transaction)
81
        finally:
82
            close_session()
83
 
483 rajveer 84
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 85
        """
86
        Parameters:
483 rajveer 87
         - customerId
104 ashish 88
         - from_date
89
         - to_date
483 rajveer 90
         - status
104 ashish 91
        """
766 rajveer 92
        try:
93
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
94
 
95
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
96
            t_transaction = []
97
            for transaction in transactions:
98
                t_transaction.append(to_t_transaction(transaction))
99
            return t_transaction
100
        finally:
101
            close_session()
483 rajveer 102
 
103
    def getTransactionsForShoppingCartId(self, shoppingCartId):
104
        """
105
        Parameters:
106
            - shoppingCartId
107
        """
766 rajveer 108
        try:
109
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
110
            t_transaction = []
111
            for transaction in transactions:
112
                t_transaction.append(to_t_transaction(transaction))
113
            return t_transaction
114
        finally:
115
            close_session()
104 ashish 116
 
483 rajveer 117
    def getTransactionStatus(self, transactionId):
104 ashish 118
        """
119
        Parameters:
483 rajveer 120
         - transactionId
121
        """
766 rajveer 122
        try:
123
            return get_transaction_status(transactionId)
124
        finally:
125
            close_session()
126
 
5527 anupam.sin 127
    def changeTransactionStatus(self, transactionId, status, description, pickUp, orderType):
483 rajveer 128
        """
129
        Parameters:
130
         - transactionId
104 ashish 131
         - status
483 rajveer 132
         - description
5387 rajveer 133
         - selfPickup
483 rajveer 134
        """
766 rajveer 135
        try:
5527 anupam.sin 136
            return change_transaction_status(transactionId, status, description, pickUp, orderType)
766 rajveer 137
        finally:
138
            close_session()
139
 
1528 ankur.sing 140
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 141
        """
1528 ankur.sing 142
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
143
        only user who owns the transaction can view its order details.
144
 
483 rajveer 145
        Parameters:
146
         - transactionId
1528 ankur.sing 147
         - customerId
483 rajveer 148
        """
766 rajveer 149
        try:
1528 ankur.sing 150
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 151
            return [to_t_order(order) for order in orders]    
152
        finally:
153
            close_session()
154
 
4801 anupam.sin 155
    def getAllOrders(self, statuses, from_date, to_date, warehouse_id):
483 rajveer 156
        """
157
        Parameters:
158
         - status
104 ashish 159
         - from_date
160
         - to_date
483 rajveer 161
         - warehouse_id
104 ashish 162
        """
766 rajveer 163
        try:
164
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
4801 anupam.sin 165
            orders = get_all_orders(statuses, current_from_date, current_to_date, warehouse_id)
766 rajveer 166
            return [to_t_order(order) for order in orders]
167
        finally:
168
            close_session()
4133 chandransh 169
 
170
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id):
171
        """
172
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
173
        Pass the status as null and the limit as 0 to ignore them.
174
 
175
        Parameters:
176
         - statuses
177
         - offset
178
         - limit
179
         - warehouse_id
180
        """
181
        try:
182
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id)
183
            return [to_t_order(order) for order in orders]
184
        finally:
185
            close_session()
186
 
187
    def getOrderCount(self, statuses, warehouseId):
188
        """
189
        Returns the count of orders with the given statuses assigned to the given warehouse.
190
 
191
        Parameters:
192
         - statuses
193
         - warehouseId
194
        """
195
        try:
196
            return get_order_count(statuses, warehouseId)
197
        finally:
198
            close_session()
199
 
995 varun.gupt 200
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
201
        """
202
        Parameters:
203
         - status
204
         - start_billing_date
205
         - end_billing_date
206
         - warehouse_id
207
        """
208
        try:
209
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
210
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
211
            return [to_t_order(order) for order in orders]
212
        finally:
213
            close_session()
1382 varun.gupt 214
 
3451 chandransh 215
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 216
        """
217
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 218
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
219
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 220
 
221
        Parameters:
222
         - fromShippingDate
223
         - toShippingDate
224
         - providerId
225
         - warehouseId
3451 chandransh 226
         - cod
3427 chandransh 227
        """
228
        try:
229
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 230
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 231
            return [to_t_order(order) for order in orders]
232
        finally:
233
            close_session()
234
 
1382 varun.gupt 235
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
236
        """
237
        Parameters:
238
         - customerId
239
         - limit
240
        """
241
        try:
242
            return get_returnable_orders_for_customer(customerId, limit)
243
        finally:
244
            close_session()
995 varun.gupt 245
 
1382 varun.gupt 246
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
247
        """
248
        Parameters:
249
         - customerId
250
         - limit
251
        """
252
        try:
253
            return get_cancellable_orders_for_customer(customerId, limit)
254
        finally:
255
            close_session()
256
 
483 rajveer 257
    def changeOrderStatus(self, orderId, status, description):
258
        """
259
        Parameters:
260
         - orderId
261
         - status
262
         - description
263
         - 
264
        """
766 rajveer 265
        try:
266
            return change_order_status(self, orderId, status, description)
267
        finally:
268
            close_session()
921 rajveer 269
 
3064 chandransh 270
    def verifyOrder(self, orderId):
271
        """
272
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
273
        timestamp. It is intended to be used for COD orders but can be harmlessly
274
        used for all other orders as well.
275
        Throws an exception if no such order exists.
276
 
277
        Parameters:
278
         - orderId
279
        """
280
        try:
281
            return verify_order(self, orderId)
282
        finally:
283
            close_session()
284
 
921 rajveer 285
    def acceptOrder(self, orderId):
286
        """
3064 chandransh 287
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
288
        given order is not a COD order, it also captures the payment if the same has
289
        not been captured.
290
        Throws an exception if no such order exists.
291
 
921 rajveer 292
        Parameters:
293
         - orderId
294
        """
295
        try:
4285 rajveer 296
            return accept_order(orderId)
921 rajveer 297
        finally:
298
            close_session()
299
 
3014 chandransh 300
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 301
        """
3014 chandransh 302
        Returns list of orders for the given customer created between the given dates and having the given statuses.
303
        Pass and empty list to ignore filtering on statuses.
304
 
104 ashish 305
        Parameters:
306
         - customerId
307
         - from_date
308
         - to_date
3014 chandransh 309
         - statuses
104 ashish 310
        """
766 rajveer 311
        try:
312
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
313
 
3014 chandransh 314
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 315
            return [to_t_order(order) for order in orders]
316
        finally:
317
            close_session()
1528 ankur.sing 318
 
319
    def getOrderForCustomer(self, orderId, customerId):
320
        """
321
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
322
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
323
 
324
        Parameters:
325
         - customerId
326
         - orderId
327
        """
328
        try:
329
            return to_t_order(get_order_for_customer(orderId, customerId))
330
        finally:
331
            close_session()
766 rajveer 332
 
483 rajveer 333
    def getOrder(self, id):
334
        """
335
        Parameters:
336
         - id
337
        """
766 rajveer 338
        try:
339
            return to_t_order(get_order(id))
340
        finally:
341
            close_session()
4999 phani.kuma 342
 
343
    def getOrderList(self, order_ids):
344
        """
345
        Parameters:
346
         - order_ids
347
        """
348
        try:
349
            orders = get_order_list(order_ids)
350
            return [to_t_order(order) for order in orders]
351
        finally:
352
            close_session()
353
 
5386 phani.kuma 354
    def getOrderListForVendor(self, order_ids, vendorId):
355
        """
356
        Parameters:
357
         - order_ids
358
         - vendorId
359
        """
360
        try:
361
            orders = get_order_list_for_vendor(order_ids, vendorId)
362
            return [to_t_order(order) for order in orders]
363
        finally:
364
            close_session()
365
 
483 rajveer 366
    def getLineItemsForOrder(self, orderId):
367
        """
368
        Parameters:
369
         - orderId
370
        """
766 rajveer 371
        try:
372
            lineitems = get_line_items_for_order(orderId)
373
            t_lineitems = []
374
            for lineitem in lineitems:
375
                t_lineitems.append(to_t_lineitem(lineitem))
376
            return t_lineitems
377
        finally:
378
            close_session()
1149 chandransh 379
 
4763 rajveer 380
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 381
        """
4658 mandeep.dh 382
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 383
        Also marks the order as billed and sets the billing timestamp.
384
        Return false if it doesn't find the order with the given ID.
1149 chandransh 385
 
386
        Parameters:
387
         - orderId
388
         - jacketNumber
4658 mandeep.dh 389
         - serialNumber
2783 chandransh 390
         - itemNumber
391
         - billedBy
1149 chandransh 392
        """
393
        try:
4763 rajveer 394
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 395
        finally:
396
            close_session()
1220 chandransh 397
 
4763 rajveer 398
    def addInvoiceNumber(self, orderId, invoiceNumber, color):
4579 rajveer 399
        """
400
        Add the invoice number to the order.
401
 
402
        Parameters:
403
         - orderId
404
         - invoice_number
405
        """
406
        try:
4763 rajveer 407
            add_invoice_number(orderId, invoiceNumber, color)
4579 rajveer 408
        finally:
409
            close_session()
410
 
1220 chandransh 411
    def batchOrders(self, warehouseId):
412
        """
413
        Create a batch of all the pending orders for the given warehouse.
414
        The returned list is orderd by created_timestamp.
415
        If there are no pending orders, an empty list is returned.
1208 chandransh 416
 
1220 chandransh 417
        Parameters:
418
         - warehouseId
419
        """
420
        try:
421
            pending_orders = batch_orders(warehouseId)
422
            return [to_t_order(order) for order in pending_orders]
423
        finally:
424
            close_session()
425
 
1208 chandransh 426
    def markOrderAsOutOfStock(self, orderId):
427
        """
428
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
429
 
430
 
431
        Parameters:
432
         - orderId
433
        """
434
        try:
435
            return order_outofstock(orderId)
436
        finally:
437
            close_session()
438
 
4910 phani.kuma 439
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod, orderIds):
759 chandransh 440
        """
3064 chandransh 441
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4910 phani.kuma 442
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 443
 
444
        Parameters:
445
         - warehouseId
446
         - providerId
3064 chandransh 447
         - cod
759 chandransh 448
        """
766 rajveer 449
        try:
4910 phani.kuma 450
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds)
766 rajveer 451
        finally:
452
            close_session()
1113 chandransh 453
 
5713 rajveer 454
    def markOrdersAsReturnedFromStore(self, providerId, orderIds, awbs):
5676 rajveer 455
        """
456
        Parameters:
457
         - providerId
458
         - orderIds
5713 rajveer 459
         - awbs
5676 rajveer 460
        """
461
        try:
5713 rajveer 462
            return mark_orders_as_returned_from_store(providerId, orderIds, awbs)
5676 rajveer 463
        finally:
464
            close_session()
465
 
466
    def setOrderAttributes(self, orderId, attributes):
467
        """
468
        sets attributes for an order
469
 
470
        Parameters:
471
         - orderId
472
         - attributes
473
        """
474
        try:
475
            return set_order_attributes(orderId, attributes)
476
        finally:
477
            close_session()
478
 
479
 
4910 phani.kuma 480
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
4410 rajveer 481
        """
4910 phani.kuma 482
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
483
        Raises an exception if we encounter report for an AWB number that we did not ship.
4410 rajveer 484
 
485
        Parameters:
486
         - providerId
4910 phani.kuma 487
         - pickupDetails
4410 rajveer 488
        """
489
        try:
4910 phani.kuma 490
            mark_orders_as_picked_up(providerId, pickupDetails)
4410 rajveer 491
        finally:
492
            close_session()
493
 
4910 phani.kuma 494
    def getOrdersNotPickedUp(self, providerId):
1113 chandransh 495
        """
496
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
497
 
498
        Parameters:
499
         - providerId
500
        """
501
        try:
4910 phani.kuma 502
            orders_not_picked_up = get_orders_not_picked_up(providerId)
1113 chandransh 503
            return [to_t_order(order) for order in orders_not_picked_up]
504
        finally:
505
            close_session()
1132 chandransh 506
 
507
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
508
        """
509
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
510
        the name of the receiver.
511
        Raises an exception if we encounter report for an AWB number that we did not ship.
512
 
513
        Parameters:
514
         - providerId
515
         - deliveredOrders
516
        """
517
        try:
518
            mark_orders_as_delivered(providerId, deliveredOrders)
519
        finally:
520
            close_session()
1135 chandransh 521
 
4712 rajveer 522
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
523
        """
524
        Attributes:
525
         - orderId
526
         - deliveryTimestamp
527
         - receiver
528
        """
529
        try:
530
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
531
        finally:
532
            close_session()
533
 
534
 
5555 rajveer 535
    def markOrderAsReceivedAtStore(self, orderId, deliveryTimestamp):
536
        """
537
        Attributes:
538
         - orderId
539
         - deliveryTimestamp
540
        """
541
        try:
542
            mark_order_as_received_at_store(orderId, to_py_date(deliveryTimestamp))
543
        finally:
544
            close_session()
545
 
546
    def getReceivePendingOrders(self, storeId):
547
        """
548
        Attributes:
549
         - storeId
550
        """
551
        try:
552
            orders = get_receive_pending_orders(storeId)
553
            return [to_t_order(order) for order in orders]
554
        finally:
555
            close_session()
556
 
557
    def getReceivedAtStoreOrders(self, storeId):
558
        """
559
        Attributes:
560
         - storeId
561
        """
562
        try:
563
            orders = get_received_at_store_orders(storeId)
564
            return [to_t_order(order) for order in orders]
565
        finally:
566
            close_session()
5713 rajveer 567
 
568
    def getOrdersCollectionAtStore(self, storeId, fromDate, toDate, onlyCod):
569
        """
570
        Parameters:
571
         - storeId
572
         - fromDate
573
         - toDate
574
         - onlyCod
575
        """
576
        try:
577
            orders = get_orders_collection_at_store(storeId, to_py_date(fromDate), to_py_date(toDate), onlyCod)
578
            return [to_t_order(order) for order in orders]
579
        finally:
580
            close_session()
581
 
4910 phani.kuma 582
    def markAsRTOrders(self, providerId, returnedOrders):
1135 chandransh 583
        """
4910 phani.kuma 584
        Mark all orders with AWBs in the given map as RTO. Also sets the delivery timestamp.
1135 chandransh 585
        Raises an exception if we encounter report for an AWB number that we did not ship.
586
 
587
        Parameters:
588
         - providerId
589
         - returnedOrders
590
        """
591
        try:
4910 phani.kuma 592
            mark_orders_as_rto(providerId, returnedOrders)
1135 chandransh 593
        finally:
594
            close_session()
1246 chandransh 595
 
4910 phani.kuma 596
    def getRTOrders(self, providerId):
597
        """
598
        Returns a list of orders that were returned by courier.
599
 
600
        Parameters:
601
         - providerId
602
        """
603
        try:
604
            rto_orders = get_rto_orders(providerId)
605
            return [to_t_order(order) for order in rto_orders]
606
        finally:
607
            close_session()
608
 
1246 chandransh 609
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
610
        """
611
        Update the status description of orders whose AWB numbers are keys of the Map.
612
 
613
        Parameters:
614
         - providerId
615
         - undelivered_orders
616
        """
617
        try:
4910 phani.kuma 618
            update_non_delivery_reason(providerId, undeliveredOrders)
619
        finally:
620
            close_session()
621
 
622
    def getNonDeliveredOrdersbyCourier(self, providerId):
623
        """
624
        Returns a list of orders that were picked up or shipped four days ago but did not get delivered.
625
 
626
        Parameters:
627
         - providerId
628
        """
629
        try:
630
            orders_not_delivered = get_non_delivered_orders_by_courier(providerId)
4581 phani.kuma 631
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 632
        finally:
633
            close_session()
1405 ankur.sing 634
 
4910 phani.kuma 635
    def markOrdersAsLocalConnected(self, providerId, local_connected_orders):
636
        """
637
        Mark all orders with AWBs in the given map as local connected. Also sets the local connected timestamp.
638
 
639
        Parameters:
640
         - providerId
641
         - local_connected_orders
642
        """
643
        try:
644
            mark_orders_as_local_connected(providerId, local_connected_orders)
645
        finally:
646
            close_session()
647
 
648
    def getOrdersNotLocalConnected(self, providerId):
649
        """
650
        Returns a list of orders that were picked up or shipped but pending local connection.
651
 
652
        Parameters:
653
         - providerId
654
        """
655
        try:
656
            orders_pending_local_connection = get_orders_not_local_connected(providerId)
657
            return [to_t_order(order) for order in orders_pending_local_connection]
658
        finally:
659
            close_session()
660
 
661
    def markOrdersAsDestinationCityReached(self, providerId, destination_city_reached_orders):
662
        """
663
        Mark all orders with AWBs in the given map as reached destination city. Also sets the reached destination timestamp.
664
 
665
        Parameters:
666
         - providerId
667
         - destination_city_reached_orders
668
        """
669
        try:
670
            mark_orders_as_destinationCityReached(providerId, destination_city_reached_orders)
671
        finally:
672
            close_session()
673
 
674
    def markOrdersAsFirstDeliveryAttempted(self, providerId, first_atdl_orders):
675
        """
676
        Mark all orders with AWBs in the given map as first delivery attempt made. Also sets the first delivery attempted timestamp.
677
 
678
        Parameters:
679
         - providerId
680
         - first_atdl_orders
681
        """
682
        try:
683
            mark_orders_as_firstDeliveryAttempted(providerId, first_atdl_orders)
684
        finally:
685
            close_session()
686
 
4783 phani.kuma 687
    def getUndeliveredOrdersExpectedDeliveryDateNotMet(self):
688
        """
689
        Returns the list of orders whose expected delivery date has passed but have not been
690
        delivered yet.
691
        Returns an empty list if no such orders exist.
692
        """
693
        try:
694
            orders_not_delivered = get_orders_not_met_expected_delivery_date()
695
            return [to_t_order(order) for order in orders_not_delivered]
696
        finally:
697
            close_session()
698
 
1405 ankur.sing 699
    def getUndeliveredOrders(self, providerId, warehouseId):
700
        """
701
        Returns the list of orders whose delivery time has passed but have not been
702
        delivered yet for the given provider and warehouse. To get a complete list of
703
        undelivered orders, pass them as -1.
704
        Returns an empty list if no such orders exist.
705
 
706
        Parameters:
707
         - providerId
708
         - warehouseId
709
        """
710
        try:
711
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
712
            return [to_t_order(order) for order in undelivered_orders]
713
        finally:
714
            close_session()
1351 varun.gupt 715
 
1398 varun.gupt 716
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 717
        """
1398 varun.gupt 718
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 719
 
720
        Parameters:
721
         - transactionId
722
        """
723
        try:
1398 varun.gupt 724
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 725
        finally:
726
            close_session()
727
 
4444 rajveer 728
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 729
        """
730
        Parameters:
4394 rajveer 731
         - type
4444 rajveer 732
         - warehouseId
4394 rajveer 733
         - status
734
         - timestamp
483 rajveer 735
        """
766 rajveer 736
        try:
4444 rajveer 737
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 738
 
739
            t_alerts = []
740
            for alert in alerts:
741
                t_alerts.append(to_t_alert(alert)) 
742
 
743
            return t_alerts
744
        finally:
745
            close_session()
4394 rajveer 746
 
4447 rajveer 747
    def addAlert(self, type, warehouseId, description):
483 rajveer 748
        """
749
        Parameters:
750
         - type
4394 rajveer 751
         - description
4447 rajveer 752
         - warehouseId
483 rajveer 753
        """
766 rajveer 754
        try:
4447 rajveer 755
            add_alert(type, warehouseId, description)
766 rajveer 756
        finally:
757
            close_session()
1596 ankur.sing 758
 
4444 rajveer 759
    def markAlertsAsSeen(self, warehouseId):
760
        """
761
        Parameters:
762
         - warehouseId
763
        """
764
        try:
765
            mark_alerts_as_seen(warehouseId)
766
        finally:
767
            close_session()
768
        pass
769
 
1596 ankur.sing 770
    def getValidOrderCount(self, ):
771
        """
772
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
773
        """
1731 ankur.sing 774
        try:
775
            return get_valid_order_count()
776
        finally:
777
            close_session()
1627 ankur.sing 778
 
779
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
780
        """
781
        Returns the number of distinct customers who have done successful transactions
782
        """
1731 ankur.sing 783
        try:
784
            return get_cust_count_with_successful_txn()
785
        finally:
786
            close_session()
1627 ankur.sing 787
 
1731 ankur.sing 788
 
789
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 790
        """
1731 ankur.sing 791
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
792
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 793
        """
1731 ankur.sing 794
        try:
795
            return get_valid_orders_amount_range()
796
        finally:
797
            close_session()
1627 ankur.sing 798
 
5874 rajveer 799
    def getValidOrders(self, limit, onlyStore):
1886 ankur.sing 800
        """
801
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
802
        If limit is passed as 0, then all valid Orders are returned.
803
 
804
        Parameters:
805
         - limit
5874 rajveer 806
         - onlyStore
1886 ankur.sing 807
        """
808
        try:
5874 rajveer 809
            return [to_t_order(order) for order in get_valid_orders(limit, onlyStore)]
1886 ankur.sing 810
        finally:
811
            close_session()
104 ashish 812
 
2536 chandransh 813
    def toggleDOAFlag(self, orderId):
104 ashish 814
        """
2536 chandransh 815
        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.
816
        Returns the final flag status.
817
        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 818
 
132 ashish 819
        Parameters:
2536 chandransh 820
         - orderId
132 ashish 821
        """
2536 chandransh 822
        try:
823
            return toggle_doa_flag(orderId)
824
        finally:
825
            close_session()
483 rajveer 826
 
4454 rajveer 827
    def markOrderDoaRequestReceived(self, orderId):
828
        """
829
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
830
 
831
        Parameters:
832
         - orderId
833
        """
834
        try:
835
            return mark_order_doa_request_received(orderId)
836
        finally:
837
            close_session()
838
 
839
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized):
840
        """
841
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
842
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
843
 
844
        Parameters:
845
         - orderId
846
         - isAuthorized
847
        """
848
        try:
849
            return mark_order_doa_request_authorized(orderId, isAuthorized)
850
        finally:
851
            close_session()
852
 
4488 rajveer 853
    def markOrderReturnRequestReceived(self, orderId):
854
        """
855
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
856
 
857
        Parameters:
858
         - orderId
859
        """
860
        try:
861
            return mark_order_return_request_received(orderId)
862
        finally:
863
            close_session()
864
 
865
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized):
866
        """
867
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
868
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
869
 
870
        Parameters:
871
         - orderId
872
         - isAuthorized
873
        """
874
        try:
875
            return mark_order_return_request_authorized(orderId, isAuthorized)
876
        finally:
877
            close_session()
878
 
4579 rajveer 879
    def requestPickupNumber(self, orderId, providerId):
104 ashish 880
        """
2536 chandransh 881
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 882
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
883
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 884
        For any other status, it returns false.
885
        Throws an exception if the order with the given id couldn't be found.
104 ashish 886
 
887
        Parameters:
2536 chandransh 888
         - orderId
104 ashish 889
        """
2536 chandransh 890
        try:
4579 rajveer 891
            return request_pickup_number(orderId, providerId)
2536 chandransh 892
        finally:
893
            close_session()
483 rajveer 894
 
4602 rajveer 895
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 896
        """
4452 rajveer 897
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 898
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
899
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
900
            3. Returns true
901
        If the order is any other status, it returns false.
902
        Throws an exception if the order with the given id couldn't be found.
304 ashish 903
 
904
        Parameters:
2536 chandransh 905
         - orderId
906
         - pickupNumber
304 ashish 907
        """
2536 chandransh 908
        try:
4602 rajveer 909
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 910
        finally:
911
            close_session()    
2764 chandransh 912
 
913
    def markDoasAsPickedUp(self, providerId, pickupDetails):
914
        """
915
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
916
 
917
        Parameters:
918
         - providerId
919
         - pickupDetails
920
        """
921
        try:
4910 phani.kuma 922
            mark_doas_as_picked_up(providerId, pickupDetails)
923
        finally:
924
            close_session()
925
 
926
    def getDoasNotPickedUp(self, providerId):
927
        """
928
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
929
 
930
        Parameters:
931
         - providerId
932
        """
933
        try:
934
            orders_not_picked_up = get_doas_not_picked_up(providerId)
2764 chandransh 935
            return [to_t_order(order) for order in orders_not_picked_up]
936
        finally:
937
            close_session()
4910 phani.kuma 938
 
4741 phani.kuma 939
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
940
        """
941
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
942
 
943
        Parameters:
944
         - providerId
945
         - pickupDetails
946
        """
947
        try:
4910 phani.kuma 948
            mark_return_orders_as_picked_up(providerId, pickupDetails)
949
        finally:
950
            close_session()
951
 
952
    def getReturnOrdersNotPickedUp(self, providerId):
953
        """
954
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
955
 
956
        Parameters:
957
         - providerId
958
        """
959
        try:
960
            orders_not_picked_up = get_return_orders_not_picked_up(providerId)
4741 phani.kuma 961
            return [to_t_order(order) for order in orders_not_picked_up]
962
        finally:
963
            close_session()
4910 phani.kuma 964
 
4479 rajveer 965
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 966
        """
4452 rajveer 967
        If the order status is DOA_PICKUP_CONFIRMED or DOA_RETURN_IN_TRANSIT, marks the order status as DOA_RECEIVED_PRESTINE and returns true.
2591 chandransh 968
        If the order is in any other state, it returns false.
969
        Throws an exception if the order with the given id couldn't be found.
970
 
971
        Parameters:
972
         - orderId
973
        """
974
        try:
4479 rajveer 975
            return receive_return(orderId, receiveCondition)
2591 chandransh 976
        finally:
977
            close_session()
978
 
979
    def validateDoa(self, orderId, isValid):
980
        """
4452 rajveer 981
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 982
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 983
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
984
        If the order is in any other state, it returns false.
985
        Throws an exception if the order with the given id couldn't be found.
986
 
987
        Parameters:
988
         - orderId
989
         - isValid
990
        """
991
        try:
992
            return validate_doa(orderId, isValid)
993
        finally:
994
            close_session()
2628 chandransh 995
 
4495 rajveer 996
    def validateReturnProduct(self, orderId, isUsable):
997
        """
998
        Parameters:
999
         - orderId
1000
         - isUsable
1001
        """
1002
        try:
1003
            return validate_return_product(orderId, isUsable)
1004
        finally:
1005
            close_session()
1006
 
2628 chandransh 1007
    def reshipOrder(self, orderId):
1008
        """
4484 rajveer 1009
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1010
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 1011
            2. Marks the current order as one of the final states RTO_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
2628 chandransh 1012
 
1013
        If the order is in DOA_CERT_VALID state, it does the following:
1014
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1015
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 1016
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 1017
 
1018
        Returns the id of the newly created order.
1019
 
1020
        Throws an exception if the order with the given id couldn't be found.
1021
 
1022
        Parameters:
1023
         - orderId
1024
        """
1025
        try:
1026
            return reship_order(orderId)
1027
        finally:
1028
            close_session()
1029
 
3226 chandransh 1030
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 1031
        """
4484 rajveer 1032
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1033
            1. Creates a refund request for batch processing.
1034
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 1035
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 1036
 
1037
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1038
            1. Creates a refund request for batch processing.
3226 chandransh 1039
            2. Cancels the reservation of the item in the warehouse.
1040
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 1041
 
3226 chandransh 1042
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1043
            1. Cancels the reservation of the item in the warehouse.
1044
            2. Marks the current order as CANCELED.
1045
 
1046
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
1047
 
2628 chandransh 1048
        Returns True if it is successful, False otherwise.
1049
 
1050
        Throws an exception if the order with the given id couldn't be found.
1051
 
1052
        Parameters:
1053
         - orderId
3226 chandransh 1054
         - refundedBy
1055
         - reason
2628 chandransh 1056
        """
1057
        try:
3226 chandransh 1058
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 1059
        finally:
1060
            close_session()
1061
 
2697 chandransh 1062
    def getReturnOrders(self, warehouseId, fromDate, toDate):
1063
        """
1064
        Get all return orders created between the from and to dates for the given warehouse.
1065
        Ignores the warehouse if it is passed as -1.
1066
 
1067
        Parameters:
1068
         - warehouseId
1069
         - fromDate
1070
         - toDate
1071
        """
1072
        try:
1073
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1074
            return get_return_orders(warehouseId, from_date, to_date)
1075
        finally:
1076
            close_session()
1077
 
5481 phani.kuma 1078
    def getAllReturnOrders(self, onlyNotProcessed, fromDate, toDate):
1079
        """
1080
        Get all return orders created between the from and to dates for the given warehouse.
1081
        Ignores the warehouse if it is passed as -1.
1082
 
1083
        Parameters:
1084
         - warehouseId
1085
         - fromDate
1086
         - toDate
1087
        """
1088
        try:
1089
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1090
            return get_all_return_orders(onlyNotProcessed, from_date, to_date)
1091
        finally:
1092
            close_session()
1093
 
2700 chandransh 1094
    def getReturnOrder(self, id):
1095
        """
1096
        Returns the ReturnOrder corresponding to the given id.
1097
        Throws an exception if the return order with the given id couldn't be found.
1098
 
1099
        Parameters:
1100
         - id
1101
        """
1102
        try:
1103
            return get_return_order(id)
1104
        finally:
1105
            close_session()
1106
 
2697 chandransh 1107
    def processReturn(self, returnOrderId):
1108
        """
1109
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
1110
 
1111
        Parameters:
1112
         - returnOrderId
1113
        """
1114
        try:
1115
            process_return(returnOrderId)
1116
        finally:
1117
            close_session()
4757 mandeep.dh 1118
 
1119
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 1120
        """
4757 mandeep.dh 1121
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
1122
        the quantities for which the PO is raised.
1123
 
2819 chandransh 1124
        Parameters:
4757 mandeep.dh 1125
         - itemIdQuantityMap
1126
         - purchaseOrderId
2819 chandransh 1127
         - warehouseId
1128
        """
1129
        try:
4757 mandeep.dh 1130
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 1131
        finally:
1132
            close_session()
4757 mandeep.dh 1133
 
3451 chandransh 1134
    def updateWeight(self, orderId, weight):
1135
        """
1136
        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.
1137
 
1138
        Parameters:
1139
         - orderId
1140
         - weight
1141
        """
1142
        try:
1143
            order = update_weight(orderId, weight)
1144
            return to_t_order(order)
1145
        finally:
1146
            close_session()
1147
 
3469 chandransh 1148
    def changeItem(self, orderId, itemId):
1149
        """
1150
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
1151
        Currently, it also ensures that only a different color of the given item is shipped.
1152
 
1153
        Parameters:
1154
         - orderId
1155
         - itemId
1156
        """
1157
        try:
1158
            order = change_product(orderId, itemId)
1159
            return to_t_order(order)
1160
        finally:
1161
            close_session()
1162
 
1163
    def shiftToWarehouse(self, orderId, warehouseId):
1164
        """
1165
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
1166
 
1167
        Parameters:
1168
         - orderId
1169
         - warehouseId
1170
        """
1171
        try:
1172
            order = change_warehouse(orderId, warehouseId)
1173
            return to_t_order(order)
1174
        finally:
1175
            close_session()
3553 chandransh 1176
 
4647 rajveer 1177
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 1178
        """
1179
        Adds the given delay reason to the given order.
3986 chandransh 1180
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 1181
        Raises an exception if no order with the given id can be found.
3469 chandransh 1182
 
3553 chandransh 1183
        Parameters:
1184
         - orderId
1185
         - delayReason
1186
        """
1187
        try:
4647 rajveer 1188
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 1189
        finally:
1190
            close_session()
1191
 
3956 chandransh 1192
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
1193
        """
1194
        Marks the COD orders with given AWB nos. as having been processed.
1195
        Updates the captured amount for the corresponding payment.
1196
 
1197
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
1198
        1. There is no order corresponding to an AWB number.
1199
        2. The captured amount for a payment exceeds the total payment.
1200
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
1201
 
1202
        Parameters:
1203
         - collectedAmountMap
1204
         - xferBy
1205
         - xferTxnId
1206
         - xferDate
1207
        """
1208
        try:
1209
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
1210
        finally:
1211
            close_session()
4008 mandeep.dh 1212
 
1213
    def getTransactionsRequiringExtraProcessing(self, category):
1214
        """
1215
        Returns the list of transactions that require some extra processing and
1216
        which belong to a particular category. This is currently used by CRM
1217
        application.
1218
        """
1219
        try:
1220
            return get_transactions_requiring_extra_processing(category)
1221
        finally:
1222
            close_session()
1223
 
1224
    def markTransactionAsProcessed(self, transactionId, category):
1225
        """
1226
        Marks a particular transaction as processed for a particular category.
1227
        It essentially deletes the transaction if it is processed for a particular
1228
        category. This is currently used by CRM application.
1229
        """
1230
        try:
1231
            return mark_transaction_as_processed(transactionId, category)
1232
        finally:
1233
            close_session()
4018 chandransh 1234
 
1235
    def getItemWiseRiskyOrdersCount(self, ):
1236
        """
1237
        Returns a map containing the number of risky orders keyed by item id. A risky order
1238
        is defined as one whose shipping date is about to expire.
1239
        """
1240
        try:
1241
            return get_item_wise_risky_orders_count()
1242
        finally:
1243
            close_session()
3956 chandransh 1244
 
4247 rajveer 1245
    def markOrderCancellationRequestReceived(self, orderId):
1246
        """
1247
        Mark order as cancellation request received. If customer sends request of cancellation of
1248
        a particular order, this method will be called. It will just change status of the order
1249
        depending on its current status. It also records the previous status, so that we can move
1250
        back to that status if cancellation request is denied.
1251
 
1252
        Parameters:
1253
         - orderId
1254
        """
1255
        try:
1256
            return mark_order_cancellation_request_received(orderId)
1257
        finally:
1258
            close_session()
1259
 
1260
 
4662 rajveer 1261
    def markOrderAsLostInTransit(self, orderId):
1262
        """
1263
        Parameters:
1264
         - orderId
1265
        """
1266
        try:
1267
            return mark_order_as_lost_in_transit(orderId)
1268
        finally:
1269
            close_session()
1270
 
4258 rajveer 1271
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1272
        """
4258 rajveer 1273
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1274
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1275
 
1276
        Parameters:
4258 rajveer 1277
         - transactionId
4247 rajveer 1278
        """
1279
        try:
4259 anupam.sin 1280
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1281
        finally:
1282
            close_session()
4259 anupam.sin 1283
 
1284
    def refundTransaction(self, transactionId, refundedBy, reason):
1285
        """
1286
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1287
        need to be cancelled
1288
 
1289
        Parameters:
1290
         - transactionId
1291
        """
1292
        try:
1293
            return refund_transaction(transactionId, refundedBy, reason)
1294
        finally:
1295
            close_session()
4247 rajveer 1296
 
1297
    def markOrderCancellationRequestDenied(self, orderId):
1298
        """
1299
        If we decide to not to cancel order, we will move the order ro previous status.
1300
 
1301
        Parameters:
1302
         - orderId
1303
        """
1304
        try:
1305
            return mark_order_cancellation_request_denied(orderId)
1306
        finally:
1307
            close_session()
1308
 
1309
    def markOrderCancellationRequestConfirmed(self, orderId):
1310
        """
1311
        If we decide to to cancel order, CRM will call this method to move the status of order to
1312
        cancellation request confirmed. After this OM will be able to cancel the order.
1313
 
1314
        Parameters:
1315
         - orderId
1316
        """
1317
        try:
1318
            return mark_order_cancellation_request_confirmed(orderId)
1319
        finally:
1320
            close_session()
1321
 
4324 mandeep.dh 1322
    def updateShipmentAddress(self, orderId, addressId):
1323
        """
1324
        Updates shipment address of an order. Delivery and shipping date estimates
1325
        etc. are also updated here.
1326
 
1327
        Throws TransactionServiceException in case address change is not
1328
        possible due to certain reasons such as new pincode in address is
1329
        not serviceable etc.
1330
 
1331
        Parameters:
1332
         - orderId
1333
         - addressId
1334
        """
1335
        try:
1336
            update_shipment_address(orderId, addressId)
1337
        finally:
1338
            close_session()
1339
 
4285 rajveer 1340
    def acceptOrdersForItemId(self, itemId, inventory):
1341
        """
1342
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1343
        given order is not a COD order, it also captures the payment if the same has not been captured.
1344
 
1345
        Parameters:
1346
         - itemId
1347
         - inventory
1348
        """
1349
        try:
1350
            return accept_orders_for_item_id(itemId, inventory)
1351
        finally:
1352
            close_session()
1353
 
4303 rajveer 1354
 
1355
 
4369 rajveer 1356
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1357
        """
1358
        Parameters:
1359
         - vendorId
1360
         - itemId
1361
         - quantity
1362
         - estimate
4369 rajveer 1363
         - isReminder
4303 rajveer 1364
        """
1365
        try:
4369 rajveer 1366
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1367
        finally:
1368
            close_session()
1369
 
4369 rajveer 1370
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1371
        """
1372
        Parameters:
1373
         - vendorId
1374
         - itemId
1375
         - quantity
1376
         - estimate
4369 rajveer 1377
         - isReminder
4303 rajveer 1378
        """
1379
        try:
4369 rajveer 1380
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1381
        finally:
1382
            close_session()
1383
 
4369 rajveer 1384
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1385
        """
1386
        Parameters:
1387
         - vendorId
1388
         - itemId
1389
         - quantity
1390
         - estimate
4369 rajveer 1391
         - isReminder
4303 rajveer 1392
        """
1393
        try:
4369 rajveer 1394
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1395
        finally:
1396
            close_session()
1397
 
1398
 
4369 rajveer 1399
    def markOrdersAsTimeout(self, vendorId):
1400
        """
1401
        Parameters:
1402
         - vendorId
1403
        """
1404
        try:
1405
            return mark_orders_as_timeout(vendorId)
1406
        finally:
1407
            close_session()
4386 anupam.sin 1408
 
1409
    def getOrderForAwb(self, awb):
1410
        """
1411
        Parameters:
1412
         - AirwayBill Number
1413
        """
1414
        try:
1415
            return to_t_order(get_order_for_awb(awb))
1416
        finally:
1417
            close_session()
4369 rajveer 1418
 
4910 phani.kuma 1419
    def getOrdersForProviderForStatus(self, provider_id, order_status_list):
4506 phani.kuma 1420
        """
1421
        Parameters:
1422
         - provider id
1423
         - order status
1424
        """
1425
        try:
4910 phani.kuma 1426
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status_list)
4506 phani.kuma 1427
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1428
        finally:
1429
            close_session()
4600 varun.gupt 1430
 
1431
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1432
        '''
1433
        Parameters:
1434
         - vendorId
1435
         - billingDateFrom
1436
         - billingDateTo
1437
        '''
1438
        try:
1439
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1440
        finally:
1441
            close_session()
1442
 
4607 rajveer 1443
    def getSlippedSippingDateOrders(self):
1444
        try:
1445
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1446
        finally:
1447
            close_session()
1448
 
4709 rajveer 1449
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1450
        try:
1451
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1452
        finally:
1453
            close_session()
1454
 
4600 varun.gupt 1455
    def getEBSSettlementSummaries(self):
1456
        try:
1457
            return get_ebs_settlement_summaries()
1458
        finally:
1459
            close_session()
4369 rajveer 1460
 
4600 varun.gupt 1461
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1462
        try:
1463
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1464
        finally:
1465
            close_session()
1466
 
5386 phani.kuma 1467
    def getSettlementForPrepaid(self, referenceId, isRefund):
4600 varun.gupt 1468
        '''
1469
        Parameters:
5189 varun.gupt 1470
         - referenceId
1471
         - isRefund
4600 varun.gupt 1472
        '''
1473
        try:
5386 phani.kuma 1474
            return to_t_payment_settlement(get_settlement_for_Prepaid(referenceId, isRefund))
4600 varun.gupt 1475
        finally:
1476
            close_session()
5386 phani.kuma 1477
 
1478
    def getSettlementForCod(self, orderId, isRefund):
1479
        '''
1480
        Parameters:
1481
         - orderId
1482
         - isRefund
1483
        '''
1484
        try:
1485
            return to_t_payment_settlement(get_settlement_for_Cod(orderId, isRefund))
1486
        finally:
1487
            close_session()
1488
 
4600 varun.gupt 1489
    def getEBSSettlementDate(self, settlementId):
1490
        try:
1491
            return to_java_date(get_ebs_settlement_date(settlementId))
1492
        finally:
1493
            close_session()
1494
 
4905 varun.gupt 1495
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection):
4600 varun.gupt 1496
        try:
4905 varun.gupt 1497
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection)
4600 varun.gupt 1498
        finally:
1499
            close_session()
1500
 
1501
    def markEBSSettlementUploaded(self, settlementId):
1502
        try:
1503
            mark_ebs_settlement_uploaded(settlementId)
1504
        finally:
1505
            close_session()
1506
 
4715 varun.gupt 1507
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1508
        try:
1509
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1510
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1511
        finally:
1512
            close_session()
1513
 
1514
    def getReshippedOrderIds(self, orderIds):
1515
        try:
1516
            return get_reshipped_order_ids(orderIds)
1517
        finally:
1518
            close_session()
1519
 
5481 phani.kuma 1520
    def getBilledOrders(self, vendorId, onlyVendorNotPaid, billingDateFrom, billingDateTo):
4875 varun.gupt 1521
        try:
5481 phani.kuma 1522
            from_date, to_date = get_fdate_tdate(billingDateFrom, billingDateTo)
1523
            return [to_t_order(order) for order in get_billed_orders(vendorId, onlyVendorNotPaid, from_date, to_date)]
4875 varun.gupt 1524
        finally:
1525
            close_session()
1526
 
5062 varun.gupt 1527
    def getStatusDistributionOfOrders(self, startDate, endDate):
1528
        try:
5067 varun.gupt 1529
            distribution = {}
1530
 
1531
            for status, count in get_order_distribution_by_status(to_py_date(startDate), to_py_date(endDate)):
1532
                distribution[status] = count
1533
 
1534
            return distribution
5062 varun.gupt 1535
        finally:
1536
            close_session()
1537
 
5067 varun.gupt 1538
    def getOrderIdsForStatus(self, status, startDatetime, endDatetime):
1539
        try:
1540
            orders = get_order_ids_for_status(status, to_py_date(startDatetime), to_py_date(endDatetime))
1541
            return [order.id for order in orders]
1542
        finally:
1543
            close_session()
1544
 
5099 varun.gupt 1545
    def updateOrderAsPaidToVendor(self, orderId):
1546
        try:
1547
            update_orders_as_paid_to_vendor(orderId)
1548
        finally:
1549
            close_session()
1550
 
5348 anupam.sin 1551
    def updateCODAgent(self, agentEmailId, orderId):
1552
        try:
1553
            update_COD_agent(agentEmailId, orderId)
1554
        finally:
1555
            close_session()
1556
 
5386 phani.kuma 1557
    def updateOrderOnlyAsPaidToVendor(self, orderId):
1558
        try:
1559
            update_order_only_as_paid_to_vendor(orderId)
1560
        finally:
1561
            close_session()
1562
 
5208 varun.gupt 1563
    def getRefundedOrdersMarkedPaid(self):
1564
        try:
1565
            return [to_t_order(order) for order in get_refunded_orders_marked_paid()]
1566
        finally:
1567
            close_session()
5447 anupam.sin 1568
 
1569
    def getAllVerificationAgents(self, minOrderId, maxOrderId):
1570
        try:
1571
            return [to_t_verification_agent(codAgent) for codAgent in get_all_verification_agents(minOrderId, maxOrderId)]
1572
        finally:
5527 anupam.sin 1573
            close_session()
1574
 
1575
    def getAllAttributesForOrderId(self, orderId):
1576
        try:
1577
            return [to_t_attribute(attribute) for attribute in get_all_attributes_for_order_id(orderId)]
1578
        finally:
1579
            close_session()
1580
 
1581
    def setOrderAttributeForTransaction(self, transactionId, attribute):
1582
        try:
1583
            set_order_attribute_for_transaction(transactionId, attribute)                    
1584
        finally:
1585
            close_session()
5593 mandeep.dh 1586
 
1587
    def acceptOrderForItem(self, itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
1588
        """
1589
        Accepts appropriate order for an item in a given billingWarehouse. Usually
1590
        invoked while scanning IN of items.
1591
 
1592
        Parameters:
1593
         - itemId
1594
         - quantity
1595
         - fulfilmentWarehouseId
1596
         - billingWarehouseId
1597
        """
1598
        try:
1599
            accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId)
1600
        finally:
1601
            close_session()
1602
 
5833 rajveer 1603
    def getOrderAttributeValue(self, orderId, attributeName):
1604
        """
1605
        Parameters:
1606
         - orderId
1607
         - attributeName
1608
        """
1609
        try:
1610
            get_order_attribute_value(orderId, attributeName)
1611
        finally:
1612
            close_session()
1613
 
2536 chandransh 1614
    def closeSession(self, ):
1615
        close_session()
3376 rajveer 1616
 
1617
    def isAlive(self, ):
1618
        """
5447 anupam.sin 1619
        For checking whether service is alive or not. It also checks connectivity with database
3376 rajveer 1620
        """
1621
        try:
1622
            return is_alive()
1623
        finally:
4247 rajveer 1624
            close_session()