Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
104 ashish 1
'''
2
Created on 29-Mar-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.model.v1.order.impl import DataService
7
from shop2020.model.v1.order.impl.DataAccessors import create_transaction,\
1382 varun.gupt 8
    create_order, get_new_transaction, get_transactions_for_customer, get_transaction_status,\
9
    get_line_items_for_order, get_transaction, get_transactions_for_shopping_cart_id,\
10
    change_transaction_status, get_orders_for_customer,get_orders_for_transaction, get_order,\
11
    get_returnable_orders_for_customer, get_cancellable_orders_for_customer, get_orders_by_billing_date,\
12
    get_all_orders, change_order_status, get_alerts, set_alert, add_billing_details,\
13
    mark_orders_as_manifested, close_session, accept_order, bill_order, mark_orders_as_picked_up,\
1208 chandransh 14
    mark_orders_as_delivered, mark_orders_as_failed, add_jacket_number,\
1405 ankur.sing 15
    order_outofstock, batch_orders, update_non_delivery_reason, enqueue_transaction_info_email,\
1627 ankur.sing 16
    get_undelivered_orders, get_order_for_customer, get_valid_order_count,\
1886 ankur.sing 17
    get_cust_count_with_successful_txn, get_valid_orders_amount_range,\
2591 chandransh 18
    get_valid_orders, toggle_doa_flag, request_pickup_number, authorize_pickup,\
2697 chandransh 19
    receive_return, validate_doa, reship_order, refund_order, get_return_orders,\
2819 chandransh 20
    process_return, get_return_order, mark_doas_as_picked_up,\
3064 chandransh 21
    create_purchase_order, verify_order
1405 ankur.sing 22
 
104 ashish 23
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
1348 chandransh 24
    to_t_alert, to_t_order, to_t_lineitem
483 rajveer 25
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
2783 chandransh 26
    LineItem, Order, TransactionServiceException
738 chandransh 27
from shop2020.utils.Utils import to_py_date, get_fdate_tdate
104 ashish 28
 
29
class OrderServiceHandler:
30
 
1249 chandransh 31
    def __init__(self, dbname='transaction'):
483 rajveer 32
        """
104 ashish 33
        Constructor
483 rajveer 34
        """
1249 chandransh 35
        DataService.initialize(dbname)
104 ashish 36
 
37
    def createTransaction(self, transaction):
38
        """
39
        Parameters:
40
         - transaction
41
        """
766 rajveer 42
        try:
43
            return create_transaction(transaction)
44
        finally:
45
            close_session()
46
 
104 ashish 47
    def getTransaction(self, id):
48
        """
49
            Get transaction methods.
50
 
51
        Parameters:
52
         - id
53
        """
766 rajveer 54
        try:
55
            transaction = get_transaction(id)
56
            return to_t_transaction(transaction)
57
        finally:
58
            close_session()
59
 
483 rajveer 60
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 61
        """
62
        Parameters:
483 rajveer 63
         - customerId
104 ashish 64
         - from_date
65
         - to_date
483 rajveer 66
         - status
104 ashish 67
        """
766 rajveer 68
        try:
69
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
70
 
71
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
72
            t_transaction = []
73
            for transaction in transactions:
74
                t_transaction.append(to_t_transaction(transaction))
75
            return t_transaction
76
        finally:
77
            close_session()
483 rajveer 78
 
79
    def getTransactionsForShoppingCartId(self, shoppingCartId):
80
        """
81
        Parameters:
82
            - shoppingCartId
83
        """
766 rajveer 84
        try:
85
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
86
            t_transaction = []
87
            for transaction in transactions:
88
                t_transaction.append(to_t_transaction(transaction))
89
            return t_transaction
90
        finally:
91
            close_session()
104 ashish 92
 
483 rajveer 93
    def getTransactionStatus(self, transactionId):
104 ashish 94
        """
95
        Parameters:
483 rajveer 96
         - transactionId
97
        """
766 rajveer 98
        try:
99
            return get_transaction_status(transactionId)
100
        finally:
101
            close_session()
102
 
483 rajveer 103
    def changeTransactionStatus(self, transactionId, status, description):
104
        """
105
        Parameters:
106
         - transactionId
104 ashish 107
         - status
483 rajveer 108
         - description
109
        """
766 rajveer 110
        try:
111
            return change_transaction_status(transactionId, status, description)
112
        finally:
113
            close_session()
114
 
1528 ankur.sing 115
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 116
        """
1528 ankur.sing 117
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
118
        only user who owns the transaction can view its order details.
119
 
483 rajveer 120
        Parameters:
121
         - transactionId
1528 ankur.sing 122
         - customerId
483 rajveer 123
        """
766 rajveer 124
        try:
1528 ankur.sing 125
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 126
            return [to_t_order(order) for order in orders]    
127
        finally:
128
            close_session()
129
 
483 rajveer 130
    def getAllOrders(self, status, from_date, to_date, warehouse_id):
131
        """
132
        Parameters:
133
         - status
104 ashish 134
         - from_date
135
         - to_date
483 rajveer 136
         - warehouse_id
104 ashish 137
        """
766 rajveer 138
        try:
139
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
140
            orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
141
            return [to_t_order(order) for order in orders]
142
        finally:
143
            close_session()
144
 
995 varun.gupt 145
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
146
        """
147
        Parameters:
148
         - status
149
         - start_billing_date
150
         - end_billing_date
151
         - warehouse_id
152
        """
153
        try:
154
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
155
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
156
            return [to_t_order(order) for order in orders]
157
        finally:
158
            close_session()
1382 varun.gupt 159
 
160
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
161
        """
162
        Parameters:
163
         - customerId
164
         - limit
165
        """
166
        try:
167
            return get_returnable_orders_for_customer(customerId, limit)
168
        finally:
169
            close_session()
995 varun.gupt 170
 
1382 varun.gupt 171
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
172
        """
173
        Parameters:
174
         - customerId
175
         - limit
176
        """
177
        try:
178
            return get_cancellable_orders_for_customer(customerId, limit)
179
        finally:
180
            close_session()
181
 
483 rajveer 182
    def changeOrderStatus(self, orderId, status, description):
183
        """
184
        Parameters:
185
         - orderId
186
         - status
187
         - description
188
         - 
189
        """
766 rajveer 190
        try:
191
            return change_order_status(self, orderId, status, description)
192
        finally:
193
            close_session()
921 rajveer 194
 
3064 chandransh 195
    def verifyOrder(self, orderId):
196
        """
197
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
198
        timestamp. It is intended to be used for COD orders but can be harmlessly
199
        used for all other orders as well.
200
        Throws an exception if no such order exists.
201
 
202
        Parameters:
203
         - orderId
204
        """
205
        try:
206
            return verify_order(self, orderId)
207
        finally:
208
            close_session()
209
 
921 rajveer 210
    def acceptOrder(self, orderId):
211
        """
3064 chandransh 212
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
213
        given order is not a COD order, it also captures the payment if the same has
214
        not been captured.
215
        Throws an exception if no such order exists.
216
 
921 rajveer 217
        Parameters:
218
         - orderId
219
        """
220
        try:
221
            return accept_order(self, orderId)
222
        finally:
223
            close_session()
224
 
225
    def billOrder(self, orderId):
226
        """
227
        Parameters:
228
         - orderId
229
        """
230
        try:
231
            return bill_order(self, orderId)
232
        finally:
233
            close_session()
766 rajveer 234
 
3014 chandransh 235
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 236
        """
3014 chandransh 237
        Returns list of orders for the given customer created between the given dates and having the given statuses.
238
        Pass and empty list to ignore filtering on statuses.
239
 
104 ashish 240
        Parameters:
241
         - customerId
242
         - from_date
243
         - to_date
3014 chandransh 244
         - statuses
104 ashish 245
        """
766 rajveer 246
        try:
247
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
248
 
3014 chandransh 249
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 250
            return [to_t_order(order) for order in orders]
251
        finally:
252
            close_session()
1528 ankur.sing 253
 
254
    def getOrderForCustomer(self, orderId, customerId):
255
        """
256
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
257
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
258
 
259
        Parameters:
260
         - customerId
261
         - orderId
262
        """
263
        try:
264
            return to_t_order(get_order_for_customer(orderId, customerId))
265
        finally:
266
            close_session()
766 rajveer 267
 
483 rajveer 268
    def getOrder(self, id):
269
        """
270
        Parameters:
271
         - id
272
        """
766 rajveer 273
        try:
274
            return to_t_order(get_order(id))
275
        finally:
276
            close_session()
277
 
483 rajveer 278
    def getLineItemsForOrder(self, orderId):
279
        """
280
        Parameters:
281
         - orderId
282
        """
766 rajveer 283
        try:
284
            lineitems = get_line_items_for_order(orderId)
285
            t_lineitems = []
286
            for lineitem in lineitems:
287
                t_lineitems.append(to_t_lineitem(lineitem))
288
            return t_lineitems
289
        finally:
290
            close_session()
1149 chandransh 291
 
292
    def addBillingDetails(self, orderId, invoice_number, billed_by):
494 rajveer 293
        """
1149 chandransh 294
        Add billing details such as the bill number and the biller to the Order.
295
 
494 rajveer 296
        Parameters:
297
         - orderId
298
         - invoice_number
299
         - billed_by
300
        """
766 rajveer 301
        try:
1149 chandransh 302
            return add_billing_details(orderId, invoice_number, billed_by)
766 rajveer 303
        finally:
304
            close_session()
1149 chandransh 305
 
2842 chandransh 306
    def addJacketNumber(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy, billingType):
1149 chandransh 307
        """
2783 chandransh 308
        Adds jacket number and IMEI no. to the order. Doesn't update the IMEI no. if a -1 is supplied.
309
        Also marks the order as billed and sets the billing timestamp.
310
        Return false if it doesn't find the order with the given ID.
1149 chandransh 311
 
312
        Parameters:
313
         - orderId
314
         - jacketNumber
2783 chandransh 315
         - imeiNumber
316
         - itemNumber
317
         - billedBy
1149 chandransh 318
        """
319
        try:
2842 chandransh 320
            return add_jacket_number(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy, billingType)
2783 chandransh 321
        except TransactionServiceException:
322
            print "ERROR: Couldn't find the order with the given id"
323
            return False
1149 chandransh 324
        finally:
325
            close_session()
1220 chandransh 326
 
327
    def batchOrders(self, warehouseId):
328
        """
329
        Create a batch of all the pending orders for the given warehouse.
330
        The returned list is orderd by created_timestamp.
331
        If there are no pending orders, an empty list is returned.
1208 chandransh 332
 
1220 chandransh 333
        Parameters:
334
         - warehouseId
335
        """
336
        try:
337
            pending_orders = batch_orders(warehouseId)
338
            return [to_t_order(order) for order in pending_orders]
339
        finally:
340
            close_session()
341
 
1208 chandransh 342
    def markOrderAsOutOfStock(self, orderId):
343
        """
344
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
345
 
346
 
347
        Parameters:
348
         - orderId
349
        """
350
        try:
351
            return order_outofstock(orderId)
352
        finally:
353
            close_session()
354
 
3064 chandransh 355
    def markOrdersAsManifested(self, warehouseId, providerId, cod):
759 chandransh 356
        """
3064 chandransh 357
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
358
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 359
 
360
        Parameters:
361
         - warehouseId
362
         - providerId
3064 chandransh 363
         - cod
759 chandransh 364
        """
766 rajveer 365
        try:
3064 chandransh 366
            return mark_orders_as_manifested(warehouseId, providerId, cod)
766 rajveer 367
        finally:
368
            close_session()
1113 chandransh 369
 
370
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
371
        """
372
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
373
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
374
        Raises an exception if we encounter report for an AWB number that we did not ship.
375
 
376
        Parameters:
377
         - providerId
378
         - pickupDetails
379
        """
380
        try:
381
            orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
382
            return [to_t_order(order) for order in orders_not_picked_up]
383
        finally:
384
            close_session()
1132 chandransh 385
 
386
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
387
        """
388
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
389
        the name of the receiver.
390
        Raises an exception if we encounter report for an AWB number that we did not ship.
391
 
392
        Parameters:
393
         - providerId
394
         - deliveredOrders
395
        """
396
        try:
397
            mark_orders_as_delivered(providerId, deliveredOrders)
398
        finally:
399
            close_session()
1135 chandransh 400
 
401
    def markOrdersAsFailed(self, providerId, returnedOrders):
402
        """
403
        Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
404
        Raises an exception if we encounter report for an AWB number that we did not ship.
405
 
406
        Parameters:
407
         - providerId
408
         - returnedOrders
409
        """
410
        try:
411
            mark_orders_as_failed(providerId, returnedOrders)
412
        finally:
413
            close_session()
1246 chandransh 414
 
415
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
416
        """
417
        Update the status description of orders whose AWB numbers are keys of the Map.
418
 
419
        Parameters:
420
         - providerId
421
         - undelivered_orders
422
        """
423
        try:
424
            update_non_delivery_reason(providerId, undeliveredOrders)
425
        finally:
426
            close_session()
1405 ankur.sing 427
 
428
    def getUndeliveredOrders(self, providerId, warehouseId):
429
        """
430
        Returns the list of orders whose delivery time has passed but have not been
431
        delivered yet for the given provider and warehouse. To get a complete list of
432
        undelivered orders, pass them as -1.
433
        Returns an empty list if no such orders exist.
434
 
435
        Parameters:
436
         - providerId
437
         - warehouseId
438
        """
439
        try:
440
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
441
            return [to_t_order(order) for order in undelivered_orders]
442
        finally:
443
            close_session()
1351 varun.gupt 444
 
1398 varun.gupt 445
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 446
        """
1398 varun.gupt 447
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 448
 
449
        Parameters:
450
         - transactionId
451
        """
452
        try:
1398 varun.gupt 453
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 454
        finally:
455
            close_session()
456
 
483 rajveer 457
    def getAlerts(self, orderId, valid):
458
        """
459
        Parameters:
460
         - orderId
461
         - valid
462
        """
766 rajveer 463
        try:
464
            alerts = get_alerts(orderId, valid)
465
 
466
            t_alerts = []
467
 
468
            for alert in alerts:
469
                t_alerts.append(to_t_alert(alert)) 
470
 
471
            return t_alerts
472
        finally:
473
            close_session()
474
 
483 rajveer 475
    def setAlert(self, orderId, unset, type, comment):
476
        """
477
        Parameters:
478
         - orderId
479
         - unset
480
         - type
481
         - comment
482
        """
766 rajveer 483
        try:
484
            set_alert(orderId, unset, type, comment)
485
        finally:
486
            close_session()
1596 ankur.sing 487
 
488
    def getValidOrderCount(self, ):
489
        """
490
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
491
        """
1731 ankur.sing 492
        try:
493
            return get_valid_order_count()
494
        finally:
495
            close_session()
1627 ankur.sing 496
 
497
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
498
        """
499
        Returns the number of distinct customers who have done successful transactions
500
        """
1731 ankur.sing 501
        try:
502
            return get_cust_count_with_successful_txn()
503
        finally:
504
            close_session()
1627 ankur.sing 505
 
1731 ankur.sing 506
 
507
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 508
        """
1731 ankur.sing 509
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
510
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 511
        """
1731 ankur.sing 512
        try:
513
            return get_valid_orders_amount_range()
514
        finally:
515
            close_session()
1627 ankur.sing 516
 
1886 ankur.sing 517
    def getValidOrders(self, limit):
518
        """
519
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
520
        If limit is passed as 0, then all valid Orders are returned.
521
 
522
        Parameters:
523
         - limit
524
        """
525
        try:
526
            return [to_t_order(order) for order in get_valid_orders(limit)]
527
        finally:
528
            close_session()
104 ashish 529
 
2536 chandransh 530
    def toggleDOAFlag(self, orderId):
104 ashish 531
        """
2536 chandransh 532
        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.
533
        Returns the final flag status.
534
        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 535
 
132 ashish 536
        Parameters:
2536 chandransh 537
         - orderId
132 ashish 538
        """
2536 chandransh 539
        try:
540
            return toggle_doa_flag(orderId)
541
        finally:
542
            close_session()
483 rajveer 543
 
2536 chandransh 544
    def requestPickupNumber(self, orderId):
104 ashish 545
        """
2536 chandransh 546
        Sends out an email to the account manager of the original courier provider used to ship the order.
547
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUESTED.
548
        If the order status was DOA_PICKUP_REQUESTED, it is left unchanged.
549
        For any other status, it returns false.
550
        Throws an exception if the order with the given id couldn't be found.
104 ashish 551
 
552
        Parameters:
2536 chandransh 553
         - orderId
104 ashish 554
        """
2536 chandransh 555
        try:
556
            return request_pickup_number(orderId)
557
        finally:
558
            close_session()
483 rajveer 559
 
2536 chandransh 560
    def authorizePickup(self, orderId, pickupNumber):
304 ashish 561
        """
2536 chandransh 562
        If the order status is DOA_PICKUP_REQUESTED, it does the following
563
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
564
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
565
            3. Returns true
566
        If the order is any other status, it returns false.
567
        Throws an exception if the order with the given id couldn't be found.
304 ashish 568
 
569
        Parameters:
2536 chandransh 570
         - orderId
571
         - pickupNumber
304 ashish 572
        """
2536 chandransh 573
        try:
574
            return authorize_pickup(orderId, pickupNumber)
575
        finally:
576
            close_session()    
2764 chandransh 577
 
578
    def markDoasAsPickedUp(self, providerId, pickupDetails):
579
        """
580
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
581
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
582
 
583
        Parameters:
584
         - providerId
585
         - pickupDetails
586
        """
587
        try:
588
            orders_not_picked_up = mark_doas_as_picked_up(providerId, pickupDetails)
589
            return [to_t_order(order) for order in orders_not_picked_up]
590
        finally:
591
            close_session()
2591 chandransh 592
 
2616 chandransh 593
    def receiveReturn(self, orderId):
2591 chandransh 594
        """
2599 chandransh 595
        If the order status is DOA_RETURN_AUTHORIZED or DOA_RETURN_IN_TRANSIT, marks the order status as DOA_RECEIVED and returns true.
2591 chandransh 596
        If the order is in any other state, it returns false.
597
        Throws an exception if the order with the given id couldn't be found.
598
 
599
        Parameters:
600
         - orderId
601
        """
602
        try:
2616 chandransh 603
            return receive_return(orderId)
2591 chandransh 604
        finally:
605
            close_session()
606
 
607
    def validateDoa(self, orderId, isValid):
608
        """
2599 chandransh 609
        Used to validate the DOA certificate for an order in the DOA_RECEIVED state. If the certificate is valid,
2609 chandransh 610
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 611
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
612
        If the order is in any other state, it returns false.
613
        Throws an exception if the order with the given id couldn't be found.
614
 
615
        Parameters:
616
         - orderId
617
         - isValid
618
        """
619
        try:
620
            return validate_doa(orderId, isValid)
621
        finally:
622
            close_session()
2628 chandransh 623
 
624
    def reshipOrder(self, orderId):
625
        """
626
        If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
627
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
628
            2. Marks the current order as one of the final states SALES_RET_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
629
 
630
        If the order is in DOA_CERT_VALID state, it does the following:
631
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
632
            2. Creates a return order for the warehouse executive to return the DOA material.
633
            3. Marks the current order as the final DOA_RESHIPPED state.
634
 
635
        Returns the id of the newly created order.
636
 
637
        Throws an exception if the order with the given id couldn't be found.
638
 
639
        Parameters:
640
         - orderId
641
        """
642
        try:
643
            return reship_order(orderId)
644
        finally:
645
            close_session()
646
 
647
    def refundOrder(self, orderId):
648
        """
649
        If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
650
            1. Creates a refund request for batch processing.
651
            2. Creates a return order for the warehouse executive to return the shipped material.
652
            3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
653
 
654
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
655
            1. Creates a refund request for batch processing.
656
            2. Marks the current order as the REFUNDED final state.
657
 
658
        Returns True if it is successful, False otherwise.
659
 
660
        Throws an exception if the order with the given id couldn't be found.
661
 
662
        Parameters:
663
         - orderId
664
        """
665
        try:
666
            return refund_order(orderId)
667
        finally:
668
            close_session()
669
 
2697 chandransh 670
    def getReturnOrders(self, warehouseId, fromDate, toDate):
671
        """
672
        Get all return orders created between the from and to dates for the given warehouse.
673
        Ignores the warehouse if it is passed as -1.
674
 
675
        Parameters:
676
         - warehouseId
677
         - fromDate
678
         - toDate
679
        """
680
        try:
681
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
682
            return get_return_orders(warehouseId, from_date, to_date)
683
        finally:
684
            close_session()
685
 
2700 chandransh 686
    def getReturnOrder(self, id):
687
        """
688
        Returns the ReturnOrder corresponding to the given id.
689
        Throws an exception if the return order with the given id couldn't be found.
690
 
691
        Parameters:
692
         - id
693
        """
694
        try:
695
            return get_return_order(id)
696
        finally:
697
            close_session()
698
 
2697 chandransh 699
    def processReturn(self, returnOrderId):
700
        """
701
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
702
 
703
        Parameters:
704
         - returnOrderId
705
        """
706
        try:
707
            process_return(returnOrderId)
708
        finally:
709
            close_session()
2591 chandransh 710
 
2819 chandransh 711
    def createPurchaseOrder(self, warehouseId):
712
        """
713
        Creates a purchase order corresponding to all the pending orders of the given warehouse.
714
        Returns the PO no. of the newly created purchase order.
715
 
716
        Parameters:
717
         - warehouseId
718
        """
719
        try:
720
            return create_purchase_order(warehouseId)
721
        finally:
722
            close_session()
723
 
2536 chandransh 724
    def closeSession(self, ):
725
        close_session()