Subversion Repositories SmartDukaan

Rev

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

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