Subversion Repositories SmartDukaan

Rev

Rev 759 | Rev 921 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 759 Rev 766
Line 7... Line 7...
7
from shop2020.model.v1.order.impl.DataAccessors import create_transaction,\
7
from shop2020.model.v1.order.impl.DataAccessors import create_transaction,\
8
create_order, get_new_transaction, get_transactions_for_customer, get_transaction_status,\
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,\
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,\
10
 change_transaction_status, get_orders_for_customer,get_orders_for_transaction, get_order,\
11
 get_all_orders, change_order_status, get_alerts, set_alert, add_billing_details,\
11
 get_all_orders, change_order_status, get_alerts, set_alert, add_billing_details,\
12
    mark_orders_as_manifested
12
    mark_orders_as_manifested, close_session
13
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
13
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
14
    to_t_lineitem, to_t_alert, to_t_order, to_t_lineitem
14
    to_t_lineitem, to_t_alert, to_t_order, to_t_lineitem
15
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
15
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
16
    LineItem, Order
16
    LineItem, Order
17
from shop2020.utils.Utils import to_py_date, get_fdate_tdate
17
from shop2020.utils.Utils import to_py_date, get_fdate_tdate
Line 27... Line 27...
27
    def createTransaction(self, transaction):
27
    def createTransaction(self, transaction):
28
        """
28
        """
29
        Parameters:
29
        Parameters:
30
         - transaction
30
         - transaction
31
        """
31
        """
-
 
32
        try:
32
        return create_transaction(transaction)
33
            return create_transaction(transaction)
-
 
34
        finally:
-
 
35
            close_session()
33
 
36
        
34
    def getTransaction(self, id):
37
    def getTransaction(self, id):
35
        """
38
        """
36
            Get transaction methods.
39
            Get transaction methods.
37
        
40
        
38
        Parameters:
41
        Parameters:
39
         - id
42
         - id
40
        """
43
        """
-
 
44
        try:
41
        transaction = get_transaction(id)
45
            transaction = get_transaction(id)
42
        return to_t_transaction(transaction)
46
            return to_t_transaction(transaction)
-
 
47
        finally:
-
 
48
            close_session()
43
    
49
            
44
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
50
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
45
        """
51
        """
46
        Parameters:
52
        Parameters:
47
         - customerId
53
         - customerId
48
         - from_date
54
         - from_date
49
         - to_date
55
         - to_date
50
         - status
56
         - status
51
        """
57
        """
-
 
58
        try:
52
        current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
59
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
53
                
60
                    
54
        transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
61
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
55
        t_transaction = []
62
            t_transaction = []
56
        for transaction in transactions:
63
            for transaction in transactions:
57
            t_transaction.append(to_t_transaction(transaction))
64
                t_transaction.append(to_t_transaction(transaction))
58
        return t_transaction
65
            return t_transaction
59
 
66
        finally:
-
 
67
            close_session()
60
 
68
 
61
    def getTransactionsForShoppingCartId(self, shoppingCartId):
69
    def getTransactionsForShoppingCartId(self, shoppingCartId):
62
        """
70
        """
63
        Parameters:
71
        Parameters:
64
            - shoppingCartId
72
            - shoppingCartId
65
        """
73
        """
-
 
74
        try:
66
        transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
75
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
67
        t_transaction = []
76
            t_transaction = []
68
        for transaction in transactions:
77
            for transaction in transactions:
69
            t_transaction.append(to_t_transaction(transaction))
78
                t_transaction.append(to_t_transaction(transaction))
70
        return t_transaction
79
            return t_transaction
71
        
80
        finally:
-
 
81
            close_session()
72
    
82
    
73
    def getTransactionStatus(self, transactionId):
83
    def getTransactionStatus(self, transactionId):
74
        """
84
        """
75
        Parameters:
85
        Parameters:
76
         - transactionId
86
         - transactionId
77
        """
87
        """
-
 
88
        try:
78
        return get_transaction_status(transactionId)
