Subversion Repositories SmartDukaan

Rev

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