Subversion Repositories SmartDukaan

Rev

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