Subversion Repositories SmartDukaan

Rev

Rev 1149 | Rev 1220 | 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,\
483 rajveer 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,\
759 chandransh 11
 get_all_orders, change_order_status, get_alerts, set_alert, add_billing_details,\
995 varun.gupt 12
    mark_orders_as_manifested, close_session, accept_order, bill_order,\
1132 chandransh 13
    get_orders_by_billing_date, mark_orders_as_picked_up,\
1208 chandransh 14
    mark_orders_as_delivered, mark_orders_as_failed, add_jacket_number,\
15
    order_outofstock
104 ashish 16
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
483 rajveer 17
    to_t_lineitem, to_t_alert, to_t_order, to_t_lineitem
18
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
19
    LineItem, Order
738 chandransh 20
from shop2020.utils.Utils import to_py_date, get_fdate_tdate
104 ashish 21
 
22
class OrderServiceHandler:
23
 
24
    def __init__(self):
483 rajveer 25
        """
104 ashish 26
        Constructor
483 rajveer 27
        """
104 ashish 28
        DataService.initialize()
29
 
30
    def createTransaction(self, transaction):
31
        """
32
        Parameters:
33
         - transaction
34
        """
766 rajveer 35
        try:
36
            return create_transaction(transaction)
37
        finally:
38
            close_session()
39
 
104 ashish 40
    def getTransaction(self, id):
41
        """
42
            Get transaction methods.
43
 
44
        Parameters:
45
         - id
46
        """
766 rajveer 47
        try:
48
            transaction = get_transaction(id)
49
            return to_t_transaction(transaction)
50
        finally:
51
            close_session()
52
 
483 rajveer 53
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 54
        """
55
        Parameters:
483 rajveer 56
         - customerId
104 ashish 57
         - from_date
58
         - to_date
483 rajveer 59
         - status
104 ashish 60
        """
766 rajveer 61
        try:
62
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
63
 
64
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
65
            t_transaction = []
66
            for transaction in transactions:
67
                t_transaction.append(to_t_transaction(transaction))
68
            return t_transaction
69
        finally:
70
            close_session()
483 rajveer 71
 
72
    def getTransactionsForShoppingCartId(self, shoppingCartId):
73
        """
74
        Parameters:
75
            - shoppingCartId
76
        """
766 rajveer 77
        try:
78
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
79
            t_transaction = []
80
            for transaction in transactions:
81
                t_transaction.append(to_t_transaction(transaction))
82
            return t_transaction
83
        finally:
84
            close_session()
104 ashish 85
 
483 rajveer 86
    def getTransactionStatus(self, transactionId):
104 ashish 87
        """
88
        Parameters:
483 rajveer 89
         - transactionId
90
        """
766 rajveer 91
        try:
92
            return get_transaction_status(transactionId)
93
        finally:
94
            close_session()
95
 
483 rajveer 96
    def changeTransactionStatus(self, transactionId, status, description):
97
        """
98
        Parameters:
99
         - transactionId
104 ashish 100
         - status
483 rajveer 101
         - description
102
        """
766 rajveer 103
        try:
104
            return change_transaction_status(transactionId, status, description)
105
        finally:
106
            close_session()
107
 
483 rajveer 108
    def getOrdersForTransaction(self, transactionId):
109
        """
110
        Parameters:
111
         - transactionId
112
        """
766 rajveer 113
        try:
114
            orders = get_orders_for_transaction(transactionId)
115
            return [to_t_order(order) for order in orders]    
116
        finally:
117
            close_session()
118
 
483 rajveer 119
    def getAllOrders(self, status, from_date, to_date, warehouse_id):
120
        """
121
        Parameters:
122
         - status
104 ashish 123
         - from_date
124
         - to_date
483 rajveer 125
         - warehouse_id
104 ashish 126
        """
766 rajveer 127
        try:
128
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
129
            orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
130
            return [to_t_order(order) for order in orders]
131
        finally:
132
            close_session()
133
 
995 varun.gupt 134
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
135
        """
136
        Parameters:
137
         - status
138
         - start_billing_date
139
         - end_billing_date
140
         - warehouse_id
141
        """
142
        try:
143
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
144
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
145
            return [to_t_order(order) for order in orders]
146
        finally:
147
            close_session()
148
 
483 rajveer 149
    def changeOrderStatus(self, orderId, status, description):
150
        """
151
        Parameters:
152
         - orderId
153
         - status
154
         - description
155
         - 
156
        """
766 rajveer 157
        try:
158
            return change_order_status(self, orderId, status, description)
159
        finally:
160
            close_session()
921 rajveer 161
 
162
    def acceptOrder(self, orderId):
163
        """
164
        Parameters:
165
         - orderId
166
        """
167
        try:
168
            return accept_order(self, orderId)
169
        finally:
170
            close_session()
171
 
172
    def billOrder(self, orderId):
173
        """
174
        Parameters:
175
         - orderId
176
        """
177
        try:
178
            return bill_order(self, orderId)
179
        finally:
180
            close_session()
766 rajveer 181
 
