Subversion Repositories SmartDukaan

Rev

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

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