Subversion Repositories SmartDukaan

Rev

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