Subversion Repositories SmartDukaan

Rev

Rev 6591 | Rev 6821 | 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
104 ashish 7
from shop2020.model.v1.order.impl import DataService
6000 mandeep.dh 8
from shop2020.model.v1.order.impl.Convertors import to_t_transaction, to_t_alert, \
9
    to_t_order, to_t_lineitem, to_t_payment_settlement, to_t_verification_agent, \
10
    to_t_attribute
11
from shop2020.model.v1.order.impl.DataAccessors import create_transaction, \
12
    get_transactions_for_customer, get_transaction_status, get_line_items_for_order, \
13
    get_transaction, get_transactions_for_shopping_cart_id, \
14
    change_transaction_status, get_orders_for_customer, get_orders_for_transaction, \
15
    get_order, get_returnable_orders_for_customer, \
16
    get_cancellable_orders_for_customer, get_orders_by_billing_date, get_all_orders, \
17
    change_order_status, get_alerts, add_alert, add_billing_details, close_session, \
18
    accept_order, mark_orders_as_picked_up, mark_orders_as_delivered, \
19
    mark_orders_as_rto, order_outofstock, batch_orders, update_non_delivery_reason, \
20
    enqueue_transaction_info_email, get_undelivered_orders, get_order_for_customer, \
21
    get_valid_order_count, get_cust_count_with_successful_txn, \
22
    get_valid_orders_amount_range, get_valid_orders, toggle_doa_flag, \
23
    request_pickup_number, authorize_pickup, receive_return, validate_doa, \
24
    reship_order, refund_order, get_return_orders, process_return, get_return_order, \
25
    mark_doas_as_picked_up, verify_order, is_alive, get_orders_by_shipping_date, \
26
    update_weight, change_warehouse, change_product, add_delay_reason, \
27
    reconcile_cod_collection, get_transactions_requiring_extra_processing, \
28
    mark_transaction_as_processed, get_item_wise_risky_orders_count, \
29
    accept_order_for_item, get_orders_in_batch, get_order_count, \
30
    get_ebs_settlement_summaries, mark_order_cancellation_request_received, \
31
    mark_order_cancellation_request_denied, refund_transaction, \
32
    mark_order_cancellation_request_confirmed, \
33
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id, \
34
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated, \
35
    mark_orders_as_not_available, update_shipment_address, mark_orders_as_timeout, \
36
    get_order_for_awb, mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
37
    mark_order_doa_request_received, mark_order_doa_request_authorized, \
38
    mark_order_return_request_received, mark_order_return_request_authorized, \
39
    add_invoice_number, get_reshipped_order_ids, validate_return_product, \
40
    get_orders_for_provider_for_status, save_ebs_settlement_summary, \
41
    get_ebs_settlement_date, save_payment_settlements, mark_ebs_settlement_uploaded, \
42
    get_billed_orders_for_vendor, get_settlement_for_Prepaid, \
43
    get_settlements_by_date, get_slipped_sipping_date_orders, \
44
    mark_order_as_lost_in_transit, get_cancelled_orders, mark_order_as_delivered, \
45
    mark_return_orders_as_picked_up, update_orders_as_PORaised, \
46
    get_order_distribution_by_status, get_orders_not_met_expected_delivery_date, \
47
    mark_orders_as_local_connected, mark_orders_as_destinationCityReached, \
48
    mark_orders_as_firstDeliveryAttempted, get_non_delivered_orders_by_courier, \
49
    get_orders_not_local_connected, get_doas_not_picked_up, \
50
    get_return_orders_not_picked_up, get_orders_not_picked_up, get_rto_orders, \
51
    get_order_list, get_order_ids_for_status, update_orders_as_paid_to_vendor, \
52
    update_COD_agent, get_refunded_orders_marked_paid, get_settlement_for_Cod, \
53
    get_order_list_for_vendor, update_order_only_as_paid_to_vendor, \
54
    get_all_verification_agents, get_all_attributes_for_order_id, \
55
    set_order_attribute_for_transaction, get_billed_orders, get_all_return_orders, \
56
    mark_order_as_received_at_store, get_receive_pending_orders, \
57
    get_received_at_store_orders, mark_orders_as_returned_from_store, \
6056 amit.gupta 58
    set_order_attributes, get_orders_collection_at_store, get_order_attribute_value, \
59
    change_jacket_number, mark_order_as_rto_in_transit, get_recharge_order, \
60
    get_recharge_orders, update_recharge_order_status, activate_recharge_txn, \
61
    get_user_wallet, get_user_wallet_history, get_service_providers, \
6396 amit.gupta 62
    get_service_provider_for_device, get_recharge_orders_for_transaction, \
63
    update_amount_in_wallet, get_recharge_orders_for_device, \
64
    get_recharge_orders_for_status, get_plans_for_operator, get_recharge_statistics, \
65
    validate_recharge, get_recharge_denominations, update_availability_status, \
6507 anupam.sin 66
    get_misc_charges, get_available_emi_schemes, refund_recharge_order
6000 mandeep.dh 67
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
6056 amit.gupta 68
from shop2020.model.v1.order.impl.model.DigitalTransaction import \
69
    DigitalTransaction
6000 mandeep.dh 70
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
71
    MobileRechargeOrder
72
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
73
    RechargeType
74
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
6031 rajveer 75
import datetime
1405 ankur.sing 76
 
5527 anupam.sin 77
 
104 ashish 78
 
79
class OrderServiceHandler:
80
 
3187 rajveer 81
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 82
        """
104 ashish 83
        Constructor
483 rajveer 84
        """
3187 rajveer 85
        DataService.initialize(dbname, db_hostname)
104 ashish 86
 
87
    def createTransaction(self, transaction):
88
        """
89
        Parameters:
90
         - transaction
91
        """
766 rajveer 92
        try:
93
            return create_transaction(transaction)
94
        finally:
95
            close_session()
96
 
104 ashish 97
    def getTransaction(self, id):
98
        """
99
            Get transaction methods.
100
 
101
        Parameters:
102
         - id
103
        """
766 rajveer 104
        try:
105
            transaction = get_transaction(id)
106
            return to_t_transaction(transaction)
107
        finally:
108
            close_session()
109
 
483 rajveer 110
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 111
        """
112
        Parameters:
483 rajveer 113
         - customerId
104 ashish 114
         - from_date
115
         - to_date
483 rajveer 116
         - status
104 ashish 117
        """
766 rajveer 118
        try:
119
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
120
 
121
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
122
            t_transaction = []
123
            for transaction in transactions:
124
                t_transaction.append(to_t_transaction(transaction))
125
            return t_transaction
126
        finally:
127
            close_session()
483 rajveer 128
 
129
    def getTransactionsForShoppingCartId(self, shoppingCartId):
130
        """
131
        Parameters:
132
            - shoppingCartId
133
        """
766 rajveer 134
        try:
135
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
136
            t_transaction = []
137
            for transaction in transactions:
138
                t_transaction.append(to_t_transaction(transaction))
139
            return t_transaction
140
        finally:
141
            close_session()
104 ashish 142
 
483 rajveer 143
    def getTransactionStatus(self, transactionId):
104 ashish 144
        """
145
        Parameters:
483 rajveer 146
         - transactionId
147
        """
766 rajveer 148
        try:
149
            return get_transaction_status(transactionId)
150
        finally:
151
            close_session()
152
 
5527 anupam.sin 153
    def changeTransactionStatus(self, transactionId, status, description, pickUp, orderType):
483 rajveer 154
        """
155
        Parameters:
156
         - transactionId
104 ashish 157
         - status
483 rajveer 158
         - description
5387 rajveer 159
         - selfPickup
483 rajveer 160
        """
766 rajveer 161
        try:
