Subversion Repositories SmartDukaan

Rev

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