Subversion Repositories SmartDukaan

Rev

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