Subversion Repositories SmartDukaan

Rev

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