Subversion Repositories SmartDukaan

Rev

Rev 19421 | Rev 19691 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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