Subversion Repositories SmartDukaan

Rev

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