Subversion Repositories SmartDukaan

Rev

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