| 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,\
|
|
|
8 |
get_transaction, get_all_transactions, get_transactions_for_shipment_status,\
|
|
|
9 |
get_transactions_for_customer, get_transactions_for_customer_shipment,\
|
|
|
10 |
get_transaction_status, change_transaction_status, set_shipping_tracker_info,\
|
|
|
11 |
change_shipping_status, set_shipping_date, set_delivery_date, get_line_items,\
|
| 132 |
ashish |
12 |
get_shipments, get_billings, set_billing,\
|
|
|
13 |
get_transactions_for_shopping_cart_id
|
| 104 |
ashish |
14 |
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
|
|
|
15 |
to_t_lineitem, to_t_shipment, to_t_billing
|
|
|
16 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderInfo,\
|
|
|
17 |
LineItem, ShipmentInfo, BillingInfo
|
|
|
18 |
from shop2020.utils import OrderStatus
|
|
|
19 |
from shop2020.utils.Utils import to_py_date, get_status_fdate_tdate
|
|
|
20 |
from shop2020.utils.OrderStatus import get_t_status, get_c_status
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
class OrderServiceHandler:
|
|
|
24 |
|
|
|
25 |
def __init__(self):
|
|
|
26 |
'''
|
|
|
27 |
Constructor
|
|
|
28 |
'''
|
|
|
29 |
DataService.initialize()
|
|
|
30 |
|
|
|
31 |
def createTransaction(self, transaction):
|
|
|
32 |
"""
|
|
|
33 |
Parameters:
|
|
|
34 |
- transaction
|
|
|
35 |
"""
|
|
|
36 |
return create_transaction(transaction)
|
|
|
37 |
|
|
|
38 |
def getTransaction(self, id):
|
|
|
39 |
"""
|
|
|
40 |
Get transaction methods.
|
|
|
41 |
|
|
|
42 |
Parameters:
|
|
|
43 |
- id
|
|
|
44 |
"""
|
|
|
45 |
transaction = get_transaction(id)
|
|
|
46 |
return to_t_transaction(transaction)
|
|
|
47 |
|
|
|
48 |
def getAllTransactions(self, status, from_date, to_date):
|
|
|
49 |
"""
|
|
|
50 |
Parameters:
|
|
|
51 |
- status
|
|
|
52 |
- from_date
|
|
|
53 |
- to_date
|
|
|
54 |
"""
|
|
|
55 |
current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
|
|
|
56 |
|
|
|
57 |
transactions = get_all_transactions(current_status, current_from_date, current_to_date)
|
|
|
58 |
t_transaction = []
|
|
|
59 |
for transaction in transactions:
|
|
|
60 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
61 |
return t_transaction
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
def getTransactionsForShipmentStatus(self, status, from_date, to_date):
|
|
|
65 |
"""
|
|
|
66 |
Parameters:
|
|
|
67 |
- status
|
|
|
68 |
- from_date
|
|
|
69 |
- to_date
|
|
|
70 |
"""
|
|
|
71 |
current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
|
|
|
72 |
|
|
|
73 |
transactions = get_transactions_for_shipment_status(current_status, current_from_date, current_to_date)
|
|
|
74 |
t_transaction = []
|
|
|
75 |
for transaction in transactions:
|
|
|
76 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
77 |
return t_transaction
|
|
|
78 |
|
|
|
79 |
def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
|
|
|
80 |
"""
|
|
|
81 |
Parameters:
|
|
|
82 |
- customerId
|
|
|
83 |
- from_date
|
|
|
84 |
- to_date
|
|
|
85 |
- status
|
|
|
86 |
"""
|
|
|
87 |
current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
|
|
|
88 |
|
|
|
89 |
transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, current_status)
|
|
|
90 |
t_transaction = []
|
|
|
91 |
for transaction in transactions:
|
|
|
92 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
93 |
return t_transaction
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
def getTransactionsForCustomerAndShipmentStatus(self, customerId, from_date, to_date, status):
|
|
|
97 |
"""
|
|
|
98 |
Parameters:
|
|
|
99 |
- customerId
|
|
|
100 |
- from_date
|
|
|
101 |
- to_date
|
|
|
102 |
- status
|
|
|
103 |
"""
|
|
|
104 |
current_status, current_from_date, current_to_date = get_status_fdate_tdate(status, from_date, to_date)
|
|
|
105 |
|
|
|
106 |
transactions = get_transactions_for_customer_shipment(customerId, current_from_date, current_to_date, current_status)
|
|
|
107 |
t_transaction = []
|
|
|
108 |
for transaction in transactions:
|
|
|
109 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
110 |
return t_transaction
|
|
|
111 |
|
| 132 |
ashish |
112 |
def getTransactionsForShoppingCartId(self, shoppingCartId):
|
|
|
113 |
"""
|
|
|
114 |
Parameters:
|
|
|
115 |
- shoppingCartId
|
|
|
116 |
"""
|
|
|
117 |
transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
|
|
|
118 |
t_transaction = []
|
|
|
119 |
for transaction in transactions:
|
|
|
120 |
t_transaction.append(to_t_transaction(transaction))
|
|
|
121 |
return t_transaction
|
|
|
122 |
pass
|
|
|
123 |
|
|
|
124 |
|
| 104 |
ashish |
125 |
def getTransactionStatus(self, transactionId):
|
|
|
126 |
"""
|
|
|
127 |
Parameters:
|
|
|
128 |
- transactionId
|
|
|
129 |
"""
|
|
|
130 |
return get_t_status(get_transaction_status(transactionId))
|
|
|
131 |
|
|
|
132 |
def changeTransactionStatus(self, transactionId, status, description):
|
|
|
133 |
"""
|
|
|
134 |
Parameters:
|
|
|
135 |
- transactionId
|
|
|
136 |
- status
|
|
|
137 |
- description
|
|
|
138 |
"""
|
|
|
139 |
return change_transaction_status(transactionId, get_c_status(status), description)
|
|
|
140 |
|
|
|
141 |
def getOrderInfo(self, transactionId):
|
|
|
142 |
"""
|
|
|
143 |
Get and set individual objects in it
|
|
|
144 |
*
|
|
|
145 |
|
|
|
146 |
Parameters:
|
|
|
147 |
- transactionId
|
|
|
148 |
"""
|
|
|
149 |
lineitems = get_line_items(transactionId)
|
|
|
150 |
order_info = OrderInfo()
|
|
|
151 |
order_info.lineitems = []
|
|
|
152 |
for lineitem in lineitems:
|
|
|
153 |
order_info.lineitems.append(to_t_lineitem(lineitem))
|
|
|
154 |
order_info.id = lineitem.transaction.id
|
|
|
155 |
|
|
|
156 |
return order_info
|
|
|
157 |
|
|
|
158 |
def getShippingInfo(self, transactionId):
|
|
|
159 |
"""
|
|
|
160 |
Parameters:
|
|
|
161 |
- transactionId
|
|
|
162 |
"""
|
|
|
163 |
shipments = get_shipments(transactionId)
|
|
|
164 |
shipment_info = ShipmentInfo()
|
|
|
165 |
shipment_info.shipments = []
|
|
|
166 |
for shipment in shipments:
|
|
|
167 |
shipment_info.shipments.append(to_t_shipment(shipment))
|
|
|
168 |
shipment_info.id = shipment.id
|
|
|
169 |
return shipment_info
|
|
|
170 |
def getBillingInfo(self, transactionId):
|
|
|
171 |
"""
|
|
|
172 |
Parameters:
|
|
|
173 |
- transactionId
|
|
|
174 |
"""
|
|
|
175 |
billings = get_billings(transactionId)
|
|
|
176 |
billing_info = BillingInfo()
|
|
|
177 |
billing_info.billings = []
|
|
|
178 |
if billings:
|
|
|
179 |
for billing in billings:
|
|
|
180 |
billing_info.billings.append(to_t_billing(billing))
|
|
|
181 |
billing_info.id = billing.line_item.transaction.id
|
|
|
182 |
return billing_info
|
|
|
183 |
|
|
|
184 |
def addBilling(self, transactionId, billing):
|
|
|
185 |
"""
|
|
|
186 |
Parameters:
|
|
|
187 |
- tranactionId
|
|
|
188 |
- billing
|
|
|
189 |
"""
|
|
|
190 |
return set_billing(transactionId, billing)
|
|
|
191 |
|
|
|
192 |
def setShippingTracker(self, transactionId, shippingId, trackingId, airwayBillNo, provider):
|
|
|
193 |
"""
|
|
|
194 |
Parameters:
|
|
|
195 |
- transactionId
|
|
|
196 |
- shippingId
|
|
|
197 |
- trackingId
|
|
|
198 |
- airwayBillNo
|
|
|
199 |
- provider
|
|
|
200 |
"""
|
|
|
201 |
return set_shipping_tracker_info(transactionId, shippingId, trackingId, airwayBillNo, provider)
|
|
|
202 |
|
|
|
203 |
def setShippingDate(self, transactionId, shippingId, timestamp):
|
|
|
204 |
"""
|
|
|
205 |
Parameters:
|
|
|
206 |
- transactionId
|
|
|
207 |
- shippingId
|
|
|
208 |
- timestamp
|
|
|
209 |
"""
|
|
|
210 |
return set_shipping_date(transactionId, shippingId, to_py_date(timestamp))
|
|
|
211 |
|
|
|
212 |
def setDeliveryDate(self, transactionId, shippingid, timestamp):
|
|
|
213 |
"""
|
|
|
214 |
Parameters:
|
|
|
215 |
- transactionId
|
|
|
216 |
- shippingid
|
|
|
217 |
- timestamp
|
|
|
218 |
"""
|
|
|
219 |
return set_delivery_date(transactionId, shippingid, timestamp)
|
|
|
220 |
|
|
|
221 |
def changeShippingStatus(self, transactionId, shippingId, status, description):
|
|
|
222 |
"""
|
|
|
223 |
Parameters:
|
|
|
224 |
- transactionId
|
|
|
225 |
- shippingId
|
|
|
226 |
- status
|
|
|
227 |
- description
|
|
|
228 |
"""
|
|
|
229 |
return change_shipping_status(transactionId, shippingId, get_c_status(status), description)
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
if __name__ == "__main__":
|
|
|
233 |
order = OrderServiceHandler()
|
|
|
234 |
t = order.getTransaction(4)
|
|
|
235 |
print t
|