5527 anupam.sin 162
            return change_transaction_status(transactionId, status, description, pickUp, orderType)
766 rajveer 163
        finally:
164
            close_session()
165
 
1528 ankur.sing 166
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 167
        """
1528 ankur.sing 168
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
169
        only user who owns the transaction can view its order details.
170
 
483 rajveer 171
        Parameters:
172
         - transactionId
1528 ankur.sing 173
         - customerId
483 rajveer 174
        """
766 rajveer 175
        try:
1528 ankur.sing 176
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 177
            return [to_t_order(order) for order in orders]    
178
        finally:
179
            close_session()
180
 
4801 anupam.sin 181
    def getAllOrders(self, statuses, from_date, to_date, warehouse_id):
483 rajveer 182
        """
183
        Parameters:
184
         - status
104 ashish 185
         - from_date
186
         - to_date
483 rajveer 187
         - warehouse_id
104 ashish 188
        """
766 rajveer 189
        try:
190
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
4801 anupam.sin 191
            orders = get_all_orders(statuses, current_from_date, current_to_date, warehouse_id)
766 rajveer 192
            return [to_t_order(order) for order in orders]
193
        finally:
194
            close_session()
4133 chandransh 195
 
196
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id):
197
        """
198
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
199
        Pass the status as null and the limit as 0 to ignore them.
200
 
201
        Parameters:
202
         - statuses
203
         - offset
204
         - limit
205
         - warehouse_id
206
        """
207
        try:
208
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id)
209
            return [to_t_order(order) for order in orders]
210
        finally:
211
            close_session()
212
 
213
    def getOrderCount(self, statuses, warehouseId):
214
        """
215
        Returns the count of orders with the given statuses assigned to the given warehouse.
216
 
217
        Parameters:
218
         - statuses
219
         - warehouseId
220
        """
221
        try:
222
            return get_order_count(statuses, warehouseId)
223
        finally:
224
            close_session()
225
 
995 varun.gupt 226
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
227
        """
228
        Parameters:
229
         - status
230
         - start_billing_date
231
         - end_billing_date
232
         - warehouse_id
233
        """
234
        try:
235
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
236
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
237
            return [to_t_order(order) for order in orders]
238
        finally:
239
            close_session()
1382 varun.gupt 240
 
3451 chandransh 241
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 242
        """
243
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 244
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
245
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 246
 
247
        Parameters:
248
         - fromShippingDate
249
         - toShippingDate
250
         - providerId
251
         - warehouseId
3451 chandransh 252
         - cod
3427 chandransh 253
        """
254
        try:
255
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 256
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 257
            return [to_t_order(order) for order in orders]
258
        finally:
259
            close_session()
260
 
1382 varun.gupt 261
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
262
        """
263
        Parameters:
264
         - customerId
265
         - limit
266
        """
267
        try:
268
            return get_returnable_orders_for_customer(customerId, limit)
269
        finally:
270
            close_session()
995 varun.gupt 271
 
1382 varun.gupt 272
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
273
        """
274
        Parameters:
275
         - customerId
276
         - limit
277
        """
278
        try:
279
            return get_cancellable_orders_for_customer(customerId, limit)
280
        finally:
281
            close_session()
282
 
483 rajveer 283
    def changeOrderStatus(self, orderId, status, description):
284
        """
285
        Parameters:
286
         - orderId
287
         - status
288
         - description
289
         - 
290
        """
766 rajveer 291
        try:
292
            return change_order_status(self, orderId, status, description)
293
        finally:
294
            close_session()
921 rajveer 295
 
3064 chandransh 296
    def verifyOrder(self, orderId):
297
        """
298
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
299
        timestamp. It is intended to be used for COD orders but can be harmlessly
300
        used for all other orders as well.
301
        Throws an exception if no such order exists.
302
 
303
        Parameters:
304
         - orderId
305
        """
306
        try:
307
            return verify_order(self, orderId)
308
        finally:
309
            close_session()
310
 
921 rajveer 311
    def acceptOrder(self, orderId):
312
        """
3064 chandransh 313
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
314
        given order is not a COD order, it also captures the payment if the same has
315
        not been captured.
316
        Throws an exception if no such order exists.
317
 
921 rajveer 318
        Parameters:
319
         - orderId
320
        """
321
        try:
4285 rajveer 322
            return accept_order(orderId)
921 rajveer 323
        finally:
324
            close_session()
325
 
3014 chandransh 326
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 327
        """
3014 chandransh 328
        Returns list of orders for the given customer created between the given dates and having the given statuses.
329
        Pass and empty list to ignore filtering on statuses.
330
 
104 ashish 331
        Parameters:
332
         - customerId
333
         - from_date
334
         - to_date
3014 chandransh 335
         - statuses
104 ashish 336
        """
766 rajveer 337
        try:
338
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
339
 
3014 chandransh 340
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 341
            return [to_t_order(order) for order in orders]
342
        finally:
343
            close_session()
1528 ankur.sing 344
 
345
    def getOrderForCustomer(self, orderId, customerId):
346
        """
347
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
348
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
349
 
350
        Parameters:
351
         - customerId
352
         - orderId
353
        """
354
        try:
355
            return to_t_order(get_order_for_customer(orderId, customerId))
356
        finally:
357
            close_session()
766 rajveer 358
 
483 rajveer 359
    def getOrder(self, id):
360
        """
361
        Parameters:
362
         - id
363
        """
766 rajveer 364
        try:
365
            return to_t_order(get_order(id))
366
        finally:
367
            close_session()
4999 phani.kuma 368
 
369
    def getOrderList(self, order_ids):
370
        """
371
        Parameters:
372
         - order_ids
373
        """
374
        try:
375
            orders = get_order_list(order_ids)
376
            return [to_t_order(order) for order in orders]
377
        finally:
378
            close_session()
379
 
5386 phani.kuma 380
    def getOrderListForVendor(self, order_ids, vendorId):
381
        """
382
        Parameters:
383
         - order_ids
384
         - vendorId
385
        """
386
        try:
387
            orders = get_order_list_for_vendor(order_ids, vendorId)
388
            return [to_t_order(order) for order in orders]
389
        finally:
390
            close_session()
391
 
483 rajveer 392
    def getLineItemsForOrder(self, orderId):
393
        """
394
        Parameters:
395
         - orderId
396
        """
766 rajveer 397
        try:
398
            lineitems = get_line_items_for_order(orderId)
399
            t_lineitems = []
400
            for lineitem in lineitems:
401
                t_lineitems.append(to_t_lineitem(lineitem))
402
            return t_lineitems
403
        finally:
404
            close_session()
1149 chandransh 405
 
4763 rajveer 406
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 407
        """
4658 mandeep.dh 408
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 409
        Also marks the order as billed and sets the billing timestamp.
410
        Return false if it doesn't find the order with the given ID.
1149 chandransh 411
 
412
        Parameters:
413
         - orderId
414
         - jacketNumber
4658 mandeep.dh 415
         - serialNumber
2783 chandransh 416
         - itemNumber
417
         - billedBy
1149 chandransh 418
        """
419
        try:
4763 rajveer 420
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 421
        finally:
422
            close_session()
1220 chandransh 423
 
6751 amar.kumar 424
    def addInvoiceNumber(self, orderId, invoiceNumber, color, serialNumber, itemNumber):
4579 rajveer 425
        """
426
        Add the invoice number to the order.
427
 
428
        Parameters:
429
         - orderId
430
         - invoice_number
431
        """
432
        try:
6751 amar.kumar 433
            add_invoice_number(orderId, invoiceNumber, color, serialNumber, itemNumber)
4579 rajveer 434
        finally:
435
            close_session()
436
 
1220 chandransh 437
    def batchOrders(self, warehouseId):