483 rajveer 182
    def getOrdersForCustomer(self, customerId, from_date, to_date, status):
104 ashish 183
        """
184
        Parameters:
185
         - customerId
186
         - from_date
187
         - to_date
188
         - status
189
        """
766 rajveer 190
        try:
191
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
192
 
193
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, status)
194
            return [to_t_order(order) for order in orders]
195
        finally:
196
            close_session()
197
 
483 rajveer 198
    def getOrder(self, id):
199
        """
200
        Parameters:
201
         - id
202
        """
766 rajveer 203
        try:
204
            return to_t_order(get_order(id))
205
        finally:
206
            close_session()
207
 
483 rajveer 208
    def getLineItemsForOrder(self, orderId):
209
        """
210
        Parameters:
211
         - orderId
212
        """
766 rajveer 213
        try:
214
            lineitems = get_line_items_for_order(orderId)
215
            t_lineitems = []
216
            for lineitem in lineitems:
217
                t_lineitems.append(to_t_lineitem(lineitem))
218
            return t_lineitems
219
        finally:
220
            close_session()
1149 chandransh 221
 
222
    def addBillingDetails(self, orderId, invoice_number, billed_by):
494 rajveer 223
        """
1149 chandransh 224
        Add billing details such as the bill number and the biller to the Order.
225
 
494 rajveer 226
        Parameters:
227
         - orderId
228
         - invoice_number
229
         - billed_by
230
        """
766 rajveer 231
        try:
1149 chandransh 232
            return add_billing_details(orderId, invoice_number, billed_by)
766 rajveer 233
        finally:
234
            close_session()
1149 chandransh 235
 
236
    def addJacketNumber(self, orderId, jacketNumber):
237
        """
238
        Adds jacket number to the order. Return false if it doesn't find the order with the given ID.
239
 
240
        Parameters:
241
         - orderId
242
         - jacketNumber
243
        """
244
        try:
245
            return add_jacket_number(orderId, jacketNumber)
246
        finally:
247
            close_session()
1208 chandransh 248
 
249
    def markOrderAsOutOfStock(self, orderId):
250
        """
251
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
252
 
253
 
254
        Parameters:
255
         - orderId
256
        """
257
        try:
258
            return order_outofstock(orderId)
259
        finally:
260
            close_session()
261
 
759 chandransh 262
    def markOrdersAsManifested(self, warehouseId, providerId):
263
        """
264
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
265
 
266
        Parameters:
267
         - warehouseId
268
         - providerId
269
        """
766 rajveer 270
        try:
271
            return mark_orders_as_manifested(warehouseId, providerId)
272
        finally:
273
            close_session()
1113 chandransh 274
 
275
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
276
        """
277
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
278
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
279
        Raises an exception if we encounter report for an AWB number that we did not ship.
280
 
281
        Parameters:
282
         - providerId
283
         - pickupDetails
284
        """
285
        try:
286
            orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
287
            return [to_t_order(order) for order in orders_not_picked_up]
288
        finally:
289
            close_session()
1132 chandransh 290
 
291
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
292
        """
293
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
294
        the name of the receiver.
295
        Raises an exception if we encounter report for an AWB number that we did not ship.
296
 
297
        Parameters:
298
         - providerId
299
         - deliveredOrders
300
        """
301
        try:
302
            mark_orders_as_delivered(providerId, deliveredOrders)
303
        finally:
304
            close_session()
1135 chandransh 305
 
306
    def markOrdersAsFailed(self, providerId, returnedOrders):
307
        """
308
        Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
309
        Raises an exception if we encounter report for an AWB number that we did not ship.
310
 
311
        Parameters:
312
         - providerId
313
         - returnedOrders
314
        """
315
        try:
316
            mark_orders_as_failed(providerId, returnedOrders)
317
        finally:
318
            close_session()
766 rajveer 319
 
483 rajveer 320
    def getAlerts(self, orderId, valid):
321
        """
322
        Parameters:
323
         - orderId
324
         - valid
325
        """
766 rajveer 326
        try:
327
            alerts = get_alerts(orderId, valid)
328
 
329
            t_alerts = []
330
 
331
            for alert in alerts:
332
                t_alerts.append(to_t_alert(alert)) 
333
 
334
            return t_alerts
335
        finally:
336
            close_session()
337
 
483 rajveer 338
    def setAlert(self, orderId, unset, type, comment):
339
        """
340
        Parameters:
341
         - orderId
342
         - unset
343
         - type
344
         - comment
345
        """
766 rajveer 346
        try:
347
            set_alert(orderId, unset, type, comment)
348
        finally:
349
            close_session()
350
 
351
    def closeSession(self, ):
352
        close_session()
104 ashish 353
 
766 rajveer 354
 
355
 
