| 104 |
ashish |
1 |
'''
|
|
|
2 |
Created on 29-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
|
|
|
7 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
| 483 |
rajveer |
8 |
LineItem as T_LineItem, PaymentInfo, Payment, Order as T_Order, Alert as T_Alert
|
| 104 |
ashish |
9 |
from shop2020.utils.Utils import to_java_date
|
|
|
10 |
from shop2020.utils import OrderStatus
|
| 483 |
rajveer |
11 |
from shop2020.model.v1.order.impl.DataService import Alerts
|
|
|
12 |
|
| 104 |
ashish |
13 |
from shop2020.utils.OrderStatus import get_t_status
|
|
|
14 |
|
|
|
15 |
def to_t_transaction(transaction):
|
|
|
16 |
t_transaction = T_Transaction()
|
|
|
17 |
t_transaction.id = transaction.id
|
| 483 |
rajveer |
18 |
t_transaction.createdOn = to_java_date(transaction.createdOn)
|
|
|
19 |
t_transaction.transactionStatus = OrderStatus.get_t_status(transaction.status)
|
|
|
20 |
t_transaction.statusDescription = transaction.status_message
|
|
|
21 |
t_transaction.customer_id = transaction.customer_id
|
|
|
22 |
t_transaction.shoppingCartid = transaction.shopping_cart_id
|
|
|
23 |
t_transaction.orders = []
|
|
|
24 |
#populate orders
|
|
|
25 |
for order in transaction.orders:
|
|
|
26 |
t_order = to_t_order(order)
|
|
|
27 |
t_transaction.orders.append(t_order)
|
|
|
28 |
|
|
|
29 |
return t_transaction
|
|
|
30 |
|
|
|
31 |
def to_t_order(order):
|
|
|
32 |
t_order = T_Order()
|
|
|
33 |
t_order.id = order.id
|
|
|
34 |
t_order.warehouse_id = order.warehouse_id
|
|
|
35 |
t_order.logistics_provider_id = order.logistics_provider_id
|
|
|
36 |
t_order.airwaybill_no = order.airwaybill_no
|
|
|
37 |
t_order.tracking_id = order.tracking_id
|
|
|
38 |
t_order.expected_delivery_time = to_java_date(order.expected_delivery_time)
|
|
|
39 |
t_order.customer_id = order.customer_id
|
|
|
40 |
t_order.customer_name = order.customer_name
|
|
|
41 |
t_order.customer_mobilenumber = order.customer_mobilenumber
|
|
|
42 |
t_order.customer_pincode = order.customer_pincode
|
|
|
43 |
t_order.customer_address = order.customer_address
|
|
|
44 |
t_order.customer_email = order.customer_email
|
| 494 |
rajveer |
45 |
t_order.status = OrderStatus.get_t_status(order.status)
|
| 483 |
rajveer |
46 |
t_order.statusDescription = order.statusDescription
|
|
|
47 |
t_order.total_amount = order.total_amount
|
|
|
48 |
t_order.total_weight = order.total_weight
|
|
|
49 |
t_order.created_timestamp = to_java_date(order.created_timestamp)
|
|
|
50 |
t_order.invoice_number = order.invoice_number
|
|
|
51 |
t_order.billed_by = order.billed_by
|
|
|
52 |
t_order.accepted_timestamp = order.accepted_timestamp
|
|
|
53 |
t_order.billing_timestamp = order.billing_timestamp
|
|
|
54 |
t_order.shipping_timestamp = order.shipping_timestamp
|
|
|
55 |
t_order.delivery_timestamp = order.delivery_timestamp
|
| 642 |
chandransh |
56 |
t_order.jacket_number = order.jacket_number
|
| 483 |
rajveer |
57 |
t_order.lineitems = []
|
|
|
58 |
for lineitem in order.lineitems:
|
|
|
59 |
t_lineitem = to_t_lineitem(lineitem)
|
|
|
60 |
t_order.lineitems.append(t_lineitem)
|
|
|
61 |
|
|
|
62 |
return t_order
|
|
|
63 |
|
|
|
64 |
def to_t_lineitem(lineitem):
|
|
|
65 |
t_lineitem = T_LineItem()
|
|
|
66 |
t_lineitem.id = lineitem.id
|
|
|
67 |
t_lineitem.sku_id = lineitem.sku_id
|
|
|
68 |
t_lineitem.unit_weight = lineitem.unit_weight
|
|
|
69 |
t_lineitem.unit_price = lineitem.unit_price
|
|
|
70 |
t_lineitem.total_price = lineitem.total_price
|
|
|
71 |
t_lineitem.total_weight = lineitem.total_weight
|
|
|
72 |
t_lineitem.quantity = lineitem.quantity
|
|
|
73 |
t_lineitem.model_number = lineitem.model_number
|
|
|
74 |
t_lineitem.model_name = lineitem.model_name
|
|
|
75 |
t_lineitem.extra_info = lineitem.extra_info
|
|
|
76 |
t_lineitem.brand = lineitem.brand
|
|
|
77 |
return t_lineitem
|
|
|
78 |
|
|
|
79 |
def to_t_payment_info(payments):
|
|
|
80 |
t_payment_info = PaymentInfo()
|
|
|
81 |
if payments:
|
|
|
82 |
payment_map = {}
|
|
|
83 |
for payment in payments:
|
|
|
84 |
t_payment_info.id = payment.id
|
|
|
85 |
t_payment = Payment()
|
|
|
86 |
t_payment.merchant_tx_id = payment.merchant_tx_id
|
|
|
87 |
t_payment.bank_tx_id = payment.bank_tx_id
|
|
|
88 |
t_payment.mode = payment.mode
|
|
|
89 |
t_payment.amount = payment.amount
|
|
|
90 |
t_payment.status = payment.status
|
|
|
91 |
t_payment.description = payment.status_message
|
|
|
92 |
t_payment.submissionTimestamp = to_java_date(payment.start_time)
|
|
|
93 |
t_payment.completionTimestamp = to_java_date(payment.finish_time)
|
|
|
94 |
payment_map[t_payment.submissionTimestamp] = t_payment
|
|
|
95 |
t_payment_info.payments = payment_map
|
|
|
96 |
|
|
|
97 |
return t_payment_info
|
|
|
98 |
|
|
|
99 |
def to_t_alert(alert):
|
|
|
100 |
t_alert = T_Alert()
|
|
|
101 |
t_alert.id = alert.id
|
|
|
102 |
t_alert.comment = alert.comment
|
|
|
103 |
try:
|
|
|
104 |
t_alert.time_set = to_java_date(alert.time_set)
|
|
|
105 |
except:
|
|
|
106 |
pass
|
|
|
107 |
try:
|
|
|
108 |
t_alert.time_unset = to_java_date(alert.time_unset)
|
|
|
109 |
except:
|
|
|
110 |
pass
|
|
|
111 |
t_alert.order_id = alert.order_id
|
|
|
112 |
t_alert.type = alert.type
|
|
|
113 |
return t_alert
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
"""
|
|
|
117 |
def to_t_transaction(transaction):
|
|
|
118 |
t_transaction = T_Transaction()
|
|
|
119 |
t_transaction.id = transaction.id
|
| 358 |
ashish |
120 |
t_transaction.warehouse_id = transaction.warehouse_id
|
| 104 |
ashish |
121 |
t_transaction.createdOn = to_java_date(transaction.createdOn)
|
|
|
122 |
t_transaction.transactionStatus = OrderStatus.get_t_status(transaction.status)
|
| 194 |
ashish |
123 |
t_transaction.statusDescription = transaction.status_message
|
| 132 |
ashish |
124 |
t_transaction.expectedDeliveryTime = to_java_date(transaction.expected_delivery_time)
|
|
|
125 |
t_transaction.customer_id = transaction.customer_id
|
|
|
126 |
t_transaction.shoppingCartid = transaction.shopping_cart_id
|
|
|
127 |
t_transaction.orderInfo = to_t_order_info(transaction.lineitems)
|
|
|
128 |
t_transaction.shipmentInfo = to_t_shipment_info(transaction.shipments)
|
|
|
129 |
t_transaction.billingInfo = to_t_billing_info(transaction.lineitems)
|
|
|
130 |
t_transaction.paymentInfo = to_t_payment_info(transaction.payments)
|
| 358 |
ashish |
131 |
|
| 132 |
ashish |
132 |
#populate order info
|
| 104 |
ashish |
133 |
|
|
|
134 |
return t_transaction
|
|
|
135 |
|
| 132 |
ashish |
136 |
def to_t_payment_info(payments):
|
|
|
137 |
t_payment_info = PaymentInfo()
|
|
|
138 |
if payments:
|
|
|
139 |
payment_map = {}
|
|
|
140 |
for payment in payments:
|
|
|
141 |
t_payment_info.id = payment.id
|
|
|
142 |
t_payment = Payment()
|
|
|
143 |
t_payment.merchant_tx_id = payment.merchant_tx_id
|
|
|
144 |
t_payment.bank_tx_id = payment.bank_tx_id
|
|
|
145 |
t_payment.mode = payment.mode
|
|
|
146 |
t_payment.amount = payment.amount
|
|
|
147 |
t_payment.status = payment.status
|
|
|
148 |
t_payment.description = payment.status_message
|
| 194 |
ashish |
149 |
t_payment.submissionTimestamp = to_java_date(payment.start_time)
|
|
|
150 |
t_payment.completionTimestamp = to_java_date(payment.finish_time)
|
| 132 |
ashish |
151 |
payment_map[t_payment.submissionTimestamp] = t_payment
|
|
|
152 |
t_payment_info.payments = payment_map
|
|
|
153 |
|
|
|
154 |
return t_payment_info
|
|
|
155 |
|
|
|
156 |
def to_t_billing_info(lineitems):
|
|
|
157 |
t_billing_info = BillingInfo()
|
|
|
158 |
if lineitems:
|
|
|
159 |
billed_items = []
|
|
|
160 |
billings = []
|
|
|
161 |
for item in lineitems:
|
|
|
162 |
#each item has a billing
|
|
|
163 |
t_billing_info.id = item.transaction.id
|
|
|
164 |
billing = item.billing
|
|
|
165 |
if billing:
|
|
|
166 |
if billed_items.count(billing.id) == 0:
|
|
|
167 |
billed_items.append(billing.id)
|
|
|
168 |
billings.append(to_t_billing(billing))
|
|
|
169 |
t_billing_info.billings = billings
|
|
|
170 |
return t_billing_info
|
|
|
171 |
|
|
|
172 |
def to_t_order_info(lineitems):
|
|
|
173 |
t_order_info = T_OrderInfo()
|
|
|
174 |
if lineitems:
|
|
|
175 |
line_item_list = []
|
|
|
176 |
for lineitem in lineitems:
|
|
|
177 |
t_order_info.id = lineitem.transaction.id
|
|
|
178 |
line_item_list.append(to_t_lineitem(lineitem))
|
|
|
179 |
t_order_info.lineitems = line_item_list
|
|
|
180 |
return t_order_info
|
|
|
181 |
|
|
|
182 |
def to_t_shipment_info(shipments):
|
|
|
183 |
shipment_info = ShipmentInfo()
|
|
|
184 |
if shipments:
|
|
|
185 |
shipment_list = []
|
|
|
186 |
for shipment in shipments:
|
|
|
187 |
shipment_info.id = shipment.transaction.id
|
|
|
188 |
shipment_list.append(to_t_shipment(shipment))
|
|
|
189 |
shipment_info.shipments = shipment_list
|
|
|
190 |
return shipment_info
|
|
|
191 |
|
| 104 |
ashish |
192 |
def to_t_billing(billing):
|
|
|
193 |
t_billing = T_Billing()
|
|
|
194 |
t_billing.id = billing.id
|
|
|
195 |
t_billing.billNumber = billing.bill_number
|
|
|
196 |
t_billing.generatedBy = billing.generated_by
|
| 132 |
ashish |
197 |
try:
|
|
|
198 |
t_billing.generatedTimestamp = to_java_date(billing.created_on)
|
|
|
199 |
except:
|
|
|
200 |
print "date not found"
|
| 194 |
ashish |
201 |
t_billing.lineItem = []
|
|
|
202 |
if billing.line_item:
|
|
|
203 |
for item in billing.line_item:
|
|
|
204 |
t_billing.lineItem.append(to_t_lineitem(item))
|
|
|
205 |
|
| 132 |
ashish |
206 |
return t_billing
|
|
|
207 |
|
| 104 |
ashish |
208 |
def to_t_lineitem(lineitem):
|
|
|
209 |
t_line_item = T_LineItem()
|
| 194 |
ashish |
210 |
try:
|
|
|
211 |
t_line_item.id = lineitem.id
|
|
|
212 |
except:
|
|
|
213 |
t_line_item.id = 0
|
| 132 |
ashish |
214 |
if lineitem.item_info:
|
|
|
215 |
t_line_item.item = to_t_item_info(lineitem.item_info)
|
|
|
216 |
|
| 104 |
ashish |
217 |
t_line_item.addedOn = to_java_date(lineitem.added_on)
|
|
|
218 |
t_line_item.additionalInfo = {}
|
|
|
219 |
if lineitem.additional_info:
|
|
|
220 |
for k,v in lineitem.additional_info.iteritems():
|
|
|
221 |
t_line_item.additionalInfo[k] = v
|
|
|
222 |
return t_line_item
|
|
|
223 |
|
| 132 |
ashish |
224 |
def to_t_item_info(item_info):
|
|
|
225 |
t_item = Item()
|
|
|
226 |
t_item.id = item_info.line_item.item_id
|
|
|
227 |
t_item.price = item_info.price
|
|
|
228 |
t_item.weight = item_info.weight
|
|
|
229 |
return t_item
|
|
|
230 |
|
| 104 |
ashish |
231 |
def to_t_shipment(shipment):
|
|
|
232 |
t_shipment = T_Shipment()
|
|
|
233 |
t_shipment.id = shipment.id
|
|
|
234 |
t_shipment.address = shipment.address
|
|
|
235 |
t_shipment.airwayBillNo = shipment.airway_bill_no
|
|
|
236 |
try:
|
|
|
237 |
t_shipment.deliveryTimestamp = to_java_date(shipment.delivery_time)
|
|
|
238 |
except:
|
|
|
239 |
print "no delivery timestamp"
|
|
|
240 |
t_shipment.insurance = shipment.insurance_value
|
|
|
241 |
t_shipment.provider = shipment.provider
|
|
|
242 |
t_shipment.value = shipment.declared_value
|
|
|
243 |
try:
|
|
|
244 |
t_shipment.shipmentTimestamp = to_java_date(shipment.shipment_time)
|
|
|
245 |
except:
|
|
|
246 |
print "no shipment timestamp"
|
|
|
247 |
t_shipment.status = get_t_status(shipment.status)
|
|
|
248 |
t_shipment.weight = shipment.weight
|
|
|
249 |
t_shipment.trackingId = shipment.tracking_id
|
|
|
250 |
|
|
|
251 |
t_shipment.lineItems = []
|
| 194 |
ashish |
252 |
if shipment.lineitems:
|
|
|
253 |
for line_item in shipment.lineitems:
|
| 104 |
ashish |
254 |
t_shipment.lineItems.append(to_t_lineitem(line_item))
|
|
|
255 |
return t_shipment
|
| 132 |
ashish |
256 |
|
| 304 |
ashish |
257 |
def to_t_alert(alert):
|
|
|
258 |
t_alert = T_Alert()
|
|
|
259 |
t_alert.id = alert.id
|
|
|
260 |
t_alert.comment = alert.comment
|
|
|
261 |
try:
|
|
|
262 |
t_alert.time_set = to_java_date(alert.time_set)
|
|
|
263 |
except:
|
|
|
264 |
pass
|
|
|
265 |
try:
|
|
|
266 |
t_alert.time_unset = to_java_date(alert.time_unset)
|
|
|
267 |
except:
|
|
|
268 |
pass
|
|
|
269 |
t_alert.transaction_id = alert.transaction_id
|
|
|
270 |
t_alert.type = alert.type
|
|
|
271 |
return t_alert
|
|
|
272 |
|
|
|
273 |
def to_t_extra_item_info(extra_item_info, transaction_id):
|
|
|
274 |
|
|
|
275 |
extra_order_info = T_ExtraOrderInfo()
|
|
|
276 |
if not extra_item_info:
|
|
|
277 |
extra_order_info.id = 2
|
|
|
278 |
extra_order_info.model_name = "N 72"
|
|
|
279 |
extra_order_info.sku_id = 34
|
|
|
280 |
extra_order_info.transaction_id = transaction_id
|
|
|
281 |
extra_order_info.vendor_info = "Nokia"
|
|
|
282 |
extra_order_info.colour = "Black"
|
|
|
283 |
return extra_order_info
|
|
|
284 |
|
|
|
285 |
extra_order_info.id = extra_item_info.id
|
|
|
286 |
extra_order_info.model_name = extra_item_info.model
|
|
|
287 |
extra_order_info.vendor_info = extra_item_info.vendor
|
|
|
288 |
extra_order_info.transaction_id = extra_item_info.transaction_id
|
|
|
289 |
extra_order_info.sku_id = extra_item_info.sku_id
|
| 483 |
rajveer |
290 |
return extra_order_info
|
|
|
291 |
"""
|