Subversion Repositories SmartDukaan

Rev

Rev 759 | Rev 921 | 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,\
766 rajveer 12
    mark_orders_as_manifested, close_session
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()
143
 
483 rajveer 144
    def getOrdersForCustomer(self, customerId, from_date, to_date, status):
104 ashish 145
        """
146
        Parameters:
147
         - customerId
148
         - from_date
149
         - to_date
150
         - status
151
        """
766 rajveer 152
        try:
153
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
154
 
155
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, status)
156
            return [to_t_order(order) for order in orders]
157
        finally:
158
            close_session()
159
 
483 rajveer 160
    def getOrder(self, id):
161
        """
162
        Parameters:
163
         - id
164
        """
766 rajveer 165
        try:
166
            return to_t_order(get_order(id))
167
        finally:
168
            close_session()
169
 
483 rajveer 170
    def getLineItemsForOrder(self, orderId):
171
        """
172
        Parameters:
173
         - orderId
174
        """
766 rajveer 175
        try:
176
            lineitems = get_line_items_for_order(orderId)
177
            t_lineitems = []
178
            for lineitem in lineitems:
179
                t_lineitems.append(to_t_lineitem(lineitem))
180
            return t_lineitems
181
        finally:
182
            close_session()
183
 
642 chandransh 184
    def addBillingDetails(self, orderId, invoice_number, jacket_number, billed_by):
494 rajveer 185
        """
186
        Parameters:
187
         - orderId
188
         - invoice_number
189
         - billed_by
190
        """
766 rajveer 191
        try:
192
            return add_billing_details(orderId, invoice_number, jacket_number, billed_by)
193
        finally:
194
            close_session()
195
 
759 chandransh 196
    def markOrdersAsManifested(self, warehouseId, providerId):
197
        """
198
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
199
 
200
        Parameters:
201
         - warehouseId
202
         - providerId
203
        """
766 rajveer 204
        try:
205
            return mark_orders_as_manifested(warehouseId, providerId)
206
        finally:
207
            close_session()
208
 
483 rajveer 209
    def getAlerts(self, orderId, valid):
210
        """
211
        Parameters:
212
         - orderId
213
         - valid
214
        """
766 rajveer 215
        try:
216
            alerts = get_alerts(orderId, valid)
217
 
218
            t_alerts = []
219
 
220
            for alert in alerts:
221
                t_alerts.append(to_t_alert(alert)) 
222
 
223
            return t_alerts
224
        finally:
225
            close_session()
226
 
483 rajveer 227
    def setAlert(self, orderId, unset, type, comment):
228
        """
229
        Parameters:
230
         - orderId
231
         - unset
232
         - type
233
         - comment
234
        """
766 rajveer 235
        try:
236
            set_alert(orderId, unset, type, comment)
237
        finally:
238
            close_session()
239
 
240
    def closeSession(self, ):
241
        close_session()
104 ashish 242
 
766 rajveer 243
 
244
 
