Subversion Repositories SmartDukaan

Rev

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

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