Subversion Repositories SmartDukaan

Rev

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