Subversion Repositories SmartDukaan

Rev

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