Subversion Repositories SmartDukaan

Rev

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