Subversion Repositories SmartDukaan

Rev

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