Subversion Repositories SmartDukaan

Rev

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