Subversion Repositories SmartDukaan

Rev

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