Subversion Repositories SmartDukaan

Rev

Rev 12589 | Rev 12653 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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