Subversion Repositories SmartDukaan

Rev

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