Subversion Repositories SmartDukaan

Rev

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