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