Subversion Repositories SmartDukaan

Rev

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