Subversion Repositories SmartDukaan

Rev

Rev 6077 | Rev 6154 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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