Subversion Repositories SmartDukaan

Rev

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