Subversion Repositories SmartDukaan

Rev

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