438
        """
439
        Create a batch of all the pending orders for the given warehouse.
440
        The returned list is orderd by created_timestamp.
441
        If there are no pending orders, an empty list is returned.
1208 chandransh 442
 
1220 chandransh 443
        Parameters:
444
         - warehouseId
445
        """
446
        try:
447
            pending_orders = batch_orders(warehouseId)
448
            return [to_t_order(order) for order in pending_orders]
449
        finally:
450
            close_session()
451
 
1208 chandransh 452
    def markOrderAsOutOfStock(self, orderId):
453
        """
454
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
455
 
456
 
457
        Parameters:
458
         - orderId
459
        """
460
        try:
461
            return order_outofstock(orderId)
462
        finally:
463
            close_session()
464
 
4910 phani.kuma 465
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod, orderIds):
759 chandransh 466
        """
3064 chandransh 467
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4910 phani.kuma 468
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 469
 
470
        Parameters:
471
         - warehouseId
472
         - providerId
3064 chandransh 473
         - cod
759 chandransh 474
        """
766 rajveer 475
        try:
4910 phani.kuma 476
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds)
766 rajveer 477
        finally:
478
            close_session()
1113 chandransh 479
 
5713 rajveer 480
    def markOrdersAsReturnedFromStore(self, providerId, orderIds, awbs):
5676 rajveer 481
        """
482
        Parameters:
483
         - providerId
484
         - orderIds
5713 rajveer 485
         - awbs
5676 rajveer 486
        """
487
        try:
5713 rajveer 488
            return mark_orders_as_returned_from_store(providerId, orderIds, awbs)
5676 rajveer 489
        finally:
490
            close_session()
491
 
492
    def setOrderAttributes(self, orderId, attributes):
493
        """
494
        sets attributes for an order
495
 
496
        Parameters:
497
         - orderId
498
         - attributes
499
        """
500
        try:
501
            return set_order_attributes(orderId, attributes)
502
        finally:
503
            close_session()
504
 
505
 
4910 phani.kuma 506
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
4410 rajveer 507
        """
4910 phani.kuma 508
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
509
        Raises an exception if we encounter report for an AWB number that we did not ship.
4410 rajveer 510
 
511
        Parameters:
512
         - providerId
4910 phani.kuma 513
         - pickupDetails
4410 rajveer 514
        """
515
        try:
4910 phani.kuma 516
            mark_orders_as_picked_up(providerId, pickupDetails)
4410 rajveer 517
        finally:
518
            close_session()
519
 
4910 phani.kuma 520
    def getOrdersNotPickedUp(self, providerId):
1113 chandransh 521
        """
522
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
523
 
524
        Parameters:
525
         - providerId
526
        """
527
        try:
4910 phani.kuma 528
            orders_not_picked_up = get_orders_not_picked_up(providerId)
1113 chandransh 529
            return [to_t_order(order) for order in orders_not_picked_up]
530
        finally:
531
            close_session()
1132 chandransh 532
 
533
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
534
        """
535
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
536
        the name of the receiver.
537
        Raises an exception if we encounter report for an AWB number that we did not ship.
538
 
539
        Parameters:
540
         - providerId
541
         - deliveredOrders
542
        """
543
        try:
544
            mark_orders_as_delivered(providerId, deliveredOrders)
545
        finally:
546
            close_session()
1135 chandransh 547
 
4712 rajveer 548
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
549
        """
550
        Attributes:
551
         - orderId
552
         - deliveryTimestamp
553
         - receiver
554
        """
555
        try:
556
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
557
        finally:
558
            close_session()
559
 
560
 
5555 rajveer 561
    def markOrderAsReceivedAtStore(self, orderId, deliveryTimestamp):
562
        """
563
        Attributes:
564
         - orderId
565
         - deliveryTimestamp
566
        """
567
        try:
568
            mark_order_as_received_at_store(orderId, to_py_date(deliveryTimestamp))
569
        finally:
570
            close_session()
571
 
572
    def getReceivePendingOrders(self, storeId):
573
        """
574
        Attributes:
575
         - storeId
576
        """
577
        try:
578
            orders = get_receive_pending_orders(storeId)
579
            return [to_t_order(order) for order in orders]
580
        finally:
581
            close_session()
582
 
583
    def getReceivedAtStoreOrders(self, storeId):
584
        """
585
        Attributes:
586
         - storeId
587
        """
588
        try:
589
            orders = get_received_at_store_orders(storeId)
590
            return [to_t_order(order) for order in orders]
591
        finally:
592
            close_session()
5713 rajveer 593
 
594
    def getOrdersCollectionAtStore(self, storeId, fromDate, toDate, onlyCod):
595
        """
596
        Parameters:
597
         - storeId
598
         - fromDate
599
         - toDate
600
         - onlyCod
601
        """
602
        try:
603
            orders = get_orders_collection_at_store(storeId, to_py_date(fromDate), to_py_date(toDate), onlyCod)
604
            return [to_t_order(order) for order in orders]
605
        finally:
606
            close_session()
607
 
4910 phani.kuma 608
    def markAsRTOrders(self, providerId, returnedOrders):
1135 chandransh 609
        """
4910 phani.kuma 610
        Mark all orders with AWBs in the given map as RTO. Also sets the delivery timestamp.
1135 chandransh 611
        Raises an exception if we encounter report for an AWB number that we did not ship.
612
 
613
        Parameters:
614
         - providerId
615
         - returnedOrders
616
        """
617
        try:
4910 phani.kuma 618
            mark_orders_as_rto(providerId, returnedOrders)
1135 chandransh 619
        finally:
620
            close_session()
1246 chandransh 621
 
4910 phani.kuma 622
    def getRTOrders(self, providerId):
623
        """
624
        Returns a list of orders that were returned by courier.
625
 
626
        Parameters:
627
         - providerId
628
        """
629
        try:
630
            rto_orders = get_rto_orders(providerId)
631
            return [to_t_order(order) for order in rto_orders]
632
        finally:
633
            close_session()
634
 
1246 chandransh 635
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
636
        """
637
        Update the status description of orders whose AWB numbers are keys of the Map.
638
 
639
        Parameters:
640
         - providerId
641
         - undelivered_orders
642
        """
643
        try:
4910 phani.kuma 644
            update_non_delivery_reason(providerId, undeliveredOrders)
645
        finally:
646
            close_session()
647
 
648
    def getNonDeliveredOrdersbyCourier(self, providerId):
649
        """
650
        Returns a list of orders that were picked up or shipped four days ago but did not get delivered.
651
 
652
        Parameters:
653
         - providerId
654
        """
655
        try:
656
            orders_not_delivered = get_non_delivered_orders_by_courier(providerId)
4581 phani.kuma 657
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 658
        finally:
659
            close_session()
1405 ankur.sing 660
 
4910 phani.kuma 661
    def markOrdersAsLocalConnected(self, providerId, local_connected_orders):
662
        """
663
        Mark all orders with AWBs in the given map as local connected. Also sets the local connected timestamp.
664
 
665
        Parameters:
666
         - providerId
667
         - local_connected_orders
668
        """
669
        try:
670
            mark_orders_as_local_connected(providerId, local_connected_orders)
671
        finally:
672
            close_session()
673
 
674
    def getOrdersNotLocalConnected(self, providerId):
675
        """
676
        Returns a list of orders that were picked up or shipped but pending local connection.
677
 
678
        Parameters:
679
         - providerId
680
        """
681
        try:
682
            orders_pending_local_connection = get_orders_not_local_connected(providerId)
683
            return [to_t_order(order) for order in orders_pending_local_connection]
684
        finally:
685
            close_session()
686
 
687
    def markOrdersAsDestinationCityReached(self, providerId, destination_city_reached_orders):
