Subversion Repositories SmartDukaan

Rev

Rev 1113 | Rev 1135 | 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,\
14
    mark_orders_as_delivered
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()
220
 
642 chandransh 221
    def addBillingDetails(self, orderId, invoice_number, jacket_number, billed_by):
494 rajveer 222
        """
223
        Parameters:
224
         - orderId
225
         - invoice_number
226
         - billed_by
227
        """
766 rajveer 228
        try:
229
            return add_billing_details(orderId, invoice_number, jacket_number, billed_by)
230
        finally:
231
            close_session()
232
 
759 chandransh 233
    def markOrdersAsManifested(self, warehouseId, providerId):
234
        """
235
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
236
 
237
        Parameters:
238
         - warehouseId
239
         - providerId
240
        """
766 rajveer 241
        try:
242
            return mark_orders_as_manifested(warehouseId, providerId)
243
        finally:
244
            close_session()
1113 chandransh 245
 
246
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
247
        """
248
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
249
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
250
        Raises an exception if we encounter report for an AWB number that we did not ship.
251
 
252
        Parameters:
253
         - providerId
254
         - pickupDetails
255
        """
256
        try:
257
            orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
258
            return [to_t_order(order) for order in orders_not_picked_up]
259
        finally:
260
            close_session()
1132 chandransh 261
 
262
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
263
        """
264
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
265
        the name of the receiver.
266
        Raises an exception if we encounter report for an AWB number that we did not ship.
267
 
268
        Parameters:
269
         - providerId
270
         - deliveredOrders
271
        """
272
        try:
273
            mark_orders_as_delivered(providerId, deliveredOrders)
274
        finally:
275
            close_session()
766 rajveer 276
 
483 rajveer 277
    def getAlerts(self, orderId, valid):
278
        """
279
        Parameters:
280
         - orderId
281
         - valid
282
        """
766 rajveer 283
        try:
284
            alerts = get_alerts(orderId, valid)
285
 
286
            t_alerts = []
287
 
288
            for alert in alerts:
289
                t_alerts.append(to_t_alert(alert)) 
290
 
291
            return t_alerts
292
        finally:
293
            close_session()
294
 
483 rajveer 295
    def setAlert(self, orderId, unset, type, comment):
296
        """
297
        Parameters:
298
         - orderId
299
         - unset
300
         - type
301
         - comment
302
        """
766 rajveer 303
        try:
304
            set_alert(orderId, unset, type, comment)
305
        finally:
306
            close_session()
307
 
308
    def closeSession(self, ):
309
        close_session()
104 ashish 310
 
766 rajveer 311
 
312
 
