Subversion Repositories SmartDukaan

Rev

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