688
        """
689
        Mark all orders with AWBs in the given map as reached destination city. Also sets the reached destination timestamp.
690
 
691
        Parameters:
692
         - providerId
693
         - destination_city_reached_orders
694
        """
695
        try:
696
            mark_orders_as_destinationCityReached(providerId, destination_city_reached_orders)
697
        finally:
698
            close_session()
699
 
700
    def markOrdersAsFirstDeliveryAttempted(self, providerId, first_atdl_orders):
701
        """
702
        Mark all orders with AWBs in the given map as first delivery attempt made. Also sets the first delivery attempted timestamp.
703
 
704
        Parameters:
705
         - providerId
706
         - first_atdl_orders
707
        """
708
        try:
709
            mark_orders_as_firstDeliveryAttempted(providerId, first_atdl_orders)
710
        finally:
711
            close_session()
712
 
4783 phani.kuma 713
    def getUndeliveredOrdersExpectedDeliveryDateNotMet(self):
714
        """
715
        Returns the list of orders whose expected delivery date has passed but have not been
716
        delivered yet.
717
        Returns an empty list if no such orders exist.
718
        """
719
        try:
720
            orders_not_delivered = get_orders_not_met_expected_delivery_date()
721
            return [to_t_order(order) for order in orders_not_delivered]
722
        finally:
723
            close_session()
724
 
1405 ankur.sing 725
    def getUndeliveredOrders(self, providerId, warehouseId):
726
        """
727
        Returns the list of orders whose delivery time has passed but have not been
728
        delivered yet for the given provider and warehouse. To get a complete list of
729
        undelivered orders, pass them as -1.
730
        Returns an empty list if no such orders exist.
731
 
732
        Parameters:
733
         - providerId
734
         - warehouseId
735
        """
736
        try:
737
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
738
            return [to_t_order(order) for order in undelivered_orders]
739
        finally:
740
            close_session()
1351 varun.gupt 741
 
1398 varun.gupt 742
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 743
        """
1398 varun.gupt 744
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 745
 
746
        Parameters:
747
         - transactionId
748
        """
749
        try:
1398 varun.gupt 750
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 751
        finally:
752
            close_session()
753
 
4444 rajveer 754
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 755
        """
756
        Parameters:
4394 rajveer 757
         - type
4444 rajveer 758
         - warehouseId
4394 rajveer 759
         - status
760
         - timestamp
483 rajveer 761
        """
766 rajveer 762
        try:
4444 rajveer 763
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 764
 
765
            t_alerts = []
766
            for alert in alerts:
767
                t_alerts.append(to_t_alert(alert)) 
768
 
769
            return t_alerts
770
        finally:
771
            close_session()
4394 rajveer 772
 
4447 rajveer 773
    def addAlert(self, type, warehouseId, description):
483 rajveer 774
        """
775
        Parameters:
776
         - type
4394 rajveer 777
         - description
4447 rajveer 778
         - warehouseId
483 rajveer 779
        """
766 rajveer 780
        try:
4447 rajveer 781
            add_alert(type, warehouseId, description)
766 rajveer 782
        finally:
783
            close_session()
1596 ankur.sing 784
 
4444 rajveer 785
    def markAlertsAsSeen(self, warehouseId):
786
        """
787
        Parameters:
788
         - warehouseId
789
        """
790
        try:
791
            mark_alerts_as_seen(warehouseId)
792
        finally:
793
            close_session()
794
        pass
795
 
1596 ankur.sing 796
    def getValidOrderCount(self, ):
797
        """
798
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
799
        """
1731 ankur.sing 800
        try:
801
            return get_valid_order_count()
802
        finally:
803
            close_session()
1627 ankur.sing 804
 
805
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
806
        """
807
        Returns the number of distinct customers who have done successful transactions
808
        """
1731 ankur.sing 809
        try:
810
            return get_cust_count_with_successful_txn()
811
        finally:
812
            close_session()
1627 ankur.sing 813
 
1731 ankur.sing 814
 
815
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 816
        """
1731 ankur.sing 817
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
818
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 819
        """
1731 ankur.sing 820
        try:
821
            return get_valid_orders_amount_range()
822
        finally:
823
            close_session()
1627 ankur.sing 824
 
5874 rajveer 825
    def getValidOrders(self, limit, onlyStore):
1886 ankur.sing 826
        """
827
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
828
        If limit is passed as 0, then all valid Orders are returned.
829
 
830
        Parameters:
831
         - limit
5874 rajveer 832
         - onlyStore
1886 ankur.sing 833
        """
834
        try:
5874 rajveer 835
            return [to_t_order(order) for order in get_valid_orders(limit, onlyStore)]
1886 ankur.sing 836
        finally:
837
            close_session()
104 ashish 838
 
2536 chandransh 839
    def toggleDOAFlag(self, orderId):
104 ashish 840
        """
2536 chandransh 841
        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.
842
        Returns the final flag status.
843
        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 844
 
132 ashish 845
        Parameters:
2536 chandransh 846
         - orderId
132 ashish 847
        """
2536 chandransh 848
        try:
849
            return toggle_doa_flag(orderId)
850
        finally:
851
            close_session()
483 rajveer 852
 
4454 rajveer 853
    def markOrderDoaRequestReceived(self, orderId):
854
        """
855
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
856
 
857
        Parameters:
858
         - orderId
859
        """
860
        try:
861
            return mark_order_doa_request_received(orderId)
862
        finally:
863
            close_session()
864
 
865
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized):
866
        """
867
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
868
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
869
 
870
        Parameters:
871
         - orderId
872
         - isAuthorized
873
        """
874
        try:
875
            return mark_order_doa_request_authorized(orderId, isAuthorized)
876
        finally:
877
            close_session()
878
 
4488 rajveer 879
    def markOrderReturnRequestReceived(self, orderId):
880
        """
881
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
882
 
883
        Parameters:
884
         - orderId
885
        """
886
        try:
887
            return mark_order_return_request_received(orderId)
888
        finally:
889
            close_session()
890
 
891
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized):
892
        """
893
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
894
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
895
 
896
        Parameters:
897
         - orderId
898
         - isAuthorized
899
        """
900
        try:
901
            return mark_order_return_request_authorized(orderId, isAuthorized)
902
        finally:
903
            close_session()
904
 
4579 rajveer 905
    def requestPickupNumber(self, orderId, providerId):
104 ashish 906
        """
2536 chandransh 907
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 908
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
909
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 910
        For any other status, it returns false.
911
        Throws an exception if the order with the given id couldn't be found.
104 ashish 912
 
913
        Parameters:
2536 chandransh 914
         - orderId
104 ashish 915
        """
2536 chandransh 916
        try:
4579 rajveer 917
            return request_pickup_number(orderId, providerId)
2536 chandransh 918
        finally:
919
            close_session()
483 rajveer 920
 
4602 rajveer 921
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 922
        """
4452 rajveer 923
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 924
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
925
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
926
            3. Returns true
927
        If the order is any other status, it returns false.
928
        Throws an exception if the order with the given id couldn't be found.
304 ashish 929
 
930
        Parameters:
2536 chandransh 931
         - orderId
932
         - pickupNumber
304 ashish 933
        """
2536 chandransh 934
        try:
4602 rajveer 935
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 936
        finally:
937
            close_session()    
2764 chandransh 938
 
939
    def markDoasAsPickedUp(self, providerId, pickupDetails):
940
        """
941
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
942
 
943
        Parameters:
944
         - providerId
945
         - pickupDetails
946
        """
947
        try:
4910 phani.kuma 948
            mark_doas_as_picked_up(providerId, pickupDetails)
949
        finally:
950
            close_session()
951
 
952
    def getDoasNotPickedUp(self, providerId):
953
        """
954
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
955
 
956
        Parameters:
957
         - providerId
958
        """
959
        try:
