Subversion Repositories SmartDukaan

Rev

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