Subversion Repositories SmartDukaan

Rev

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