| 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,\
|
| 132 |
ashish |
8 |
Item as T_Item, LineItem as T_LineItem, PaymentInfo, Payment, BillingInfo,\
|
|
|
9 |
ShipmentInfo, Item, OrderInfo as T_OrderInfo
|
| 104 |
ashish |
10 |
from shop2020.thriftpy.model.v1.order.ttypes import Billing as T_Billing
|
|
|
11 |
from shop2020.thriftpy.model.v1.order.ttypes import Shipment as T_Shipment
|
|
|
12 |
from shop2020.utils.Utils import to_java_date
|
|
|
13 |
from shop2020.utils import OrderStatus
|
|
|
14 |
from shop2020.model.v1.order.impl.DataService import Billing
|
|
|
15 |
from shop2020.utils.OrderStatus import get_t_status
|
|
|
16 |
|
|
|
17 |
def to_t_transaction(transaction):
|
|
|
18 |
t_transaction = T_Transaction()
|
|
|
19 |
t_transaction.id = transaction.id
|
|
|
20 |
t_transaction.createdOn = to_java_date(transaction.createdOn)
|
|
|
21 |
t_transaction.transactionStatus = OrderStatus.get_t_status(transaction.status)
|
| 194 |
ashish |
22 |
t_transaction.statusDescription = transaction.status_message
|
| 132 |
ashish |
23 |
t_transaction.expectedDeliveryTime = to_java_date(transaction.expected_delivery_time)
|
|
|
24 |
t_transaction.customer_id = transaction.customer_id
|
|
|
25 |
t_transaction.shoppingCartid = transaction.shopping_cart_id
|
|
|
26 |
t_transaction.orderInfo = to_t_order_info(transaction.lineitems)
|
|
|
27 |
t_transaction.shipmentInfo = to_t_shipment_info(transaction.shipments)
|
|
|
28 |
t_transaction.billingInfo = to_t_billing_info(transaction.lineitems)
|
|
|
29 |
t_transaction.paymentInfo = to_t_payment_info(transaction.payments)
|
|
|
30 |
#populate order info
|
| 104 |
ashish |
31 |
|
|
|
32 |
return t_transaction
|
|
|
33 |
|
| 132 |
ashish |
34 |
def to_t_payment_info(payments):
|
|
|
35 |
t_payment_info = PaymentInfo()
|
|
|
36 |
if payments:
|
|
|
37 |
payment_map = {}
|
|
|
38 |
for payment in payments:
|
|
|
39 |
t_payment_info.id = payment.id
|
|
|
40 |
t_payment = Payment()
|
|
|
41 |
t_payment.merchant_tx_id = payment.merchant_tx_id
|
|
|
42 |
t_payment.bank_tx_id = payment.bank_tx_id
|
|
|
43 |
t_payment.mode = payment.mode
|
|
|
44 |
t_payment.amount = payment.amount
|
|
|
45 |
t_payment.status = payment.status
|
|
|
46 |
t_payment.description = payment.status_message
|
| 194 |
ashish |
47 |
t_payment.submissionTimestamp = to_java_date(payment.start_time)
|
|
|
48 |
t_payment.completionTimestamp = to_java_date(payment.finish_time)
|
| 132 |
ashish |
49 |
payment_map[t_payment.submissionTimestamp] = t_payment
|
|
|
50 |
t_payment_info.payments = payment_map
|
|
|
51 |
|
|
|
52 |
return t_payment_info
|
|
|
53 |
|
|
|
54 |
def to_t_billing_info(lineitems):
|
|
|
55 |
t_billing_info = BillingInfo()
|
|
|
56 |
if lineitems:
|
|
|
57 |
billed_items = []
|
|
|
58 |
billings = []
|
|
|
59 |
for item in lineitems:
|
|
|
60 |
#each item has a billing
|
|
|
61 |
t_billing_info.id = item.transaction.id
|
|
|
62 |
billing = item.billing
|
|
|
63 |
if billing:
|
|
|
64 |
if billed_items.count(billing.id) == 0:
|
|
|
65 |
billed_items.append(billing.id)
|
|
|
66 |
billings.append(to_t_billing(billing))
|
|
|
67 |
t_billing_info.billings = billings
|
|
|
68 |
return t_billing_info
|
|
|
69 |
|
|
|
70 |
def to_t_order_info(lineitems):
|
|
|
71 |
t_order_info = T_OrderInfo()
|
|
|
72 |
if lineitems:
|
|
|
73 |
line_item_list = []
|
|
|
74 |
for lineitem in lineitems:
|
|
|
75 |
t_order_info.id = lineitem.transaction.id
|
|
|
76 |
line_item_list.append(to_t_lineitem(lineitem))
|
|
|
77 |
t_order_info.lineitems = line_item_list
|
|
|
78 |
return t_order_info
|
|
|
79 |
|
|
|
80 |
def to_t_shipment_info(shipments):
|
|
|
81 |
shipment_info = ShipmentInfo()
|
|
|
82 |
if shipments:
|
|
|
83 |
shipment_list = []
|
|
|
84 |
for shipment in shipments:
|
|
|
85 |
shipment_info.id = shipment.transaction.id
|
|
|
86 |
shipment_list.append(to_t_shipment(shipment))
|
|
|
87 |
shipment_info.shipments = shipment_list
|
|
|
88 |
return shipment_info
|
|
|
89 |
|
| 104 |
ashish |
90 |
def to_t_billing(billing):
|
|
|
91 |
t_billing = T_Billing()
|
|
|
92 |
t_billing.id = billing.id
|
|
|
93 |
t_billing.billNumber = billing.bill_number
|
|
|
94 |
t_billing.generatedBy = billing.generated_by
|
| 132 |
ashish |
95 |
try:
|
|
|
96 |
t_billing.generatedTimestamp = to_java_date(billing.created_on)
|
|
|
97 |
except:
|
|
|
98 |
print "date not found"
|
| 194 |
ashish |
99 |
t_billing.lineItem = []
|
|
|
100 |
if billing.line_item:
|
|
|
101 |
for item in billing.line_item:
|
|
|
102 |
t_billing.lineItem.append(to_t_lineitem(item))
|
|
|
103 |
|
| 132 |
ashish |
104 |
return t_billing
|
|
|
105 |
|
| 104 |
ashish |
106 |
def to_t_lineitem(lineitem):
|
|
|
107 |
t_line_item = T_LineItem()
|
| 194 |
ashish |
108 |
try:
|
|
|
109 |
t_line_item.id = lineitem.id
|
|
|
110 |
except:
|
|
|
111 |
t_line_item.id = 0
|
| 132 |
ashish |
112 |
if lineitem.item_info:
|
|
|
113 |
t_line_item.item = to_t_item_info(lineitem.item_info)
|
|
|
114 |
|
| 104 |
ashish |
115 |
t_line_item.addedOn = to_java_date(lineitem.added_on)
|
|
|
116 |
t_line_item.additionalInfo = {}
|
|
|
117 |
if lineitem.additional_info:
|
|
|
118 |
for k,v in lineitem.additional_info.iteritems():
|
|
|
119 |
t_line_item.additionalInfo[k] = v
|
|
|
120 |
return t_line_item
|
|
|
121 |
|
| 132 |
ashish |
122 |
def to_t_item_info(item_info):
|
|
|
123 |
t_item = Item()
|
|
|
124 |
t_item.id = item_info.line_item.item_id
|
|
|
125 |
t_item.price = item_info.price
|
|
|
126 |
t_item.weight = item_info.weight
|
|
|
127 |
return t_item
|
|
|
128 |
|
| 104 |
ashish |
129 |
def to_t_shipment(shipment):
|
|
|
130 |
t_shipment = T_Shipment()
|
|
|
131 |
t_shipment.id = shipment.id
|
|
|
132 |
t_shipment.address = shipment.address
|
|
|
133 |
t_shipment.airwayBillNo = shipment.airway_bill_no
|
|
|
134 |
try:
|
|
|
135 |
t_shipment.deliveryTimestamp = to_java_date(shipment.delivery_time)
|
|
|
136 |
except:
|
|
|
137 |
print "no delivery timestamp"
|
|
|
138 |
t_shipment.insurance = shipment.insurance_value
|
|
|
139 |
t_shipment.provider = shipment.provider
|
|
|
140 |
t_shipment.value = shipment.declared_value
|
|
|
141 |
try:
|
|
|
142 |
t_shipment.shipmentTimestamp = to_java_date(shipment.shipment_time)
|
|
|
143 |
except:
|
|
|
144 |
print "no shipment timestamp"
|
|
|
145 |
t_shipment.status = get_t_status(shipment.status)
|
|
|
146 |
t_shipment.weight = shipment.weight
|
|
|
147 |
t_shipment.trackingId = shipment.tracking_id
|
|
|
148 |
|
|
|
149 |
t_shipment.lineItems = []
|
| 194 |
ashish |
150 |
if shipment.lineitems:
|
|
|
151 |
for line_item in shipment.lineitems:
|
| 104 |
ashish |
152 |
t_shipment.lineItems.append(to_t_lineitem(line_item))
|
|
|
153 |
return t_shipment
|
| 132 |
ashish |
154 |
|