Subversion Repositories SmartDukaan

Rev

Rev 2783 | Rev 2842 | 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,\
21
    create_purchase_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
 
195
    def acceptOrder(self, orderId):
196
        """
197
        Parameters:
198
         - orderId
199
        """
200
        try:
201
            return accept_order(self, orderId)
202
        finally:
203
            close_session()
204
 
205
    def billOrder(self, orderId):
206
        """
207
        Parameters:
208
         - orderId
209
        """
210
        try:
211
            return bill_order(self, orderId)
212
        finally:
213
            close_session()
766 rajveer 214
 
483 rajveer 215
    def getOrdersForCustomer(self, customerId, from_date, to_date, status):
104 ashish 216
        """
217
        Parameters:
218
         - customerId
219
         - from_date
220
         - to_date
221
         - status
222
        """
766 rajveer 223
        try:
224
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
225
 
226
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, status)
227
            return [to_t_order(order) for order in orders]
228
        finally:
229
            close_session()
1528 ankur.sing 230
 
231
    def getOrderForCustomer(self, orderId, customerId):
232
        """
233
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
234
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
235
 
236
        Parameters:
237
         - customerId
238
         - orderId
239
        """
240
        try:
241
            return to_t_order(get_order_for_customer(orderId, customerId))
242
        finally:
243
            close_session()
766 rajveer 244
 
483 rajveer 245
    def getOrder(self, id):
246
        """
247
        Parameters:
248
         - id
249
        """
766 rajveer 250
        try:
251
            return to_t_order(get_order(id))
252
        finally:
253
            close_session()
254
 
483 rajveer 255
    def getLineItemsForOrder(self, orderId):
256
        """
257
        Parameters:
258
         - orderId
259
        """
766 rajveer 260
        try:
261
            lineitems = get_line_items_for_order(orderId)
262
            t_lineitems = []
263
            for lineitem in lineitems:
264
                t_lineitems.append(to_t_lineitem(lineitem))
265
            return t_lineitems
266
        finally:
267
            close_session()
1149 chandransh 268
 
269
    def addBillingDetails(self, orderId, invoice_number, billed_by):
494 rajveer 270
        """
1149 chandransh 271
        Add billing details such as the bill number and the biller to the Order.
272
 
494 rajveer 273
        Parameters:
274
         - orderId
275
         - invoice_number
276
         - billed_by
277
        """
766 rajveer 278
        try:
1149 chandransh 279
            return add_billing_details(orderId, invoice_number, billed_by)
766 rajveer 280
        finally:
281
            close_session()
1149 chandransh 282
 
2783 chandransh 283
    def addJacketNumber(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy):
1149 chandransh 284
        """
2783 chandransh 285
        Adds jacket number and IMEI no. to the order. Doesn't update the IMEI no. if a -1 is supplied.
286
        Also marks the order as billed and sets the billing timestamp.
287
        Return false if it doesn't find the order with the given ID.
1149 chandransh 288
 
289
        Parameters:
290
         - orderId
291
         - jacketNumber
2783 chandransh 292
         - imeiNumber
293
         - itemNumber
294
         - billedBy
1149 chandransh 295
        """
296
        try:
2783 chandransh 297
            return add_jacket_number(self, orderId, jacketNumber, imeiNumber, itemNumber, billedBy)
298
        except TransactionServiceException:
299
            print "ERROR: Couldn't find the order with the given id"
300
            return False
1149 chandransh 301
        finally:
302
            close_session()
1220 chandransh 303
 
304
    def batchOrders(self, warehouseId):
305
        """
306
        Create a batch of all the pending orders for the given warehouse.
307
        The returned list is orderd by created_timestamp.
308
        If there are no pending orders, an empty list is returned.
1208 chandransh 309
 
1220 chandransh 310
        Parameters:
311
         - warehouseId
312
        """
313
        try:
314
            pending_orders = batch_orders(warehouseId)
315
            return [to_t_order(order) for order in pending_orders]
316
        finally:
317
            close_session()
318
 
1208 chandransh 319
    def markOrderAsOutOfStock(self, orderId):
320
        """
321
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
322
 
323
 
324
        Parameters:
325
         - orderId
326
        """
327
        try:
328
            return order_outofstock(orderId)
329
        finally:
330
            close_session()
331
 
759 chandransh 332
    def markOrdersAsManifested(self, warehouseId, providerId):
333
        """
334
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
335
 
336
        Parameters:
337
         - warehouseId
338
         - providerId
339
        """
766 rajveer 340
        try:
341
            return mark_orders_as_manifested(warehouseId, providerId)
342
        finally:
343
            close_session()
1113 chandransh 344
 
345
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
346
        """
347
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
348
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
349
        Raises an exception if we encounter report for an AWB number that we did not ship.
350
 
351
        Parameters:
352
         - providerId
353
         - pickupDetails
354
        """
355
        try:
356
            orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
357
            return [to_t_order(order) for order in orders_not_picked_up]
358
        finally:
359
            close_session()
