Subversion Repositories SmartDukaan

Rev

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