Subversion Repositories SmartDukaan

Rev

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