Subversion Repositories SmartDukaan

Rev

Rev 5527 | Rev 5593 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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