Subversion Repositories SmartDukaan

Rev

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