1132 chandransh 360
 
361
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
362
        """
363
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
364
        the name of the receiver.
365
        Raises an exception if we encounter report for an AWB number that we did not ship.
366
 
367
        Parameters:
368
         - providerId
369
         - deliveredOrders
370
        """
371
        try:
372
            mark_orders_as_delivered(providerId, deliveredOrders)
373
        finally:
374
            close_session()
1135 chandransh 375
 
376
    def markOrdersAsFailed(self, providerId, returnedOrders):
377
        """
378
        Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
379
        Raises an exception if we encounter report for an AWB number that we did not ship.
380
 
381
        Parameters:
382
         - providerId
383
         - returnedOrders
384
        """
385
        try:
386
            mark_orders_as_failed(providerId, returnedOrders)
387
        finally:
388
            close_session()
1246 chandransh 389
 
390
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
391
        """
392
        Update the status description of orders whose AWB numbers are keys of the Map.
393
 
394
        Parameters:
395
         - providerId
396
         - undelivered_orders
397
        """
398
        try:
399
            update_non_delivery_reason(providerId, undeliveredOrders)
400
        finally:
401
            close_session()
1405 ankur.sing 402
 
403
    def getUndeliveredOrders(self, providerId, warehouseId):
404
        """
405
        Returns the list of orders whose delivery time has passed but have not been
406
        delivered yet for the given provider and warehouse. To get a complete list of
407
        undelivered orders, pass them as -1.
408
        Returns an empty list if no such orders exist.
409
 
410
        Parameters:
411
         - providerId
412
         - warehouseId
413
        """
414
        try:
415
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
416
            return [to_t_order(order) for order in undelivered_orders]
417
        finally:
418
            close_session()
1351 varun.gupt 419
 
1398 varun.gupt 420
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 421
        """
1398 varun.gupt 422
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 423
 
424
        Parameters:
425
         - transactionId
426
        """
427
        try:
1398 varun.gupt 428
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 429
        finally:
430
            close_session()
431
 
483 rajveer 432
    def getAlerts(self, orderId, valid):
433
        """
434
        Parameters:
435
         - orderId
436
         - valid
437
        """
766 rajveer 438
        try:
439
            alerts = get_alerts(orderId, valid)
440
 
441
            t_alerts = []
442
 
443
            for alert in alerts:
444
                t_alerts.append(to_t_alert(alert)) 
445
 
446
            return t_alerts
447
        finally:
448
            close_session()
449
 
483 rajveer 450
    def setAlert(self, orderId, unset, type, comment):
451
        """
452
        Parameters:
453
         - orderId
454
         - unset
455
         - type
456
         - comment
457
        """
766 rajveer 458
        try:
459
            set_alert(orderId, unset, type, comment)
460
        finally:
461
            close_session()
1596 ankur.sing 462
 
463
    def getValidOrderCount(self, ):
464
        """
465
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
466
        """
1731 ankur.sing 467
        try:
468
            return get_valid_order_count()
469
        finally:
470
            close_session()
1627 ankur.sing 471
 
472
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
473
        """
474
        Returns the number of distinct customers who have done successful transactions
475
        """
1731 ankur.sing 476
        try:
477
            return get_cust_count_with_successful_txn()
478
        finally:
479
            close_session()
1627 ankur.sing 480
 
1731 ankur.sing 481
 
482
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 483
        """
1731 ankur.sing 484
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
485
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 486
        """
1731 ankur.sing 487
        try:
488
            return get_valid_orders_amount_range()
489
        finally:
490
            close_session()
1627 ankur.sing 491
 
1886 ankur.sing 492
    def getValidOrders(self, limit):
493
        """
494
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
495
        If limit is passed as 0, then all valid Orders are returned.
496
 
497
        Parameters:
498
         - limit
499
        """
500
        try:
501
            return [to_t_order(order) for order in get_valid_orders(limit)]
502
        finally:
503
            close_session()
104 ashish 504
 
2536 chandransh 505
    def toggleDOAFlag(self, orderId):
104 ashish 506
        """
2536 chandransh 507
        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.
508
        Returns the final flag status.
509
        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 510
 
132 ashish 511
        Parameters:
2536 chandransh 512
         - orderId
132 ashish 513
        """
2536 chandransh 514
        try:
515
            return toggle_doa_flag(orderId)
516
        finally:
517
            close_session()
483 rajveer 518
 
2536 chandransh 519
    def requestPickupNumber(self, orderId):
104 ashish 520
        """
2536 chandransh 521
        Sends out an email to the account manager of the original courier provider used to ship the order.
522
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUESTED.
523
        If the order status was DOA_PICKUP_REQUESTED, it is left unchanged.
524
        For any other status, it returns false.
525
        Throws an exception if the order with the given id couldn't be found.
104 ashish 526
 
527
        Parameters:
2536 chandransh 528
         - orderId
104 ashish 529
        """
2536 chandransh 530
        try:
531
            return request_pickup_number(orderId)
532
        finally:
