Subversion Repositories SmartDukaan

Rev

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

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