313
    '''
483 rajveer 314
if __name__ == "__main__":
315
    order = OrderServiceHandler()
316
    t = order.getTransaction(4)
317
    print t
318
 
766 rajveer 319
 
483 rajveer 320
    these methods commented right now. may be used later
321
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
104 ashish 322
        """
323
        Parameters:
483 rajveer 324
         - status
104 ashish 325
         - from_date
326
         - to_date
327
        """
328
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
483 rajveer 329
 
330
        transactions = get_all_transactions(current_status, current_from_date, current_to_date, warehouse_id)
104 ashish 331
        t_transaction = []
332
        for transaction in transactions:
333
            t_transaction.append(to_t_transaction(transaction))
334
        return t_transaction
483 rajveer 335
 
336
    def getTransactionsForShipmentStatus(self, status, from_date, to_date):
132 ashish 337
        """
338
        Parameters:
483 rajveer 339
         - status
340
         - from_date
341
         - to_date
132 ashish 342
        """
483 rajveer 343
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
344
 
345
        transactions = get_transactions_for_shipment_status(current_status, current_from_date, current_to_date)
132 ashish 346
        t_transaction = []
347
        for transaction in transactions:
348
            t_transaction.append(to_t_transaction(transaction))
349
        return t_transaction
483 rajveer 350
 
351
    def getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):
104 ashish 352
        """
353
        Parameters:
483 rajveer 354
         - customerId
355
         - from_date
356
         - to_date
104 ashish 357
         - status
358
        """
483 rajveer 359
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
360
 
361
        transactions = get_transactions_for_customer_shipment(customerId, current_from_date, current_to_date, current_status)
362
        t_transaction = []
363
        for transaction in transactions:
364
            t_transaction.append(to_t_transaction(transaction))
365
        return t_transaction
366
 
104 ashish 367
    def getOrderInfo(self, transactionId):
368
        """
369
            Get and set individual objects in it
370
        *
371
 
372
        Parameters:
373
         - transactionId
374
        """
375
        lineitems = get_line_items(transactionId)
376
        order_info = OrderInfo()
377
        order_info.lineitems = []
378
        for lineitem in lineitems:
379
            order_info.lineitems.append(to_t_lineitem(lineitem))
380
            order_info.id = lineitem.transaction.id
381
 
382
        return order_info
383
 
384
    def getShippingInfo(self, transactionId):
385
        """
386
        Parameters:
387
         - transactionId
388
        """
389
        shipments = get_shipments(transactionId)
390
        shipment_info = ShipmentInfo()
391
        shipment_info.shipments = []
392
        for shipment in shipments:
393
            shipment_info.shipments.append(to_t_shipment(shipment))
394
            shipment_info.id = shipment.id
395
        return shipment_info
396
    def getBillingInfo(self, transactionId):
397
        """
398
        Parameters:
399
         - transactionId
400
        """
401
        billings = get_billings(transactionId)
402
        billing_info = BillingInfo()
403
        billing_info.billings = []
404
        if billings:
405
            for billing in billings:
406
                billing_info.billings.append(to_t_billing(billing))
407
                billing_info.id = billing.line_item.transaction.id
408
        return billing_info
409
 
410
    def addBilling(self, transactionId, billing):
411
        """
412
        Parameters:
413
         - tranactionId
414
         - billing
415
        """
416
        return set_billing(transactionId, billing)
417
 
418
    def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):
419
        """
420
        Parameters:
421
         - transactionId
422
         - shippingId
423
         - trackingId
424
         - airwayBillNo
425
         - provider
426
        """
427
        return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)
428
 
429
    def setShippingDate(self, transactionId, shippingId, timestamp):
430
        """
431
        Parameters:
432
         - transactionId
433
         - shippingId
434
         - timestamp
435
        """
436
        return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))
437
 
438
    def setDeliveryDate(self, transactionId, shippingid, timestamp):
439
        """
440
        Parameters:
441
         - transactionId
442
         - shippingid
443
         - timestamp
444
        """
445
        return set_delivery_date(transactionId, shippingid, timestamp)
483 rajveer 446
 
304 ashish 447
    def getAlerts(self, transactionId, valid):
448
        """
449
        Parameters:
450
         - transactionId
451
         - valid
452
        """
453
        alerts = get_alerts(transactionId, valid)
454
 
455
        t_alerts = []
456
 
457
        for alert in alerts:
458
            t_alerts.append(to_t_alert(alert)) 
459
 
460
        return t_alerts
461
 
462
    def setAlert(self, transactionId, unset, type, comment):
463
        """
464
        Parameters:
465
         - transactionId
466
         - unset
467
         - type
468
         - comment
469
        """
470
        set_alert(transactionId, unset, type, comment)
471
 
472
    def getExtraInfo(self, transaction_id):
473
        """
474
        Parameters:
475
         - transaction_id
476
        """
477
        extra_info = get_extra_info(transaction_id)
478
 
479
        return to_t_extra_item_info(extra_info, transaction_id)
480
 
481
 
482
    def setExtraInfo(self, transaction_id, sku_id, model, colour, vendor):
483
        """
484
        Parameters:
485
         - transaction_id
486
         - sku_id
487
         - model
488
         - colour
489
         - vendor
490
        """
491
        set_extra_info(transaction_id, sku_id, model, vendor, colour)
492
 
483 rajveer 493
    '''
104 ashish 494