Subversion Repositories SmartDukaan

Rev

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