Subversion Repositories SmartDukaan

Rev

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