89
            return get_transaction_status(transactionId)
-
 
90
        finally:
-
 
91
            close_session()
79
    
92
                
80
    def changeTransactionStatus(self, transactionId, status, description):
93
    def changeTransactionStatus(self, transactionId, status, description):
81
        """
94
        """
82
        Parameters:
95
        Parameters:
83
         - transactionId
96
         - transactionId
84
         - status
97
         - status
85
         - description
98
         - description
86
        """
99
        """
-
 
100
        try:
87
        return change_transaction_status(transactionId, status, description)
101
            return change_transaction_status(transactionId, status, description)
-
 
102
        finally:
-
 
103
            close_session()
88
 
104
            
89
    def getOrdersForTransaction(self, transactionId):
105
    def getOrdersForTransaction(self, transactionId):
90
        """
106
        """
91
        Parameters:
107
        Parameters:
92
         - transactionId
108
         - transactionId
93
        """
109
        """
-
 
110
        try:
94
        orders = get_orders_for_transaction(transactionId)
111
            orders = get_orders_for_transaction(transactionId)
95
        return [to_t_order(order) for order in orders]    
112
            return [to_t_order(order) for order in orders]    
-
 
113
        finally:
-
 
114
            close_session()
96
    
115
            
97
    def getAllOrders(self, status, from_date, to_date, warehouse_id):
116
    def getAllOrders(self, status, from_date, to_date, warehouse_id):
98
        """
117
        """
99
        Parameters:
118
        Parameters:
100
         - status
119
         - status
101
         - from_date
120
         - from_date
102
         - to_date
121
         - to_date
103
         - warehouse_id
122
         - warehouse_id
104
        """
123
        """
-
 
124
        try:
105
        current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
125
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
106
        orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
126
            orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
107
        return [to_t_order(order) for order in orders]
127
            return [to_t_order(order) for order in orders]
-
 
128
        finally:
-
 
129
            close_session()
108
        
130
            
109
    def changeOrderStatus(self, orderId, status, description):
131
    def changeOrderStatus(self, orderId, status, description):
110
        """
132
        """
111
        Parameters:
133
        Parameters:
112
         - orderId
134
         - orderId
113
         - status
135
         - status
114
         - description
136
         - description
115
         - 
137
         - 
116
        """
138
        """
-
 
139
        try:
117
        return change_order_status(self, orderId, status, description)
140
            return change_order_status(self, orderId, status, description)
-
 
141
        finally:
-
 
142
            close_session()
118
 
143
            
119
    def getOrdersForCustomer(self, customerId, from_date, to_date, status):
144
    def getOrdersForCustomer(self, customerId, from_date, to_date, status):
120
        """
145
        """
121
        Parameters:
146
        Parameters:
122
         - customerId
147
         - customerId
123
         - from_date
148
         - from_date
124
         - to_date
149
         - to_date
125
         - status
150
         - status
126
        """
151
        """
-
 
152
        try:
127
        current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
153
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
128
        
154
            
129
        orders = get_orders_for_customer(customerId, current_from_date, current_to_date, status)
155
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, status)
130
        return [to_t_order(order) for order in orders]
156
            return [to_t_order(order) for order in orders]
-
 
157
        finally:
-
 
158
            close_session()
131
    
159
            
132
    def getOrder(self, id):
160
    def getOrder(self, id):
133
        """
161
        """
134
        Parameters:
162
        Parameters:
135
         - id
163
         - id
136
        """
164
        """
-
 
165
        try:
137
        return to_t_order(get_order(id))
166
            return to_t_order(get_order(id))
-
 
167
        finally:
-
 
168
            close_session()
138
        
169
            
139
    def getLineItemsForOrder(self, orderId):
170
    def getLineItemsForOrder(self, orderId):
140
        """
171
        """
141
        Parameters:
172
        Parameters:
142
         - orderId
173
         - orderId
143
        """
174
        """
-
 
175
        try:
144
        lineitems = get_line_items_for_order(orderId)
