Subversion Repositories SmartDukaan

Rev

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