Subversion Repositories SmartDukaan

Rev

Rev 921 | Rev 1113 | 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,\
13
    get_orders_by_billing_date
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()
244
 
483 rajveer 245
    def getAlerts(self, orderId, valid):
246
        """
247
        Parameters:
248
         - orderId
249
         - valid
250
        """
766 rajveer 251
        try:
252
            alerts = get_alerts(orderId, valid)
253
 
254
            t_alerts = []
255
 
256
            for alert in alerts:
257
                t_alerts.append(to_t_alert(alert)) 
258
 
259
            return t_alerts
260
        finally:
261
            close_session()
262
 
483 rajveer 263
    def setAlert(self, orderId, unset, type, comment):
264
        """
265
        Parameters:
266
         - orderId
267
         - unset
268
         - type
269
         - comment
270
        """
766 rajveer 271
        try:
272
            set_alert(orderId, unset, type, comment)
273
        finally:
274
            close_session()
275
 
276
    def closeSession(self, ):
277
        close_session()
104 ashish 278
 
766 rajveer 279
 
280
 
281
    '''
483 rajveer 282
if __name__ == "__main__":
283
    order = OrderServiceHandler()
284
    t = order.getTransaction(4)
285
    print t
286
 
766 rajveer 287
 
483 rajveer 288
    these methods commented right now. may be used later
289
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
104 ashish 290
        """
291
        Parameters:
483 rajveer 292
         - status
104 ashish 293
         - from_date
294
         - to_date
295
        """
296
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
483 rajveer 297
 
298
        transactions = get_all_transactions(current_status, current_from_date, current_to_date, warehouse_id)
104 ashish 299
        t_transaction = []
300
        for transaction in transactions:
301
            t_transaction.append(to_t_transaction(transaction))
302
        return t_transaction
483 rajveer 303
 
304
    def getTransactionsForShipmentStatus(self, status, from_date, to_date):
132 ashish 305
        """
306
        Parameters:
483 rajveer 307
         - status
308
         - from_date
309
         - to_date
132 ashish 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_shipment_status(current_status, current_from_date, current_to_date)
132 ashish 314
        t_transaction = []
315
        for transaction in transactions:
316
            t_transaction.append(to_t_transaction(transaction))
317
        return t_transaction
483 rajveer 318
 
319
    def getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):
104 ashish 320
        """
321
        Parameters:
483 rajveer 322
         - customerId
323
         - from_date
324
         - to_date
104 ashish 325
         - status
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_customer_shipment(customerId, current_from_date, current_to_date, current_status)
330
        t_transaction = []
331
        for transaction in transactions:
332
            t_transaction.append(to_t_transaction(transaction))
333
        return t_transaction
334
 
104 ashish 335
    def getOrderInfo(self, transactionId):
336
        """
337
            Get and set individual objects in it
338
        *
339
 
340
        Parameters:
341
         - transactionId
342
        """
343
        lineitems = get_line_items(transactionId)
344
        order_info = OrderInfo()
345
        order_info.lineitems = []
346
        for lineitem in lineitems:
347
            order_info.lineitems.append(to_t_lineitem(lineitem))
348
            order_info.id = lineitem.transaction.id
349
 
350
        return order_info
351
 
352
    def getShippingInfo(self, transactionId):
353
        """
354
        Parameters:
355
         - transactionId
356
        """
357
        shipments = get_shipments(transactionId)
358
        shipment_info = ShipmentInfo()
359
        shipment_info.shipments = []
360
        for shipment in shipments:
361
            shipment_info.shipments.append(to_t_shipment(shipment))
362
            shipment_info.id = shipment.id
363
        return shipment_info
364
    def getBillingInfo(self, transactionId):
365
        """
366
        Parameters:
367
         - transactionId
368
        """
369
        billings = get_billings(transactionId)
370
        billing_info = BillingInfo()
371
        billing_info.billings = []
372
        if billings:
373
            for billing in billings:
374
                billing_info.billings.append(to_t_billing(billing))
375
                billing_info.id = billing.line_item.transaction.id
376
        return billing_info
377
 
378
    def addBilling(self, transactionId, billing):
379
        """
380
        Parameters:
381
         - tranactionId
382
         - billing
383
        """
384
        return set_billing(transactionId, billing)
385
 
386
    def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):
387
        """
388
        Parameters:
389
         - transactionId
390
         - shippingId
391
         - trackingId
392
         - airwayBillNo
393
         - provider
394
        """
395
        return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)
396
 
397
    def setShippingDate(self, transactionId, shippingId, timestamp):
398
        """
399
        Parameters:
400
         - transactionId
401
         - shippingId
402
         - timestamp
403
        """
404
        return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))
405
 
406
    def setDeliveryDate(self, transactionId, shippingid, timestamp):
407
        """
408
        Parameters:
409
         - transactionId
410
         - shippingid
411
         - timestamp
412
        """
413
        return set_delivery_date(transactionId, shippingid, timestamp)
483 rajveer 414
 
304 ashish 415
    def getAlerts(self, transactionId, valid):
416
        """
417
        Parameters:
418
         - transactionId
419
         - valid
420
        """
421
        alerts = get_alerts(transactionId, valid)
422
 
423
        t_alerts = []
424
 
425
        for alert in alerts:
426
            t_alerts.append(to_t_alert(alert)) 
427
 
428
        return t_alerts
429
 
430
    def setAlert(self, transactionId, unset, type, comment):
431
        """
432
        Parameters:
433
         - transactionId
434
         - unset
435
         - type
436
         - comment
437
        """
438
        set_alert(transactionId, unset, type, comment)
439
 
440
    def getExtraInfo(self, transaction_id):
441
        """
442
        Parameters:
443
         - transaction_id
444
        """
445
        extra_info = get_extra_info(transaction_id)
446
 
447
        return to_t_extra_item_info(extra_info, transaction_id)
448
 
449
 
450
    def setExtraInfo(self, transaction_id, sku_id, model, colour, vendor):
451
        """
452
        Parameters:
453
         - transaction_id
454
         - sku_id
455
         - model
456
         - colour
457
         - vendor
458
        """
459
        set_extra_info(transaction_id, sku_id, model, vendor, colour)
460
 
483 rajveer 461
    '''
104 ashish 462