Subversion Repositories SmartDukaan

Rev

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