245
    '''
483 rajveer 246
if __name__ == "__main__":
247
    order = OrderServiceHandler()
248
    t = order.getTransaction(4)
249
    print t
250
 
766 rajveer 251
 
483 rajveer 252
    these methods commented right now. may be used later
253
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
104 ashish 254
        """
255
        Parameters:
483 rajveer 256
         - status
104 ashish 257
         - from_date
258
         - to_date
259
        """
260
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
483 rajveer 261
 
262
        transactions = get_all_transactions(current_status, current_from_date, current_to_date, warehouse_id)
104 ashish 263
        t_transaction = []
264
        for transaction in transactions:
265
            t_transaction.append(to_t_transaction(transaction))
266
        return t_transaction
483 rajveer 267
 
268
    def getTransactionsForShipmentStatus(self, status, from_date, to_date):
132 ashish 269
        """
270
        Parameters:
483 rajveer 271
         - status
272
         - from_date
273
         - to_date
132 ashish 274
        """
483 rajveer 275
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
276
 
277
        transactions = get_transactions_for_shipment_status(current_status, current_from_date, current_to_date)
132 ashish 278
        t_transaction = []
279
        for transaction in transactions:
280
            t_transaction.append(to_t_transaction(transaction))
281
        return t_transaction
483 rajveer 282
 
283
    def getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):
104 ashish 284
        """
285
        Parameters:
483 rajveer 286
         - customerId
287
         - from_date
288
         - to_date
104 ashish 289
         - status
290
        """
483 rajveer 291
        current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
292
 
293
        transactions = get_transactions_for_customer_shipment(customerId, current_from_date, current_to_date, current_status)
294
        t_transaction = []
295
        for transaction in transactions:
296
            t_transaction.append(to_t_transaction(transaction))
297
        return t_transaction
298
 
104 ashish 299
    def getOrderInfo(self, transactionId):
300
        """
301
            Get and set individual objects in it
302
        *
303
 
304
        Parameters:
305
         - transactionId
306
        """
307
        lineitems = get_line_items(transactionId)
308
        order_info = OrderInfo()
309
        order_info.lineitems = []
310
        for lineitem in lineitems:
311
            order_info.lineitems.append(to_t_lineitem(lineitem))
312
            order_info.id = lineitem.transaction.id
313
 
314
        return order_info
315
 
316
    def getShippingInfo(self, transactionId):
317
        """
318
        Parameters:
319
         - transactionId
320
        """
321
        shipments = get_shipments(transactionId)
322
        shipment_info = ShipmentInfo()
323
        shipment_info.shipments = []
324
        for shipment in shipments:
325
            shipment_info.shipments.append(to_t_shipment(shipment))
326
            shipment_info.id = shipment.id
327
        return shipment_info
328
    def getBillingInfo(self, transactionId):
329
        """
330
        Parameters:
331
         - transactionId
332
        """
333
        billings = get_billings(transactionId)
334
        billing_info = BillingInfo()
335
        billing_info.billings = []
336
        if billings:
337
            for billing in billings:
338
                billing_info.billings.append(to_t_billing(billing))
339
                billing_info.id = billing.line_item.transaction.id
340
        return billing_info
341
 
342
    def addBilling(self, transactionId, billing):
343
        """
344
        Parameters:
345
         - tranactionId
346
         - billing
347
        """
348
        return set_billing(transactionId, billing)
349
 
350
    def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):
351
        """
352
        Parameters:
353
         - transactionId
354
         - shippingId
355
         - trackingId
356
         - airwayBillNo
357
         - provider
358
        """
359
        return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)
360
 
361
    def setShippingDate(self, transactionId, shippingId, timestamp):
362
        """
363
        Parameters:
364
         - transactionId
365
         - shippingId
366
         - timestamp
367
        """
368
        return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))
369
 
370
    def setDeliveryDate(self, transactionId, shippingid, timestamp):
371
        """
372
        Parameters:
373
         - transactionId
374
         - shippingid
375
         - timestamp
376
        """
377
        return set_delivery_date(transactionId, shippingid, timestamp)
483 rajveer 378
 
304 ashish 379
    def getAlerts(self, transactionId, valid):
380
        """
381
        Parameters:
382
         - transactionId
383
         - valid
384
        """
385
        alerts = get_alerts(transactionId, valid)
386
 
387
        t_alerts = []
388
 
389
        for alert in alerts:
390
            t_alerts.append(to_t_alert(alert)) 
391
 
392
        return t_alerts
393
 
394
    def setAlert(self, transactionId, unset, type, comment):
395
        """
396
        Parameters:
397
         - transactionId
398
         - unset
399
         - type
400
         - comment
401
        """
402
        set_alert(transactionId, unset, type, comment)
403
 
404
    def getExtraInfo(self, transaction_id):
405
        """
406
        Parameters:
407
         - transaction_id
408
        """
409
        extra_info = get_extra_info(transaction_id)
410
 
411
        return to_t_extra_item_info(extra_info, transaction_id)
412
 
413
 
414
    def setExtraInfo(self, transaction_id, sku_id, model, colour, vendor):
415
        """
416
        Parameters:
417
         - transaction_id
418
         - sku_id
419
         - model
420
         - colour
421
         - vendor
422
        """
423
        set_extra_info(transaction_id, sku_id, model, vendor, colour)
424
 
483 rajveer 425
    '''
104 ashish 426