960
            orders_not_picked_up = get_doas_not_picked_up(providerId)
2764 chandransh 961
            return [to_t_order(order) for order in orders_not_picked_up]
962
        finally:
963
            close_session()
4910 phani.kuma 964
 
4741 phani.kuma 965
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
966
        """
967
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
968
 
969
        Parameters:
970
         - providerId
971
         - pickupDetails
972
        """
973
        try:
4910 phani.kuma 974
            mark_return_orders_as_picked_up(providerId, pickupDetails)
975
        finally:
976
            close_session()
977
 
978
    def getReturnOrdersNotPickedUp(self, providerId):
979
        """
980
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
981
 
982
        Parameters:
983
         - providerId
984
        """
985
        try:
986
            orders_not_picked_up = get_return_orders_not_picked_up(providerId)
4741 phani.kuma 987
            return [to_t_order(order) for order in orders_not_picked_up]
988
        finally:
989
            close_session()
4910 phani.kuma 990
 
4479 rajveer 991
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 992
        """
4452 rajveer 993
        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 994
        If the order is in any other state, it returns false.
995
        Throws an exception if the order with the given id couldn't be found.
996
 
997
        Parameters:
998
         - orderId
999
        """
1000
        try:
4479 rajveer 1001
            return receive_return(orderId, receiveCondition)
2591 chandransh 1002
        finally:
1003
            close_session()
1004
 
1005
    def validateDoa(self, orderId, isValid):
1006
        """
4452 rajveer 1007
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 1008
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 1009
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
1010
        If the order is in any other state, it returns false.
1011
        Throws an exception if the order with the given id couldn't be found.
1012
 
1013
        Parameters:
1014
         - orderId
1015
         - isValid
1016
        """
1017
        try:
1018
            return validate_doa(orderId, isValid)
1019
        finally:
1020
            close_session()
2628 chandransh 1021
 
4495 rajveer 1022
    def validateReturnProduct(self, orderId, isUsable):
1023
        """
1024
        Parameters:
1025
         - orderId
1026
         - isUsable
1027
        """
1028
        try:
1029
            return validate_return_product(orderId, isUsable)
1030
        finally:
1031
            close_session()
1032
 
2628 chandransh 1033
    def reshipOrder(self, orderId):
1034
        """
4484 rajveer 1035
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1036
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 1037
            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 1038
 
1039
        If the order is in DOA_CERT_VALID state, it does the following:
1040
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1041
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 1042
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 1043
 
1044
        Returns the id of the newly created order.
1045
 
1046
        Throws an exception if the order with the given id couldn't be found.
1047
 
1048
        Parameters:
1049
         - orderId
1050
        """
1051
        try:
1052
            return reship_order(orderId)
1053
        finally:
1054
            close_session()
1055
 
3226 chandransh 1056
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 1057
        """
4484 rajveer 1058
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1059
            1. Creates a refund request for batch processing.
1060
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 1061
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 1062
 
1063
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1064
            1. Creates a refund request for batch processing.
3226 chandransh 1065
            2. Cancels the reservation of the item in the warehouse.
1066
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 1067
 
3226 chandransh 1068
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1069
            1. Cancels the reservation of the item in the warehouse.
1070
            2. Marks the current order as CANCELED.
1071
 
1072
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
1073
 
2628 chandransh 1074
        Returns True if it is successful, False otherwise.
1075
 
1076
        Throws an exception if the order with the given id couldn't be found.
1077
 
1078
        Parameters:
1079
         - orderId
3226 chandransh 1080
         - refundedBy
1081
         - reason
2628 chandransh 1082
        """
1083
        try:
3226 chandransh 1084
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 1085
        finally:
1086
            close_session()
1087
 
2697 chandransh 1088
    def getReturnOrders(self, warehouseId, fromDate, toDate):
1089
        """
1090
        Get all return orders created between the from and to dates for the given warehouse.
1091
        Ignores the warehouse if it is passed as -1.
1092
 
1093
        Parameters:
1094
         - warehouseId
1095
         - fromDate
1096
         - toDate
1097
        """
1098
        try:
1099
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1100
            return get_return_orders(warehouseId, from_date, to_date)
1101
        finally:
1102
            close_session()
1103
 
5481 phani.kuma 1104
    def getAllReturnOrders(self, onlyNotProcessed, fromDate, toDate):
1105
        """
1106
        Get all return orders created between the from and to dates for the given warehouse.
1107
        Ignores the warehouse if it is passed as -1.
1108
 
1109
        Parameters:
1110
         - warehouseId
1111
         - fromDate
1112
         - toDate
1113
        """
1114
        try:
1115
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1116
            return get_all_return_orders(onlyNotProcessed, from_date, to_date)
1117
        finally:
1118
            close_session()
1119
 
2700 chandransh 1120
    def getReturnOrder(self, id):
1121
        """
1122
        Returns the ReturnOrder corresponding to the given id.
1123
        Throws an exception if the return order with the given id couldn't be found.
1124
 
1125
        Parameters:
1126
         - id
1127
        """
1128
        try:
1129
            return get_return_order(id)
1130
        finally:
1131
            close_session()
1132
 
2697 chandransh 1133
    def processReturn(self, returnOrderId):
1134
        """
1135
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
1136
 
1137
        Parameters:
1138
         - returnOrderId
1139
        """
1140
        try:
1141
            process_return(returnOrderId)
1142
        finally:
1143
            close_session()
4757 mandeep.dh 1144
 
1145
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 1146
        """
4757 mandeep.dh 1147
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
1148
        the quantities for which the PO is raised.
1149
 
2819 chandransh 1150
        Parameters:
4757 mandeep.dh 1151
         - itemIdQuantityMap
1152
         - purchaseOrderId
2819 chandransh 1153
         - warehouseId
1154
        """
1155
        try:
4757 mandeep.dh 1156
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 1157
        finally:
1158
            close_session()
4757 mandeep.dh 1159
 
3451 chandransh 1160
    def updateWeight(self, orderId, weight):
1161
        """
1162
        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.
1163
 
1164
        Parameters:
1165
         - orderId
1166
         - weight
1167
        """
1168
        try:
1169
            order = update_weight(orderId, weight)
1170
            return to_t_order(order)
1171
        finally:
1172
            close_session()
1173
 
3469 chandransh 1174
    def changeItem(self, orderId, itemId):
1175
        """
1176
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
1177
        Currently, it also ensures that only a different color of the given item is shipped.
1178
 
1179
        Parameters:
1180
         - orderId
1181
         - itemId
1182
        """
1183
        try:
1184
            order = change_product(orderId, itemId)
1185
            return to_t_order(order)
1186
        finally:
1187
            close_session()
1188
 
1189
    def shiftToWarehouse(self, orderId, warehouseId):
1190
        """
1191
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
1192
 
1193
        Parameters:
1194
         - orderId
1195
         - warehouseId
1196
        """
1197
        try:
1198
            order = change_warehouse(orderId, warehouseId)
1199
            return to_t_order(order)
1200
        finally:
1201
            close_session()
3553 chandransh 1202
 
4647 rajveer 1203
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 1204
        """
1205
        Adds the given delay reason to the given order.
3986 chandransh 1206
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 1207
        Raises an exception if no order with the given id can be found.
3469 chandransh 1208
 
3553 chandransh 1209
        Parameters:
1210
         - orderId
1211
         - delayReason
1212
        """
1213
        try:
4647 rajveer 1214
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 1215
        finally:
1216
            close_session()
1217
 
3956 chandransh 1218
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
1219
        """
1220
        Marks the COD orders with given AWB nos. as having been processed.
1221
        Updates the captured amount for the corresponding payment.
1222
 
1223
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
1224
        1. There is no order corresponding to an AWB number.
1225
        2. The captured amount for a payment exceeds the total payment.
1226
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
1227
 
1228
        Parameters:
1229
         - collectedAmountMap
1230
         - xferBy
1231
         - xferTxnId
1232
         - xferDate
1233
        """
