Subversion Repositories SmartDukaan

Rev

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