Subversion Repositories SmartDukaan

Rev

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