Subversion Repositories SmartDukaan

Rev

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

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