1234
        try:
1235
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
1236
        finally:
1237
            close_session()
4008 mandeep.dh 1238
 
1239
    def getTransactionsRequiringExtraProcessing(self, category):
1240
        """
1241
        Returns the list of transactions that require some extra processing and
1242
        which belong to a particular category. This is currently used by CRM
1243
        application.
1244
        """
1245
        try:
1246
            return get_transactions_requiring_extra_processing(category)
1247
        finally:
1248
            close_session()
1249
 
1250
    def markTransactionAsProcessed(self, transactionId, category):
1251
        """
1252
        Marks a particular transaction as processed for a particular category.
1253
        It essentially deletes the transaction if it is processed for a particular
1254
        category. This is currently used by CRM application.
1255
        """
1256
        try:
1257
            return mark_transaction_as_processed(transactionId, category)
1258
        finally:
1259
            close_session()
4018 chandransh 1260
 
1261
    def getItemWiseRiskyOrdersCount(self, ):
1262
        """
1263
        Returns a map containing the number of risky orders keyed by item id. A risky order
1264
        is defined as one whose shipping date is about to expire.
1265
        """
1266
        try:
1267
            return get_item_wise_risky_orders_count()
1268
        finally:
1269
            close_session()
3956 chandransh 1270
 
4247 rajveer 1271
    def markOrderCancellationRequestReceived(self, orderId):
1272
        """
1273
        Mark order as cancellation request received. If customer sends request of cancellation of
1274
        a particular order, this method will be called. It will just change status of the order
1275
        depending on its current status. It also records the previous status, so that we can move
1276
        back to that status if cancellation request is denied.
1277
 
1278
        Parameters:
1279
         - orderId
1280
        """
1281
        try:
1282
            return mark_order_cancellation_request_received(orderId)
1283
        finally:
1284
            close_session()
1285
 
1286
 
4662 rajveer 1287
    def markOrderAsLostInTransit(self, orderId):
1288
        """
1289
        Parameters:
1290
         - orderId
1291
        """
1292
        try:
1293
            return mark_order_as_lost_in_transit(orderId)
1294
        finally:
1295
            close_session()
1296
 
4258 rajveer 1297
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1298
        """
4258 rajveer 1299
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1300
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1301
 
1302
        Parameters:
4258 rajveer 1303
         - transactionId
4247 rajveer 1304
        """
1305
        try:
4259 anupam.sin 1306
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1307
        finally:
1308
            close_session()
4259 anupam.sin 1309
 
1310
    def refundTransaction(self, transactionId, refundedBy, reason):
1311
        """
1312
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1313
        need to be cancelled
1314
 
1315
        Parameters:
1316
         - transactionId
1317
        """
1318
        try:
1319
            return refund_transaction(transactionId, refundedBy, reason)
1320
        finally:
1321
            close_session()
4247 rajveer 1322
 
1323
    def markOrderCancellationRequestDenied(self, orderId):
1324
        """
1325
        If we decide to not to cancel order, we will move the order ro previous status.
1326
 
1327
        Parameters:
1328
         - orderId
1329
        """
1330
        try:
1331
            return mark_order_cancellation_request_denied(orderId)
1332
        finally:
1333
            close_session()
1334
 
1335
    def markOrderCancellationRequestConfirmed(self, orderId):
1336
        """
1337
        If we decide to to cancel order, CRM will call this method to move the status of order to
1338
        cancellation request confirmed. After this OM will be able to cancel the order.
1339
 
1340
        Parameters:
1341
         - orderId
1342
        """
1343
        try:
1344
            return mark_order_cancellation_request_confirmed(orderId)
1345
        finally:
1346
            close_session()
1347
 
4324 mandeep.dh 1348
    def updateShipmentAddress(self, orderId, addressId):
1349
        """
1350
        Updates shipment address of an order. Delivery and shipping date estimates
1351
        etc. are also updated here.
1352
 
1353
        Throws TransactionServiceException in case address change is not
1354
        possible due to certain reasons such as new pincode in address is
1355
        not serviceable etc.
1356
 
1357
        Parameters:
1358
         - orderId
1359
         - addressId
1360
        """
1361
        try:
1362
            update_shipment_address(orderId, addressId)
1363
        finally:
1364
            close_session()
1365
 
4285 rajveer 1366
    def acceptOrdersForItemId(self, itemId, inventory):
1367
        """
1368
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1369
        given order is not a COD order, it also captures the payment if the same has not been captured.
1370
 
1371
        Parameters:
1372
         - itemId
1373
         - inventory
1374
        """
1375
        try:
1376
            return accept_orders_for_item_id(itemId, inventory)
1377
        finally:
1378
            close_session()
1379
 
4303 rajveer 1380
 
1381
 
4369 rajveer 1382
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1383
        """
1384
        Parameters:
1385
         - vendorId
1386
         - itemId
1387
         - quantity
1388
         - estimate
4369 rajveer 1389
         - isReminder
4303 rajveer 1390
        """
1391
        try:
4369 rajveer 1392
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1393
        finally:
1394
            close_session()
1395
 
4369 rajveer 1396
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1397
        """
1398
        Parameters:
1399
         - vendorId
1400
         - itemId
1401
         - quantity
1402
         - estimate
4369 rajveer 1403
         - isReminder
4303 rajveer 1404
        """
1405
        try:
4369 rajveer 1406
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1407
        finally:
1408
            close_session()
1409
 
4369 rajveer 1410
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1411
        """
1412
        Parameters:
1413
         - vendorId
1414
         - itemId
1415
         - quantity
1416
         - estimate
4369 rajveer 1417
         - isReminder
4303 rajveer 1418
        """
1419
        try:
4369 rajveer 1420
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1421
        finally:
1422
            close_session()
1423
 
1424
 
4369 rajveer 1425
    def markOrdersAsTimeout(self, vendorId):
1426
        """
1427
        Parameters:
1428
         - vendorId
1429
        """
1430
        try:
1431
            return mark_orders_as_timeout(vendorId)
1432
        finally:
1433
            close_session()
4386 anupam.sin 1434
 
1435
    def getOrderForAwb(self, awb):
1436
        """
1437
        Parameters:
1438
         - AirwayBill Number
1439
        """
1440
        try:
1441
            return to_t_order(get_order_for_awb(awb))
1442
        finally:
1443
            close_session()
4369 rajveer 1444
 
4910 phani.kuma 1445
    def getOrdersForProviderForStatus(self, provider_id, order_status_list):
4506 phani.kuma 1446
        """
1447
        Parameters:
1448
         - provider id
1449
         - order status
1450
        """
1451
        try:
4910 phani.kuma 1452
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status_list)
4506 phani.kuma 1453
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1454
        finally:
1455
            close_session()
4600 varun.gupt 1456
 
1457
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1458
        '''
1459
        Parameters:
1460
         - vendorId
1461
         - billingDateFrom
1462
         - billingDateTo
1463
        '''
1464
        try:
1465
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1466
        finally:
1467
            close_session()
1468
 
4607 rajveer 1469
    def getSlippedSippingDateOrders(self):
1470
        try:
1471
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1472
        finally:
1473
            close_session()
1474
 
4709 rajveer 1475
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1476
        try:
1477
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1478
        finally:
1479
            close_session()
1480
 
4600 varun.gupt 1481
    def getEBSSettlementSummaries(self):
1482
        try:
1483
            return get_ebs_settlement_summaries()
1484
        finally:
1485
            close_session()
4369 rajveer 1486
 
4600 varun.gupt 1487
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1488
        try:
1489
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1490
        finally:
