Subversion Repositories SmartDukaan

Rev

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