Subversion Repositories SmartDukaan

Rev

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