1491
            close_session()
1492
 
5386 phani.kuma 1493
    def getSettlementForPrepaid(self, referenceId, isRefund):
4600 varun.gupt 1494
        '''
1495
        Parameters:
5189 varun.gupt 1496
         - referenceId
1497
         - isRefund
4600 varun.gupt 1498
        '''
1499
        try:
5386 phani.kuma 1500
            return to_t_payment_settlement(get_settlement_for_Prepaid(referenceId, isRefund))
4600 varun.gupt 1501
        finally:
1502
            close_session()
5386 phani.kuma 1503
 
1504
    def getSettlementForCod(self, orderId, isRefund):
1505
        '''
1506
        Parameters:
1507
         - orderId
1508
         - isRefund
1509
        '''
1510
        try:
1511
            return to_t_payment_settlement(get_settlement_for_Cod(orderId, isRefund))
1512
        finally:
1513
            close_session()
1514
 
4600 varun.gupt 1515
    def getEBSSettlementDate(self, settlementId):
1516
        try:
1517
            return to_java_date(get_ebs_settlement_date(settlementId))
1518
        finally:
1519
            close_session()
1520
 
4905 varun.gupt 1521
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection):
4600 varun.gupt 1522
        try:
4905 varun.gupt 1523
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection)
4600 varun.gupt 1524
        finally:
1525
            close_session()
1526
 
1527
    def markEBSSettlementUploaded(self, settlementId):
1528
        try:
1529
            mark_ebs_settlement_uploaded(settlementId)
1530
        finally:
1531
            close_session()
1532
 
4715 varun.gupt 1533
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1534
        try:
1535
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1536
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1537
        finally:
1538
            close_session()
1539
 
1540
    def getReshippedOrderIds(self, orderIds):
1541
        try:
1542
            return get_reshipped_order_ids(orderIds)
1543
        finally:
1544
            close_session()
1545
 
5481 phani.kuma 1546
    def getBilledOrders(self, vendorId, onlyVendorNotPaid, billingDateFrom, billingDateTo):
4875 varun.gupt 1547
        try:
5481 phani.kuma 1548
            from_date, to_date = get_fdate_tdate(billingDateFrom, billingDateTo)
1549
            return [to_t_order(order) for order in get_billed_orders(vendorId, onlyVendorNotPaid, from_date, to_date)]
4875 varun.gupt 1550
        finally:
1551
            close_session()
1552
 
5062 varun.gupt 1553
    def getStatusDistributionOfOrders(self, startDate, endDate):
1554
        try:
5067 varun.gupt 1555
            distribution = {}
1556
 
1557
            for status, count in get_order_distribution_by_status(to_py_date(startDate), to_py_date(endDate)):
1558
                distribution[status] = count
1559
 
1560
            return distribution
5062 varun.gupt 1561
        finally:
1562
            close_session()
1563
 
5067 varun.gupt 1564
    def getOrderIdsForStatus(self, status, startDatetime, endDatetime):
1565
        try:
1566
            orders = get_order_ids_for_status(status, to_py_date(startDatetime), to_py_date(endDatetime))
1567
            return [order.id for order in orders]
1568
        finally:
1569
            close_session()
1570
 
5099 varun.gupt 1571
    def updateOrderAsPaidToVendor(self, orderId):
1572
        try:
1573
            update_orders_as_paid_to_vendor(orderId)
1574
        finally:
1575
            close_session()
1576
 
5348 anupam.sin 1577
    def updateCODAgent(self, agentEmailId, orderId):
1578
        try:
1579
            update_COD_agent(agentEmailId, orderId)
1580
        finally:
1581
            close_session()
1582
 
5386 phani.kuma 1583
    def updateOrderOnlyAsPaidToVendor(self, orderId):
1584
        try:
1585
            update_order_only_as_paid_to_vendor(orderId)
1586
        finally:
1587
            close_session()
1588
 
5208 varun.gupt 1589
    def getRefundedOrdersMarkedPaid(self):
1590
        try:
1591
            return [to_t_order(order) for order in get_refunded_orders_marked_paid()]
1592
        finally:
1593
            close_session()
5447 anupam.sin 1594
 
1595
    def getAllVerificationAgents(self, minOrderId, maxOrderId):
1596
        try:
1597
            return [to_t_verification_agent(codAgent) for codAgent in get_all_verification_agents(minOrderId, maxOrderId)]
1598
        finally:
5527 anupam.sin 1599
            close_session()
1600
 
1601
    def getAllAttributesForOrderId(self, orderId):
1602
        try:
1603
            return [to_t_attribute(attribute) for attribute in get_all_attributes_for_order_id(orderId)]
1604
        finally:
1605
            close_session()
1606
 
1607
    def setOrderAttributeForTransaction(self, transactionId, attribute):
1608
        try:
1609
            set_order_attribute_for_transaction(transactionId, attribute)                    
1610
        finally:
1611
            close_session()
5593 mandeep.dh 1612
 
1613
    def acceptOrderForItem(self, itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
1614
        """
1615
        Accepts appropriate order for an item in a given billingWarehouse. Usually
1616
        invoked while scanning IN of items.
1617
 
1618
        Parameters:
1619
         - itemId
1620
         - quantity
1621
         - fulfilmentWarehouseId
1622
         - billingWarehouseId
1623
        """
1624
        try:
1625
            accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId)
1626
        finally:
1627
            close_session()
1628
 
5833 rajveer 1629
    def getOrderAttributeValue(self, orderId, attributeName):
1630
        """
1631
        Parameters:
1632
         - orderId
1633
         - attributeName
1634
        """
1635
        try:
6019 rajveer 1636
            return get_order_attribute_value(orderId, attributeName)
5833 rajveer 1637
        finally:
1638
            close_session()
1639
 
6019 rajveer 1640
    def changeJacketNumber(self, orderId, jacketNumber):
1641
        """
1642
        Parameters:
1643
         - orderId
1644
         - jacketNumber
1645
        """
1646
        try:
1647
            return change_jacket_number(orderId, jacketNumber)
1648
        finally:
1649
            close_session()
1650
 
1651
    def markOrderAsRtoInTransit(self, orderId):
1652
        """
1653
        Parameters:
1654
         - orderId
1655
        """
1656
        try:
1657
            return mark_order_as_rto_in_transit(orderId)
1658
        finally:
1659
            close_session()        
1660
 
6000 mandeep.dh 1661
    def createRechargeOrder(self, thriftRechargeOrder):
1662
        """
1663
        Parameters:
1664
         - thriftRechargeOrder
1665
        """
6031 rajveer 1666
        try:
1667
            if thriftRechargeOrder is None or thriftRechargeOrder.rechargeType is None:
1668
                raise TransactionServiceException(102, 'Order or the type is Null')
1669
 
1670
            rechargeOrder = None
1671
            if thriftRechargeOrder.rechargeType == RechargeType.MOBILE:
1672
                rechargeOrder = MobileRechargeOrder()
1673
            elif thriftRechargeOrder.rechargeType == RechargeType.DTH:
1674
                rechargeOrder = DTHRechargeOrder()
1675
 
1676
            if rechargeOrder is None:
1677
                raise TransactionServiceException(102, 'Unsupported recharge type')
6000 mandeep.dh 1678
 
6031 rajveer 1679
            transaction = DigitalTransaction()
1680
            transaction.createdOn = datetime.datetime.now()
6056 amit.gupta 1681
            transaction.userId = thriftRechargeOrder.userId
6031 rajveer 1682
            transaction.orders = [rechargeOrder]
1683
 
6000 mandeep.dh 1684
            rechargeOrder.from_thrift_object(thriftRechargeOrder)
1685
            session.commit()
6031 rajveer 1686
            return rechargeOrder.to_thrift_object()