356
    '''
483 rajveer 357
if __name__ == "__main__":
358
    order = OrderServiceHandler()
359
    t = order.getTransaction(4)
360
    print t
361
 
766 rajveer 362
 
483 rajveer 363
    these methods commented right now. may be used later
364
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
104 ashish 365
        """
366
        Parameters:
483 rajveer 367
         - status
104 ashish 368
         - from_date
369
         - to_date
370
        """
371
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
483 rajveer 372
 
373
        transactions = get_all_transactions(current_status, current_from_date, current_to_date, warehouse_id)
104 ashish 374
        t_transaction = []
375
        for transaction in transactions:
376
            t_transaction.append(to_t_transaction(transaction))
377
        return t_transaction
483 rajveer 378
 
379
    def getTransactionsForShipmentStatus(self, status, from_date, to_date):
132 ashish 380
        """
381
        Parameters:
483 rajveer 382
         - status
383
         - from_date
384
         - to_date
132 ashish 385
        """
483 rajveer 386
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
387
 
388
        transactions = get_transactions_for_shipment_status(current_status, current_from_date, current_to_date)
132 ashish 389
        t_transaction = []
390
        for transaction in transactions:
391
            t_transaction.append(to_t_transaction(transaction))
392
        return t_transaction
483 rajveer 393
 
394
    def getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):
104 ashish 395
        """
396
        Parameters:
483 rajveer 397
         - customerId
398
         - from_date
399
         - to_date
104 ashish 400
         - status
401
        """
483 rajveer 402
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
403
 
404
        transactions = get_transactions_for_customer_shipment(customerId, current_from_date, current_to_date, current_status)
405
        t_transaction = []
406
        for transaction in transactions:
407
            t_transaction.append(to_t_transaction(transaction))
408
        return t_transaction
409
 
104 ashish 410
    def getOrderInfo(self, transactionId):
411
        """
412
            Get and set individual objects in it
413
        *
414
 
415
        Parameters:
416
         - transactionId
417
        """
418
        lineitems = get_line_items(transactionId)
419
        order_info = OrderInfo()
420
        order_info.lineitems = []
421
        for lineitem in lineitems:
422
            order_info.lineitems.append(to_t_lineitem(lineitem))
423
            order_info.id = lineitem.transaction.id
424
 
425
        return order_info
426
 
427
    def getShippingInfo(self, transactionId):
428
        """
429
        Parameters:
430
         - transactionId
431
        """
432
        shipments = get_shipments(transactionId)
433
        shipment_info = ShipmentInfo()
434
        shipment_info.shipments = []
435
        for shipment in shipments:
436
            shipment_info.shipments.append(to_t_shipment(shipment))
437
            shipment_info.id = shipment.id
438
        return shipment_info
439
    def getBillingInfo(self, transactionId):
440
        """
441
        Parameters:
442
         - transactionId
443
        """
444
        billings = get_billings(transactionId)
445
        billing_info = BillingInfo()
446
        billing_info.billings = []
447
        if billings:
448
            for billing in billings:
449
                billing_info.billings.append(to_t_billing(billing))
450
                billing_info.id = billing.line_item.transaction.id
451
        return billing_info
452
 
453
    def addBilling(self, transactionId, billing):
454
        """
455
        Parameters:
456
         - tranactionId
457
         - billing
458
        """
459
        return set_billing(transactionId, billing)
460
 
461
    def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):
462
        """
463
        Parameters:
464
         - transactionId
465
         - shippingId
466
         - trackingId
467
         - airwayBillNo
468
         - provider
469
        """
470
        return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)
471
 
472
    def setShippingDate(self, transactionId, shippingId, timestamp):
473
        """
474
        Parameters:
475
         - transactionId
476
         - shippingId
477
         - timestamp
478
        """
479
        return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))
480
 
481
    def setDeliveryDate(self, transactionId, shippingid, timestamp):
482
        """
483
        Parameters:
484
         - transactionId
485
         - shippingid
486
         - timestamp
487
        """
488
        return set_delivery_date(transactionId, shippingid, timestamp)
483 rajveer 489
 
304 ashish 490
    def getAlerts(self, transactionId, valid):
491
        """
492
        Parameters:
493
         - transactionId
494
         - valid
495
        """
496
        alerts = get_alerts(transactionId, valid)
497
 
498
        t_alerts = []
499
 
500
        for alert in alerts:
501
            t_alerts.append(to_t_alert(alert)) 
502
 
503
        return t_alerts
504
 
505
    def setAlert(self, transactionId, unset, type, comment):
506
        """
507
        Parameters:
508
         - transactionId
509
         - unset
510
         - type
511
         - comment
512
        """
513
        set_alert(transactionId, unset, type, comment)
514
 
515
    def getExtraInfo(self, transaction_id):
516
        """
517
        Parameters:
518
         - transaction_id
519
        """
520
        extra_info = get_extra_info(transaction_id)
521
 
522
        return to_t_extra_item_info(extra_info, transaction_id)
523
 
524
 
525
    def setExtraInfo(self, transaction_id, sku_id, model, colour, vendor):
526
        """
527
        Parameters:
528
         - transaction_id
529
         - sku_id
530
         - model
531
         - colour
532
         - vendor
533
        """
534
        set_extra_info(transaction_id, sku_id, model, vendor, colour)
535
 
483 rajveer 536
    '''
104 ashish 537