533
            close_session()
483 rajveer 534
 
2536 chandransh 535
    def authorizePickup(self, orderId, pickupNumber):
304 ashish 536
        """
2536 chandransh 537
        If the order status is DOA_PICKUP_REQUESTED, it does the following
538
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
539
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
540
            3. Returns true
541
        If the order is any other status, it returns false.
542
        Throws an exception if the order with the given id couldn't be found.
304 ashish 543
 
544
        Parameters:
2536 chandransh 545
         - orderId
546
         - pickupNumber
304 ashish 547
        """
2536 chandransh 548
        try:
549
            return authorize_pickup(orderId, pickupNumber)
550
        finally:
551
            close_session()    
2764 chandransh 552
 
553
    def markDoasAsPickedUp(self, providerId, pickupDetails):
554
        """
555
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
556
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
557
 
558
        Parameters:
559
         - providerId
560
         - pickupDetails
561
        """
562
        try:
563
            orders_not_picked_up = mark_doas_as_picked_up(providerId, pickupDetails)
564
            return [to_t_order(order) for order in orders_not_picked_up]
565
        finally:
566
            close_session()
2591 chandransh 567
 
2616 chandransh 568
    def receiveReturn(self, orderId):
2591 chandransh 569
        """
2599 chandransh 570
        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 571
        If the order is in any other state, it returns false.
572
        Throws an exception if the order with the given id couldn't be found.
573
 
574
        Parameters:
575
         - orderId
576
        """
577
        try:
2616 chandransh 578
            return receive_return(orderId)
2591 chandransh 579
        finally:
580
            close_session()
581
 
582
    def validateDoa(self, orderId, isValid):
583
        """
2599 chandransh 584
        Used to validate the DOA certificate for an order in the DOA_RECEIVED state. If the certificate is valid,
2609 chandransh 585
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 586
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
587
        If the order is in any other state, it returns false.
588
        Throws an exception if the order with the given id couldn't be found.
589
 
590
        Parameters:
591
         - orderId
592
         - isValid
593
        """
594
        try:
595
            return validate_doa(orderId, isValid)
596
        finally:
597
            close_session()
2628 chandransh 598
 
599
    def reshipOrder(self, orderId):
600
        """
601
        If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
602
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
603
            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.
604
 
605
        If the order is in DOA_CERT_VALID state, it does the following:
606
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
607
            2. Creates a return order for the warehouse executive to return the DOA material.
608
            3. Marks the current order as the final DOA_RESHIPPED state.
609
 
610
        Returns the id of the newly created order.
611
 
612
        Throws an exception if the order with the given id couldn't be found.
613
 
614
        Parameters:
615
         - orderId
616
        """
617
        try:
618
            return reship_order(orderId)
619
        finally:
620
            close_session()
621
 
622
    def refundOrder(self, orderId):
623
        """
624
        If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
625
            1. Creates a refund request for batch processing.
626
            2. Creates a return order for the warehouse executive to return the shipped material.
627
            3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
628
 
629
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
630
            1. Creates a refund request for batch processing.
631
            2. Marks the current order as the REFUNDED final state.
632
 
633
        Returns True if it is successful, False otherwise.
634
 
635
        Throws an exception if the order with the given id couldn't be found.
636
 
637
        Parameters:
638
         - orderId
639
        """
640
        try:
641
            return refund_order(orderId)
642
        finally:
643
            close_session()
644
 
2697 chandransh 645
    def getReturnOrders(self, warehouseId, fromDate, toDate):
646
        """
647
        Get all return orders created between the from and to dates for the given warehouse.
648
        Ignores the warehouse if it is passed as -1.
649
 
650
        Parameters:
651
         - warehouseId
652
         - fromDate
653
         - toDate
654
        """
655
        try:
656
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
657
            return get_return_orders(warehouseId, from_date, to_date)
658
        finally:
659
            close_session()
660
 
2700 chandransh 661
    def getReturnOrder(self, id):
662
        """
663
        Returns the ReturnOrder corresponding to the given id.
664
        Throws an exception if the return order with the given id couldn't be found.
665
 
666
        Parameters:
667
         - id
668
        """
669
        try:
670
            return get_return_order(id)
671
        finally:
672
            close_session()
673
 
2697 chandransh 674
    def processReturn(self, returnOrderId):
675
        """
676
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
677
 
678
        Parameters:
679
         - returnOrderId
680
        """
681
        try:
682
            process_return(returnOrderId)
683
        finally:
684
            close_session()
2591 chandransh 685
 
2819 chandransh 686
    def createPurchaseOrder(self, warehouseId):
687
        """
688
        Creates a purchase order corresponding to all the pending orders of the given warehouse.
689
        Returns the PO no. of the newly created purchase order.
690
 
691
        Parameters:
692
         - warehouseId
693
        """
694
        try:
695
            return create_purchase_order(warehouseId)
696
        finally:
697
            close_session()
698
 
2536 chandransh 699
    def closeSession(self, ):
700
        close_session()