6000 mandeep.dh 1687
        except:
1688
            raise TransactionServiceException(103, 'Invalid values passed')
1689
        finally:
1690
            self.closeSession()
1691
 
6031 rajveer 1692
    def getRechargeOrder(self, rechargeOrderId):
1693
        """
1694
        Parameters:
1695
         - rechargeOrderId
1696
        """
1697
        try:
6048 rajveer 1698
            return get_recharge_order(rechargeOrderId).to_thrift_object()
6031 rajveer 1699
        finally:
1700
            self.closeSession()
1701
 
1702
    def getRechargeOrders(self, userId):
1703
        """
1704
        Parameters:
1705
         - userId
1706
        """
1707
        try:
1708
            return [order.to_thrift_object() for order in get_recharge_orders(userId)]
1709
        finally:
1710
            self.closeSession()
1711
 
6000 mandeep.dh 1712
    def updateRechargeOrderStatus(self, rechargeOrderId, rechargeOrderStatus):
1713
        """
1714
        Parameters:
1715
         - rechargeOrderId
1716
         - rechargeOrderStatus
1717
        """
6031 rajveer 1718
        try:
1719
            return update_recharge_order_status(rechargeOrderId, rechargeOrderStatus)
1720
        finally:
1721
            self.closeSession()
1722
 
1723
    def activateRechargeTxn(self, rechargeOrderId):
6000 mandeep.dh 1724
        """
1725
        Parameters:
6031 rajveer 1726
         - rechargeOrderId
6000 mandeep.dh 1727
        """
6031 rajveer 1728
        try:
1729
            return True
1730
            activate_recharge_txn(rechargeOrderId)
1731
        finally:
1732
            self.closeSession()
6000 mandeep.dh 1733
 
6031 rajveer 1734
    def getUserWallet(self, userId):
6000 mandeep.dh 1735
        """
1736
        Parameters:
6031 rajveer 1737
         - userId
6000 mandeep.dh 1738
        """
6031 rajveer 1739
        try:
1740
            return get_user_wallet(userId).to_thrift_object()
1741
        finally:
1742
            self.closeSession()
6000 mandeep.dh 1743
 
6031 rajveer 1744
    def getUserWalletHistory(self, userId):
6000 mandeep.dh 1745
        """
1746
        Parameters:
6031 rajveer 1747
         - userId
6000 mandeep.dh 1748
        """
6031 rajveer 1749
        try:
1750
            return [wallet.to_thrift_object() for wallet in get_user_wallet_history(userId)]
1751
        finally:
1752
            self.closeSession()
6000 mandeep.dh 1753
 
6206 rajveer 1754
    def getServiceProviders(self, rechargeType, onlyActive):
6048 rajveer 1755
        """
1756
        Parameters:
1757
         - rechargeType
6206 rajveer 1758
         - onlyActive
6048 rajveer 1759
        """
6077 anupam.sin 1760
 
6048 rajveer 1761
        try:
6206 rajveer 1762
            return get_service_providers(rechargeType, onlyActive)
6048 rajveer 1763
        finally:
1764
            self.closeSession()
1765
 
6049 rajveer 1766
    def getServiceProviderForDevice(self, rechargeType, deviceNumber):
6048 rajveer 1767
        """
1768
        Parameters:
1769
         - deviceNumber
1770
        """
1771
        try:
6049 rajveer 1772
            return get_service_provider_for_device(rechargeType, deviceNumber)
6048 rajveer 1773
        finally:
1774
            self.closeSession()
6056 amit.gupta 1775
 
6591 anupam.sin 1776
    def validateRecharge(self, rechargeType, deviceNumber, userSelectedProviderId, clientAddress):
6269 rajveer 1777
        """
1778
        Parameters:
1779
         - deviceNumber
1780
        """
1781
        try:
6591 anupam.sin 1782
            return validate_recharge(rechargeType, deviceNumber, userSelectedProviderId, clientAddress)
6269 rajveer 1783
        finally:
1784
            self.closeSession()
1785
 
6056 amit.gupta 1786
    def getRechargeOrdersForTransaction(self, txId):
1787
        """
1788
        Parameters:
1789
         - transactionId
1790
        """
1791
        try:
1792
            return get_recharge_orders_for_transaction(txId).to_thrift_object()
1793
        finally:
1794
            self.closeSession()
6048 rajveer 1795
 
6094 rajveer 1796
    def getRechargeOrdersForDevice(self, deviceNumber):
1797
        """
1798
        Parameters:
1799
        - deviceNumber
1800
        """
1801
        try:
1802
            return [order.to_thrift_object() for order in get_recharge_orders_for_device(deviceNumber)]
1803
        finally:
1804
            self.closeSession()
1805
 
6154 rajveer 1806
    def getRechargeOrdersForStatus(self, status):
1807
        """
1808
        Parameters:
1809
        - status
1810
        """
1811
        try:
1812
            return [order.to_thrift_object() for order in get_recharge_orders_for_status(status)]
1813
        finally:
1814
            self.closeSession()
1815
 
6159 rajveer 1816
    def getPlansForOperator(self, operatorId):
1817
        """
1818
        Parameters:
1819
        - operatorId
1820
        """
1821
        try:
1822
            return [plan.to_thrift_object() for plan in get_plans_for_operator(operatorId)]
1823
        finally:
1824
            self.closeSession()
1825
 
1826
 
6094 rajveer 1827
    def addAmountToWallet(self, userId, orderId, amount):
1828
        """
1829
        Parameters:
1830
        - userId
1831
        - orderId
1832
        - amount
1833
        """
1834
        try:
1835
            update_amount_in_wallet(userId, amount, orderId)
1836
        finally:
1837
            self.closeSession()
1838
 
6188 rajveer 1839
    def getRechargeStatistics(self):
1840
        """
1841
        Parameters:
1842
        """
1843
        try:
1844
            return get_recharge_statistics()
1845
        finally:
1846
            self.closeSession()
1847
 
6307 anupam.sin 1848
    def getRechargeDenominations(self, operatorId, circleCode, denominationType):
6289 anupam.sin 1849
        try:
1850
            returnList = []
6307 anupam.sin 1851
            rechargeDenominations = get_recharge_denominations(operatorId, circleCode, denominationType)
6289 anupam.sin 1852
            for rechargeDenomination in rechargeDenominations:
1853
                returnList.append(rechargeDenomination.to_thrift_object())
1854
            return returnList
1855
        finally:
1856
            self.closeSession() 
6188 rajveer 1857
 
6371 rajveer 1858
    def updateAvailabilityStatus(self, operatorId, circleId, isAvailable):
1859
        try:
1860
            update_availability_status(operatorId, circleId, isAvailable)
1861
        finally:
1862
            self.closeSession() 
1863
 
6396 amit.gupta 1864
    def getAvailableEmiSchemes(self):
1865
        try:
1866
            return get_available_emi_schemes()
1867
        finally:
1868
            self.closeSession()
1869
 
6389 rajveer 1870
    def getMiscCharges(self, transactionId):
1871
        try:
1872
            return get_misc_charges(transactionId)
1873
        finally:
1874
            self.closeSession()
1875
 
6507 anupam.sin 1876
    def refundRechargeOrder (self, rechargeOrderId):
1877
        try:
1878
            return refund_recharge_order(rechargeOrderId)
1879
        finally:
1880
            self.closeSession()
1881
 
2536 chandransh 1882
    def closeSession(self, ):
1883
        close_session()
3376 rajveer 1884
 
1885
    def isAlive(self, ):
1886
        """
5447 anupam.sin 1887
        For checking whether service is alive or not. It also checks connectivity with database
3376 rajveer 1888
        """
1889
        try:
1890
            return is_alive()
1891
        finally:
4247 rajveer 1892
            close_session()