Subversion Repositories SmartDukaan

Rev

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