176
            lineitems = get_line_items_for_order(orderId)
145
        t_lineitems = []
177
            t_lineitems = []
146
        for lineitem in lineitems:
178
            for lineitem in lineitems:
147
            t_lineitems.append(to_t_lineitem(lineitem))
179
                t_lineitems.append(to_t_lineitem(lineitem))
148
        return t_lineitems
180
            return t_lineitems
-
 
181
        finally:
-
 
182
            close_session()
149
 
183
            
150
    def addBillingDetails(self, orderId, invoice_number, jacket_number, billed_by):
184
    def addBillingDetails(self, orderId, invoice_number, jacket_number, billed_by):
151
        """
185
        """
152
        Parameters:
186
        Parameters:
153
         - orderId
187
         - orderId
154
         - invoice_number
188
         - invoice_number
155
         - billed_by
189
         - billed_by
156
        """
190
        """
-
 
191
        try:
157
        return add_billing_details(orderId, invoice_number, jacket_number, billed_by)
192
            return add_billing_details(orderId, invoice_number, jacket_number, billed_by)
-
 
193
        finally:
-
 
194
            close_session()
158
 
195
            
159
    def markOrdersAsManifested(self, warehouseId, providerId):
196
    def markOrdersAsManifested(self, warehouseId, providerId):
160
        """
197
        """
161
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
198
        Marks all BILLED orders for a warehouse and a provider as SHIPPED_FROM_WH
162
        
199
        
163
        Parameters:
200
        Parameters:
164
         - warehouseId
201
         - warehouseId
165
         - providerId
202
         - providerId
166
        """
203
        """
-
 
204
        try:
167
        return mark_orders_as_manifested(warehouseId, providerId)
205
            return mark_orders_as_manifested(warehouseId, providerId)
-
 
206
        finally:
-
 
207
            close_session()
168
 
208
            
169
    def getAlerts(self, orderId, valid):
209
    def getAlerts(self, orderId, valid):
170
        """
210
        """
171
        Parameters:
211
        Parameters:
172
         - orderId
212
         - orderId
173
         - valid
213
         - valid
174
        """
214
        """
-
 
215
        try:
175
        alerts = get_alerts(orderId, valid)
216
            alerts = get_alerts(orderId, valid)
176
        
217
            
177
        t_alerts = []
218
            t_alerts = []
178
        
219
            
179
        for alert in alerts:
220
            for alert in alerts:
180
            t_alerts.append(to_t_alert(alert)) 
221
                t_alerts.append(to_t_alert(alert)) 
181
        
222
            
182
        return t_alerts
223
            return t_alerts
-
 
224
        finally:
-
 
225
            close_session()
183
 
226
            
184
    def setAlert(self, orderId, unset, type, comment):
227
    def setAlert(self, orderId, unset, type, comment):
185
        """
228
        """
186
        Parameters:
229
        Parameters:
187
         - orderId
230
         - orderId
188
         - unset
231
         - unset
189
         - type
232
         - type
190
         - comment
233
         - comment
191
        """
234
        """
-
 
235
        try:
192
        set_alert(orderId, unset, type, comment)
236
            set_alert(orderId, unset, type, comment)
-
 
237
        finally:
-
 
238
            close_session()
-
 
239
            
-
 
240
    def closeSession(self, ):
-
 
241
        close_session()
193
 
242
    
-
 
243
    
194
    
244
    
-
 
245
    '''
195
if __name__ == "__main__":
246
if __name__ == "__main__":
196
    order = OrderServiceHandler()
247
    order = OrderServiceHandler()
197
    t = order.getTransaction(4)
248
    t = order.getTransaction(4)
198
    print t
249
    print t
199
    
250
    
200
    '''
251
    
201
    these methods commented right now. may be used later
252
    these methods commented right now. may be used later
202
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
253
    def getAllTransactions(self, status, from_date, to_date, warehouse_id):
203
        """
254
        """
204
        Parameters:
255
        Parameters:
205
         - status
256
         - status