Subversion Repositories SmartDukaan

Rev

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