| 104 |
ashish |
1 |
'''
|
|
|
2 |
Created on 29-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem,\
|
| 483 |
rajveer |
7 |
Payment, Alerts, Order
|
| 104 |
ashish |
8 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction,\
|
|
|
9 |
TransactionServiceException
|
|
|
10 |
import datetime
|
| 483 |
rajveer |
11 |
from shop2020.utils.OrderStatus import status_transaction_init, get_c_status
|
| 122 |
ashish |
12 |
from elixir import *
|
| 104 |
ashish |
13 |
from shop2020.utils.Utils import to_py_date
|
|
|
14 |
from sqlalchemy.sql.expression import and_
|
| 483 |
rajveer |
15 |
from shop2020.model.v1 import order
|
| 104 |
ashish |
16 |
|
|
|
17 |
|
| 483 |
rajveer |
18 |
|
| 104 |
ashish |
19 |
def get_new_transaction():
|
|
|
20 |
transaction = Transaction()
|
|
|
21 |
transaction.createdOn = datetime.datetime.now()
|
| 353 |
ashish |
22 |
transaction.status = status_transaction_init
|
| 104 |
ashish |
23 |
transaction.status_message = "New transaction"
|
| 483 |
rajveer |
24 |
|
|
|
25 |
return transaction
|
|
|
26 |
|
|
|
27 |
'''
|
|
|
28 |
customer_id = Field(Integer)
|
|
|
29 |
shopping_cart_id = Field(Integer)
|
|
|
30 |
payments = OneToMany("Payment")
|
|
|
31 |
orders = OneToMany("Order")
|
|
|
32 |
'''
|
|
|
33 |
|
|
|
34 |
def create_order(t_order):
|
|
|
35 |
order = Order()
|
|
|
36 |
if t_order.warehouse_id:
|
|
|
37 |
order.warehouse_id = t_order.warehouse_id
|
|
|
38 |
if order.logistics_provider_id:
|
|
|
39 |
order.logistics_provider_id = t_order.logistics_provider_id
|
|
|
40 |
order.airwaybill_no = t_order.airwaybill_no
|
|
|
41 |
order.tracking_id = t_order.tracking_id
|
|
|
42 |
if t_order.expected_delivery_time:
|
|
|
43 |
order.expected_delivery_time = to_py_date(t_order.expected_delivery_time)
|
|
|
44 |
if t_order.customer_id:
|
|
|
45 |
order.customer_id = t_order.customer_id
|
|
|
46 |
order.customer_name = t_order.customer_name
|
|
|
47 |
order.customer_mobilenumber = t_order.customer_mobilenumber
|
|
|
48 |
order.customer_pincode = t_order.customer_pincode
|
|
|
49 |
order.customer_address = t_order.customer_address
|
|
|
50 |
order.customer_email = t_order.customer_email
|
|
|
51 |
#new status and status description to be added
|
|
|
52 |
order.status = t_order.status
|
|
|
53 |
order.statusDescription = t_order.statusDescription
|
|
|
54 |
order.total_amount = t_order.total_amount
|
|
|
55 |
order.total_weight = t_order.total_weight
|
|
|
56 |
if t_order.created_timestamp:
|
|
|
57 |
order.created_timestamp = to_py_date(t_order.created_timestamp)
|
|
|
58 |
else:
|
|
|
59 |
order.created_timestamp = datetime.datetime.now()
|
|
|
60 |
#these fields will not be populated in initial
|
|
|
61 |
"""
|
|
|
62 |
order.invoice_number = order.invoice_number
|
|
|
63 |
order.billed_by = order.billed_by
|
|
|
64 |
order.accepted_timestamp = order.accepted_timestamp
|
|
|
65 |
order.billing_timestamp = order.billing_timestamp
|
|
|
66 |
order.shipping_timestamp = order.shipping_timestamp
|
|
|
67 |
order.delivery_timestamp = order.delivery_timestamp
|
|
|
68 |
"""
|
|
|
69 |
return order
|
|
|
70 |
|
|
|
71 |
def create_transaction(t_transaction):
|
|
|
72 |
t_orders = t_transaction.orders
|
|
|
73 |
if not t_orders:
|
|
|
74 |
raise TransactionServiceException(101, "Orders missing from the transaction")
|
|
|
75 |
transaction = get_new_transaction()
|
|
|
76 |
transaction.customer_id = t_transaction.customer_id
|
|
|
77 |
transaction.shopping_cart_id = t_transaction.shoppingCartid
|
|
|
78 |
|
|
|
79 |
for t_order in t_orders:
|
|
|
80 |
order = create_order(t_order)
|
|
|
81 |
order.transaction = transaction
|
|
|
82 |
for line_item in t_order.lineitems:
|
|
|
83 |
litem = LineItem()
|
|
|
84 |
litem.sku_id = line_item.sku_id
|
|
|
85 |
litem.brand = line_item.brand
|
|
|
86 |
if line_item.model_number:
|
|
|
87 |
litem.model_number = line_item.model_number
|
|
|
88 |
if line_item.model_name:
|
|
|
89 |
litem.model_name = line_item.model_name
|
|
|
90 |
if line_item.extra_info:
|
|
|
91 |
litem.extra_info = line_item.extra_info
|
|
|
92 |
litem.quantity = line_item.quantity
|
|
|
93 |
litem.unit_price = line_item.unit_price
|
|
|
94 |
litem.unit_weight = line_item.unit_weight
|
|
|
95 |
litem.total_price = line_item.total_price
|
|
|
96 |
litem.total_weight = line_item.total_weight
|
|
|
97 |
"""
|
|
|
98 |
if line_item.addedOn:
|
|
|
99 |
litem.added_on = to_py_date(line_item.addedOn)
|
|
|
100 |
else:
|
|
|
101 |
litem.added_on = datetime.datetime.now()
|
|
|
102 |
"""
|
|
|
103 |
litem.order = order
|
|
|
104 |
|
|
|
105 |
#add payment info
|
|
|
106 |
#transaction.payments=[]
|
|
|
107 |
if t_transaction.paymentInfo:
|
|
|
108 |
if not t_transaction.paymentInfo.payments:
|
|
|
109 |
raise TransactionServiceException(108, "no payments found")
|
|
|
110 |
|
|
|
111 |
for k,v in t_transaction.paymentInfo.payments.iteritems():
|
|
|
112 |
payment = Payment()
|
|
|
113 |
payment.merchant_tx_id = v.merchant_tx_id
|
|
|
114 |
payment.bank_tx_id = v.bank_tx_id
|
|
|
115 |
payment.mode = v.mode
|
|
|
116 |
payment.amount = v.amount
|
|
|
117 |
payment.payment_id = v.id
|
|
|
118 |
payment.status = v.status
|
|
|
119 |
payment.status_message = v.description
|
|
|
120 |
payment.start_time = to_py_date(v.submissionTimestamp)
|
|
|
121 |
payment.finish_time = to_py_date(v.completionTimestamp)
|
|
|
122 |
transaction.payments.append(payment)
|
|
|
123 |
session.commit()
|
|
|
124 |
return transaction.id
|
|
|
125 |
|
|
|
126 |
def get_transaction(transaction_id):
|
|
|
127 |
transaction = Transaction.get_by(id=transaction_id)
|
|
|
128 |
if not transaction:
|
|
|
129 |
raise TransactionServiceException(108, "no such transaction")
|
|
|
130 |
|
|
|
131 |
return transaction
|
|
|
132 |
|
|
|
133 |
def get_transactions_for_customer(customer_id, from_date, to_date, status):
|
|
|
134 |
if not customer_id:
|
|
|
135 |
raise TransactionServiceException(101, "bad customer id")
|
|
|
136 |
query = Transaction.query.filter(Transaction.customer_id == customer_id)
|
|
|
137 |
if status:
|
|
|
138 |
query = query.filter(Transaction.status == status)
|
|
|
139 |
if from_date:
|
|
|
140 |
query = query.filter(Transaction.createdOn >from_date)
|
|
|
141 |
if to_date:
|
|
|
142 |
query = query.filter(Transaction.createdOn < to_date)
|
|
|
143 |
return query.all()
|
|
|
144 |
|
|
|
145 |
def get_transactions_for_shopping_cart_id(shopping_cart_id):
|
|
|
146 |
transactions = Transaction.query.filter_by(shopping_cart_id=shopping_cart_id).all()
|
|
|
147 |
if not transactions:
|
|
|
148 |
raise TransactionServiceException(108, "transactions for this shopping cart")
|
|
|
149 |
return transactions
|
|
|
150 |
|
|
|
151 |
def get_transaction_status(transaction_id):
|
|
|
152 |
if not transaction_id:
|
|
|
153 |
raise TransactionServiceException(101, "bad transaction id")
|
|
|
154 |
|
|
|
155 |
transaction = get_transaction(transaction_id)
|
|
|
156 |
|
|
|
157 |
return transaction.status
|
|
|
158 |
|
|
|
159 |
def change_transaction_status(transaction_id, new_status, description):
|
|
|
160 |
transaction = get_transaction(transaction_id)
|
|
|
161 |
transaction.status = new_status
|
|
|
162 |
transaction.status_message = description
|
|
|
163 |
session.commit()
|
|
|
164 |
return True
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
def get_order(order_id):
|
|
|
168 |
order = Order.get_by(id=order_id)
|
|
|
169 |
if not order:
|
|
|
170 |
raise TransactionServiceException(108, "no such order")
|
|
|
171 |
|
|
|
172 |
return order
|
|
|
173 |
|
|
|
174 |
def get_orders_for_customer(customer_id, from_date, to_date, status):
|
|
|
175 |
if not customer_id:
|
|
|
176 |
raise TransactionServiceException(101, "bad customer id")
|
|
|
177 |
query = Order.query.filter(Order.customer_id == customer_id)
|
|
|
178 |
if status:
|
|
|
179 |
query = query.filter(Order.status == status)
|
|
|
180 |
if from_date:
|
|
|
181 |
query = query.filter(Order.created_timestamp >from_date)
|
|
|
182 |
if to_date:
|
|
|
183 |
query = query.filter(Order.created_timestamp < to_date)
|
|
|
184 |
return query.all()
|
|
|
185 |
|
|
|
186 |
def get_all_orders(status, from_date, to_date, warehouse_id):
|
|
|
187 |
if not warehouse_id:
|
|
|
188 |
raise TransactionServiceException(101, "bad warehouse id")
|
|
|
189 |
query = Order.query.filter(Order.warehouse_id == warehouse_id)
|
|
|
190 |
if status:
|
|
|
191 |
query = query.filter(Order.status == status)
|
|
|
192 |
if from_date:
|
|
|
193 |
query = query.filter(Order.created_timestamp >from_date)
|
|
|
194 |
if to_date:
|
|
|
195 |
query = query.filter(Order.created_timestamp < to_date)
|
|
|
196 |
return query.all()
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
def change_order_status(self, orderId, status, description):
|
|
|
200 |
order = get_order(orderId)
|
|
|
201 |
order.status = status
|
|
|
202 |
order.statusDescription = description
|
|
|
203 |
session.commit()
|
|
|
204 |
return True
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
def get_orders_for_transaction(transaction_id):
|
|
|
208 |
orders = Order.query.filter_by(transaction_id=transaction_id).all()
|
|
|
209 |
if not orders:
|
|
|
210 |
raise TransactionServiceException(101, "No order for the transaction")
|
|
|
211 |
return orders
|
|
|
212 |
|
|
|
213 |
def get_line_items_for_order(order_id):
|
|
|
214 |
query = LineItem.query.filter(LineItem.order_id == order_id)
|
|
|
215 |
return query.all()
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
def get_alerts(order_id, all):
|
|
|
220 |
query = Alerts.query.filter_by(order_id=order_id)
|
|
|
221 |
if not all:
|
|
|
222 |
query = query.filter_by(valid=True)
|
|
|
223 |
return query.all()
|
|
|
224 |
|
|
|
225 |
def set_alert(order_id, unset, type, comment):
|
|
|
226 |
#get existing alert
|
|
|
227 |
if unset:
|
|
|
228 |
query = Alerts.query.filter_by(order_id=order_id)
|
|
|
229 |
query = query.filter_by(type=type)
|
|
|
230 |
alerts = query.all()
|
|
|
231 |
for alert in alerts:
|
|
|
232 |
if alert.valid:
|
|
|
233 |
alert.valid = False
|
|
|
234 |
alert.comment = comment
|
|
|
235 |
alert.time_unset = datetime.datetime.now()
|
|
|
236 |
else:
|
|
|
237 |
alert = Alerts()
|
|
|
238 |
alert.order_id = order_id
|
|
|
239 |
alert.valid = True
|
|
|
240 |
alert.type = type
|
|
|
241 |
alert.comment = comment
|
|
|
242 |
alert.time_set = datetime.datetime.now()
|
|
|
243 |
session.commit()
|
|
|
244 |
|
|
|
245 |
"""
|
|
|
246 |
def get_new_transaction():
|
|
|
247 |
transaction = Transaction()
|
|
|
248 |
transaction.createdOn = datetime.datetime.now()
|
|
|
249 |
transaction.status = status_transaction_init
|
|
|
250 |
transaction.status_message = "New transaction"
|
| 104 |
ashish |
251 |
transaction.trails = []
|
|
|
252 |
session.commit()
|
|
|
253 |
return transaction
|
|
|
254 |
|
|
|
255 |
def create_transaction(t_transaction):
|
|
|
256 |
orderinfo = t_transaction.orderInfo
|
|
|
257 |
if not orderinfo:
|
|
|
258 |
raise TransactionServiceException(101, "Orderinfo missing from the transaction")
|
|
|
259 |
transaction = get_new_transaction()
|
|
|
260 |
for line_item in orderinfo.lineitems:
|
|
|
261 |
litem = LineItem()
|
| 132 |
ashish |
262 |
if line_item.item.id:
|
|
|
263 |
litem.item_id = line_item.item.id
|
|
|
264 |
item_info = ItemInfo()
|
|
|
265 |
item_info.price = line_item.item.price
|
|
|
266 |
item_info.weight = line_item.item.weight
|
|
|
267 |
litem.item_info = item_info
|
| 104 |
ashish |
268 |
litem.added_on = to_py_date(line_item.addedOn)
|
|
|
269 |
transaction.lineitems.append(litem)
|
|
|
270 |
if line_item.additionalInfo:
|
|
|
271 |
for k,v in line_item.additionalInfo.iteritems():
|
|
|
272 |
additional_info = AdditionalInfo()
|
|
|
273 |
additional_info.key = k
|
|
|
274 |
additional_info.value = v
|
|
|
275 |
litem.additional_info.append(additional_info)
|
| 358 |
ashish |
276 |
if t_transaction.warehouse_id:
|
|
|
277 |
transaction.warehouse_id = t_transaction.warehouse_id
|
| 132 |
ashish |
278 |
if t_transaction.shoppingCartid:
|
|
|
279 |
transaction.shopping_cart_id = t_transaction.shoppingCartid
|
|
|
280 |
transaction.customer_id = t_transaction.customer_id
|
|
|
281 |
transaction.expected_delivery_time = to_py_date(t_transaction.expectedDeliveryTime)
|
| 194 |
ashish |
282 |
#no need to set status. It is already set.
|
|
|
283 |
#transaction.status = t_transaction.transactionStatus
|
| 132 |
ashish |
284 |
transaction.status_message = t_transaction.statusDescription
|
|
|
285 |
transaction.createdOn = to_py_date(t_transaction.createdOn)
|
| 104 |
ashish |
286 |
|
| 132 |
ashish |
287 |
#add payment info
|
|
|
288 |
#transaction.payments=[]
|
|
|
289 |
if t_transaction.paymentInfo:
|
|
|
290 |
if not t_transaction.paymentInfo.payments:
|
|
|
291 |
raise TransactionServiceException(108, "no payments found")
|
|
|
292 |
|
|
|
293 |
for k,v in t_transaction.paymentInfo.payments.iteritems():
|
|
|
294 |
payment = Payment()
|
|
|
295 |
payment.merchant_tx_id = v.merchant_tx_id
|
|
|
296 |
payment.bank_tx_id = v.bank_tx_id
|
|
|
297 |
payment.mode = v.mode
|
|
|
298 |
payment.amount = v.amount
|
|
|
299 |
payment.payment_id = v.id
|
|
|
300 |
payment.status = v.status
|
|
|
301 |
payment.status_message = v.description
|
|
|
302 |
payment.start_time = to_py_date(v.submissionTimestamp)
|
|
|
303 |
payment.finish_time = to_py_date(v.completionTimestamp)
|
|
|
304 |
transaction.payments.append(payment)
|
| 194 |
ashish |
305 |
if not t_transaction.shipmentInfo:
|
|
|
306 |
raise TransactionServiceException(109, "no shipping info attached with this")
|
|
|
307 |
transaction.shipments = []
|
|
|
308 |
for v in t_transaction.shipmentInfo.shipments:
|
|
|
309 |
shipment = Shipment()
|
|
|
310 |
shipment.weight = v.weight
|
|
|
311 |
shipment.insurance_value = v.insurance
|
|
|
312 |
shipment.status = get_c_status(v.status);
|
| 304 |
ashish |
313 |
shipment.address = v.address
|
| 194 |
ashish |
314 |
transaction.shipments.append(shipment)
|
| 104 |
ashish |
315 |
session.commit()
|
|
|
316 |
return transaction.id
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
def get_transaction(transaction_id):
|
|
|
320 |
transaction = Transaction.get_by(id=transaction_id)
|
|
|
321 |
if not transaction:
|
|
|
322 |
raise TransactionServiceException(108, "no such transaction")
|
|
|
323 |
|
|
|
324 |
return transaction
|
|
|
325 |
|
| 358 |
ashish |
326 |
def get_all_transactions(status, from_date, to_date, warehouse_id):
|
|
|
327 |
|
|
|
328 |
query = Transaction.query
|
|
|
329 |
if warehouse_id:
|
|
|
330 |
query = query.filter_by(warehouse_id=warehouse_id)
|
|
|
331 |
|
| 104 |
ashish |
332 |
if not status:
|
|
|
333 |
if not from_date and not to_date:
|
|
|
334 |
#get all between from_date and to_date
|
| 358 |
ashish |
335 |
return query.all()
|
| 104 |
ashish |
336 |
|
|
|
337 |
if not from_date:
|
| 358 |
ashish |
338 |
return query.filter(Transaction.createdOn < to_date).all()
|
| 104 |
ashish |
339 |
|
|
|
340 |
if not to_date:
|
| 358 |
ashish |
341 |
return query.filter(Transaction.createdOn > to_date).all()
|
|
|
342 |
return query.filter(and_(Transaction.createdOn < to_date , Transaction.createdOn > from_date)).all()
|
| 104 |
ashish |
343 |
|
|
|
344 |
|
|
|
345 |
if not from_date and not to_date:
|
| 358 |
ashish |
346 |
return query.filter(Transaction.status == status).all()
|
| 104 |
ashish |
347 |
if not from_date:
|
| 358 |
ashish |
348 |
return query.filter(and_(Transaction.status == status, Transaction.createdOn <to_date)).all()
|
| 104 |
ashish |
349 |
if not from_date:
|
| 358 |
ashish |
350 |
return query.filter(and_(Transaction.status == status, Transaction.createdOn >from_date)).all()
|
| 104 |
ashish |
351 |
if not from_date:
|
| 358 |
ashish |
352 |
return query.filter(and_(Transaction.status == status, and_(Transaction.createdOn <to_date, Transaction.createdOn > from_date))).all()
|
| 104 |
ashish |
353 |
|
|
|
354 |
|
|
|
355 |
def get_transactions_for_shipment_status(status, from_date, to_date):
|
|
|
356 |
|
|
|
357 |
if not status:
|
|
|
358 |
raise TransactionServiceException(101, "unknown status")
|
|
|
359 |
|
|
|
360 |
query = Shipment.query.filter(Shipment.status == status)
|
|
|
361 |
|
|
|
362 |
if from_date:
|
|
|
363 |
query = query.filter(Shipment.shipment_time >from_date)
|
|
|
364 |
if to_date:
|
|
|
365 |
query = query.filter(Shipment.shipment_time <to_date)
|
|
|
366 |
|
|
|
367 |
shipments = query.all()
|
|
|
368 |
|
|
|
369 |
transactions = {}
|
|
|
370 |
for shipment in shipments:
|
|
|
371 |
if not transactions[shipment.transaction.id]:
|
|
|
372 |
transactions.append(shipment.transaction)
|
|
|
373 |
return transactions.values()
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
def get_transactions_for_customer(customer_id, from_date, to_date, status):
|
|
|
377 |
if not customer_id:
|
|
|
378 |
raise TransactionServiceException(101, "bas customer id")
|
|
|
379 |
query = Transaction.query.filter(Transaction.customer_id == customer_id)
|
|
|
380 |
if status:
|
|
|
381 |
query = query.filter(Transaction.status == status)
|
|
|
382 |
if from_date:
|
|
|
383 |
query = query.filter(Transaction.createdOn >from_date)
|
|
|
384 |
if to_date:
|
|
|
385 |
query = query.filter(Transaction.createdOn < to_date)
|
|
|
386 |
return query.all()
|
|
|
387 |
|
|
|
388 |
def get_transactions_for_customer_shipment(customer_id, from_date, to_date, status):
|
|
|
389 |
|
|
|
390 |
if not customer_id:
|
|
|
391 |
raise TransactionServiceException(101, "unknown customer id")
|
|
|
392 |
|
|
|
393 |
query = Shipment.query.filter(Shipment.transaction.customerId == customer_id)
|
|
|
394 |
|
|
|
395 |
if status:
|
|
|
396 |
query = query.filter(Shipment.status == status)
|
|
|
397 |
|
|
|
398 |
if from_date:
|
|
|
399 |
query = query.filter(Shipment.shipment_time >from_date)
|
|
|
400 |
|
|
|
401 |
if to_date:
|
|
|
402 |
query = query.filter(Shipment.shipment_time <to_date)
|
|
|
403 |
|
|
|
404 |
shipments = query.all()
|
|
|
405 |
|
|
|
406 |
transactions = {}
|
|
|
407 |
for shipment in shipments:
|
|
|
408 |
if not transactions[shipment.transaction.id]:
|
|
|
409 |
transactions.append(shipment.transaction)
|
|
|
410 |
return transactions.values()
|
|
|
411 |
|
|
|
412 |
def get_transaction_status(transaction_id):
|
|
|
413 |
|
|
|
414 |
if not transaction_id:
|
|
|
415 |
raise TransactionServiceException(101, "bad transaction id")
|
|
|
416 |
|
|
|
417 |
transaction = get_transaction(transaction_id)
|
|
|
418 |
|
|
|
419 |
return transaction.status
|
|
|
420 |
|
|
|
421 |
def change_transaction_status(transaction_id, new_status, description):
|
|
|
422 |
transaction = get_transaction(transaction_id)
|
|
|
423 |
trail = TransactionTrail()
|
|
|
424 |
trail.old_value = str(transaction.status)
|
|
|
425 |
trail.new_value = str(new_status)
|
|
|
426 |
transaction.status = new_status
|
|
|
427 |
trail.transaction = transaction
|
|
|
428 |
trail.timestamp = datetime.datetime.now()
|
|
|
429 |
trail.description = description
|
|
|
430 |
transaction.status_message = description
|
|
|
431 |
session.commit()
|
|
|
432 |
return True
|
|
|
433 |
|
|
|
434 |
def set_shipping_tracker_info(transaction_id, shipping_id, tracking_id, airwayBillNo, provider):
|
|
|
435 |
shipment = Shipment.get_by(id=shipping_id)
|
|
|
436 |
if not shipment:
|
|
|
437 |
raise TransactionServiceException(101, "not such shipment found")
|
|
|
438 |
|
|
|
439 |
transaction = shipment.transaction
|
|
|
440 |
if transaction.id != transaction_id:
|
|
|
441 |
raise TransactionServiceException(108, "Looks like this is invalid transaction")
|
|
|
442 |
shipment.tracking_id = tracking_id
|
|
|
443 |
shipment.airway_bill_no = airwayBillNo
|
|
|
444 |
shipment.provider = provider
|
|
|
445 |
trail = TransactionTrail()
|
|
|
446 |
trail.timestamp = datetime.datetime.now()
|
|
|
447 |
trail.description = "shipping_id %d:tracking_id %s:airwayBill %s: provider %s" %(shipping_id, tracking_id, airwayBillNo, provider)
|
|
|
448 |
trail.transaction = transaction
|
|
|
449 |
session.commit()
|
|
|
450 |
return True
|
|
|
451 |
|
|
|
452 |
def change_shipping_status(transaction_id, shipping_id, status, description):
|
|
|
453 |
shipment = Shipment.get_by(id=shipping_id)
|
|
|
454 |
if not shipment:
|
|
|
455 |
raise TransactionServiceException(101, "not such shipment found")
|
|
|
456 |
|
|
|
457 |
transaction = shipment.transaction
|
|
|
458 |
if transaction.id != transaction_id:
|
|
|
459 |
raise TransactionServiceException(108, "Looks like this is invalid transaction")
|
|
|
460 |
|
|
|
461 |
trail = TransactionTrail()
|
|
|
462 |
trail.old_value = str(shipment.status)
|
|
|
463 |
trail.new_value = str(status)
|
|
|
464 |
shipment.status = status
|
|
|
465 |
trail.transaction = transaction
|
|
|
466 |
trail.timestamp = datetime.datetime.now()
|
|
|
467 |
trail.description = "Shipping status change : %s"%(description)
|
|
|
468 |
shipment.status_message = description
|
|
|
469 |
session.commit()
|
|
|
470 |
return True
|
|
|
471 |
|
|
|
472 |
def set_shipping_date(transaction_id, shipping_id, timestamp):
|
|
|
473 |
shipment = Shipment.get_by(id=shipping_id)
|
|
|
474 |
if not shipment:
|
|
|
475 |
raise TransactionServiceException(101, "not such shipment found")
|
|
|
476 |
|
|
|
477 |
transaction = shipment.transaction
|
|
|
478 |
if transaction.id != transaction_id:
|
|
|
479 |
raise TransactionServiceException(108, "Looks like this is invalid transaction")
|
|
|
480 |
|
|
|
481 |
trail = TransactionTrail()
|
|
|
482 |
trail.old_value = str(shipment.status)
|
|
|
483 |
trail.new_value = str(status_shipment_shipped)
|
|
|
484 |
shipment.status = status_shipment_shipped
|
|
|
485 |
trail.transaction = transaction
|
|
|
486 |
trail.timestamp = datetime.datetime.now()
|
|
|
487 |
trail.description = "Shipping status change : %s"%(shipment.id)
|
|
|
488 |
shipment.status_message = "Shipment dispatched"
|
|
|
489 |
shipment.shipment_time = timestamp
|
|
|
490 |
session.commit()
|
|
|
491 |
return True
|
|
|
492 |
|
|
|
493 |
|
|
|
494 |
def set_delivery_date(transaction_id, shipping_id, timestamp):
|
|
|
495 |
shipment = Shipment.get_by(id=shipping_id)
|
|
|
496 |
if not shipment:
|
|
|
497 |
raise TransactionServiceException(101, "not such shipment found")
|
|
|
498 |
|
|
|
499 |
transaction = shipment.transaction
|
|
|
500 |
if transaction.id != transaction_id:
|
|
|
501 |
raise TransactionServiceException(108, "Looks like this is invalid transaction")
|
|
|
502 |
|
|
|
503 |
trail = TransactionTrail()
|
|
|
504 |
trail.old_value = str(shipment.status)
|
|
|
505 |
trail.new_value = str(status_shipment_delivered)
|
|
|
506 |
shipment.status = status_shipment_delivered
|
|
|
507 |
trail.transaction = transaction
|
|
|
508 |
trail.timestamp = datetime.datetime.now()
|
|
|
509 |
trail.description = "Shipping status change : %s"%(shipment.id)
|
|
|
510 |
shipment.status_message = "Shipment delivered"
|
|
|
511 |
shipment.delivery_time = timestamp
|
|
|
512 |
session.commit()
|
|
|
513 |
return True
|
|
|
514 |
|
|
|
515 |
def set_billing(transaction_id, t_billing):
|
|
|
516 |
transaction = get_transaction(transaction_id)
|
| 194 |
ashish |
517 |
line_item = LineItem.query.filter_by(transaction_id=transaction_id).all()
|
|
|
518 |
#line_item = LineItem.get_by(id = t_billing.lineItem.id)
|
| 104 |
ashish |
519 |
if not line_item:
|
|
|
520 |
raise TransactionServiceException(101, "unable to get this line item for id %d" % (t_billing.lineItem.id))
|
|
|
521 |
billing = Billing()
|
|
|
522 |
billing.line_item = line_item
|
|
|
523 |
billing.bill_number = t_billing.billNumber
|
|
|
524 |
try:
|
|
|
525 |
billing.created_on = to_py_date(t_billing.generatedTimestamp)
|
|
|
526 |
except:
|
|
|
527 |
raise TransactionServiceException(108, "bad time stamp found while adding billing for transaction id %d" %(transaction.id))
|
| 194 |
ashish |
528 |
billing.generated_by = t_billing.generatedBy
|
| 104 |
ashish |
529 |
session.commit()
|
|
|
530 |
return True
|
|
|
531 |
|
|
|
532 |
def get_line_items(transaction_id):
|
|
|
533 |
transaction = get_transaction(transaction_id)
|
|
|
534 |
if not transaction.lineitems:
|
|
|
535 |
raise TransactionServiceException(108, "no lineitems with transaction %d"%(transaction_id))
|
|
|
536 |
return transaction.lineitems
|
|
|
537 |
|
|
|
538 |
def get_shipments(transaction_id):
|
|
|
539 |
transaction = get_transaction(transaction_id)
|
|
|
540 |
if not transaction.shipments:
|
|
|
541 |
raise TransactionServiceException(108, "no shipments with transaction %d"%(transaction_id))
|
|
|
542 |
return transaction.shipments
|
|
|
543 |
|
|
|
544 |
def get_billings(transaction_id):
|
|
|
545 |
transaction = get_transaction(transaction_id)
|
|
|
546 |
if not transaction.lineitems:
|
|
|
547 |
raise TransactionServiceException(108, "no lineitems, hence no billing with transaction %d"%(transaction_id))
|
|
|
548 |
billings = []
|
|
|
549 |
for lineitem in transaction.lineitems:
|
|
|
550 |
billings.append(lineitem.billing)
|
|
|
551 |
return billings
|
| 132 |
ashish |
552 |
return transaction.shipments
|
|
|
553 |
|
|
|
554 |
def get_transactions_for_shopping_cart_id(shopping_cart_id):
|
|
|
555 |
transactions = Transaction.query.filter_by(shopping_cart_id=shopping_cart_id).all()
|
|
|
556 |
if not transactions:
|
|
|
557 |
raise TransactionServiceException(108, "transactions for this shopping cart")
|
| 304 |
ashish |
558 |
return transactions
|
|
|
559 |
|
|
|
560 |
def get_alerts(transaction_id, all):
|
|
|
561 |
query = Alerts.query.filter_by(transaction_id=transaction_id)
|
|
|
562 |
if not all:
|
|
|
563 |
query = query.filter_by(valid=True)
|
|
|
564 |
return query.all()
|
|
|
565 |
|
|
|
566 |
def set_alert(transaction_id, unset, type, comment):
|
|
|
567 |
#get existing alert
|
|
|
568 |
if unset:
|
|
|
569 |
query = Alerts.query.filter_by(transaction_id=transaction_id)
|
|
|
570 |
query = query.filter_by(type=type)
|
|
|
571 |
alerts = query.all()
|
|
|
572 |
for alert in alerts:
|
|
|
573 |
if alert.valid:
|
|
|
574 |
alert.valid = False
|
|
|
575 |
alert.comment = comment
|
|
|
576 |
alert.time_unset = datetime.datetime.now()
|
|
|
577 |
else:
|
|
|
578 |
alert = Alerts()
|
|
|
579 |
alert.transaction_id = transaction_id
|
|
|
580 |
alert.valid = True
|
|
|
581 |
alert.type = type
|
|
|
582 |
alert.comment = comment
|
|
|
583 |
alert.time_set = datetime.datetime.now()
|
|
|
584 |
session.commit()
|
|
|
585 |
|
|
|
586 |
def get_extra_info(transaction_id):
|
|
|
587 |
return ExtraItemInfo.get_by(transaction_id=transaction_id)
|
|
|
588 |
|
|
|
589 |
def set_extra_info(transaction_id, sku_id, model, vendor, colour):
|
|
|
590 |
extra_item_info = ExtraItemInfo()
|
|
|
591 |
extra_item_info.transaction_id = transaction_id
|
|
|
592 |
extra_item_info.sku_id = sku_id
|
|
|
593 |
extra_item_info.model = model
|
|
|
594 |
extra_item_info.vendor = vendor
|
|
|
595 |
extra_item_info.colour = colour
|
| 483 |
rajveer |
596 |
session.commit()
|
|
|
597 |
"""
|