Subversion Repositories SmartDukaan

Rev

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