| Line 21... |
Line 21... |
| 21 |
OrderStatus, OrderSource
|
21 |
OrderStatus, OrderSource
|
| 22 |
from shop2020.thriftpy.model.v1.user.ttypes import CartStatus, LineStatus, \
|
22 |
from shop2020.thriftpy.model.v1.user.ttypes import CartStatus, LineStatus, \
|
| 23 |
ShoppingCartException, PromotionException, CartPlus
|
23 |
ShoppingCartException, PromotionException, CartPlus
|
| 24 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
24 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 25 |
import datetime
|
25 |
import datetime
|
| - |
|
26 |
import math
|
| 26 |
|
27 |
|
| 27 |
|
28 |
|
| 28 |
|
29 |
|
| 29 |
|
30 |
|
| 30 |
def get_cart(userId):
|
31 |
def get_cart(userId):
|
| Line 235... |
Line 236... |
| 235 |
session.commit()
|
236 |
session.commit()
|
| 236 |
|
237 |
|
| 237 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
238 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
| 238 |
cart = get_cart_by_id(cart_id)
|
239 |
cart = get_cart_by_id(cart_id)
|
| 239 |
#now we have a cart. Need to create a transaction with it
|
240 |
#now we have a cart. Need to create a transaction with it
|
| - |
|
241 |
totalCartVal = 0
|
| - |
|
242 |
totalshippingCost = 0
|
| - |
|
243 |
for lineObj in cart.lines:
|
| - |
|
244 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
| 240 |
txn = TTransaction()
|
245 |
txn = TTransaction()
|
| 241 |
txn.shoppingCartid = cart_id
|
246 |
txn.shoppingCartid = cart_id
|
| 242 |
txn.customer_id = userId
|
247 |
txn.customer_id = userId
|
| 243 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
248 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
| 244 |
txn.transactionStatus = TTransactionStatus.INIT
|
249 |
txn.transactionStatus = TTransactionStatus.INIT
|
| Line 247... |
Line 252... |
| 247 |
txn.sessionSource = sessionSource
|
252 |
txn.sessionSource = sessionSource
|
| 248 |
txn.sessionStartTime = sessionTime
|
253 |
txn.sessionStartTime = sessionTime
|
| 249 |
txn.firstSource = firstSource
|
254 |
txn.firstSource = firstSource
|
| 250 |
txn.firstSourceTime = firstSourceTime
|
255 |
txn.firstSourceTime = firstSourceTime
|
| 251 |
txn.emiSchemeId = schemeId
|
256 |
txn.emiSchemeId = schemeId
|
| - |
|
257 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
| - |
|
258 |
if privateDealUser is not None:
|
| - |
|
259 |
if totalCartVal < 500:
|
| - |
|
260 |
totalshippingCost = 100
|
| - |
|
261 |
elif totalCartVal >=500 and totalCartVal<1000:
|
| - |
|
262 |
totalshippingCost = 50
|
| - |
|
263 |
txn.totalShippingCost = totalshippingCost
|
| - |
|
264 |
|
| 252 |
txn.orders = create_orders(cart, userId, orderSource)
|
265 |
txnOrders = create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal)
|
| - |
|
266 |
shippingCostInOrders = 0
|
| - |
|
267 |
for order in txnOrders:
|
| - |
|
268 |
shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
| - |
|
269 |
|
| - |
|
270 |
diff = totalshippingCost - shippingCostInOrders
|
| - |
|
271 |
if diff > 0:
|
| - |
|
272 |
txnOrders[0].shippingCost = txnOrders[0].shippingCost + diff
|
| - |
|
273 |
|
| - |
|
274 |
|
| - |
|
275 |
txn.orders = txnOrders
|
| 253 |
|
276 |
|
| 254 |
transaction_client = TransactionClient().get_client()
|
277 |
transaction_client = TransactionClient().get_client()
|
| 255 |
txn_id = transaction_client.createTransaction(txn)
|
278 |
txn_id = transaction_client.createTransaction(txn)
|
| 256 |
|
279 |
|
| 257 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
280 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
| Line 259... |
Line 282... |
| 259 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
282 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
| 260 |
session.commit()
|
283 |
session.commit()
|
| 261 |
|
284 |
|
| 262 |
return txn_id
|
285 |
return txn_id
|
| 263 |
|
286 |
|
| 264 |
def create_orders(cart, userId, orderSource):
|
287 |
def create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal):
|
| 265 |
cart_lines = cart.lines
|
288 |
cart_lines = cart.lines
|
| 266 |
orders = []
|
289 |
orders = []
|
| 267 |
isGv = False
|
290 |
isGv = False
|
| 268 |
if cart.coupon_code:
|
291 |
if cart.coupon_code:
|
| 269 |
try:
|
292 |
try:
|
| Line 277... |
Line 300... |
| 277 |
for line in cart_lines:
|
300 |
for line in cart_lines:
|
| 278 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
301 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
| 279 |
quantity_remaining_for_order = line.quantity
|
302 |
quantity_remaining_for_order = line.quantity
|
| 280 |
|
303 |
|
| 281 |
for discount in line.discounts:
|
304 |
for discount in line.discounts:
|
| 282 |
i = 0
|
305 |
#i = 0
|
| 283 |
while i < discount.quantity:
|
306 |
#while i < discount.quantity:
|
| 284 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount))
|
307 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount), line.quantity)
|
| 285 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, discount.discount if isGv else 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails,line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId)
|
308 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, discount.discount if isGv else 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails,line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, totalshippingCost, totalCartVal)
|
| 286 |
orders.append(t_order)
|
309 |
orders.append(t_order)
|
| 287 |
i += 1
|
310 |
#i += 1
|
| 288 |
quantity_remaining_for_order -= discount.quantity
|
311 |
quantity_remaining_for_order -= discount.quantity
|
| 289 |
|
312 |
|
| - |
|
313 |
if quantity_remaining_for_order > 0:
|
| - |
|
314 |
t_line_item = create_line_item(line, line.actual_price, quantity_remaining_for_order)
|
| - |
|
315 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails, line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, totalshippingCost)
|
| - |
|
316 |
orders.append(t_order)
|
| - |
|
317 |
'''
|
| 290 |
i = 0
|
318 |
i = 0
|
| 291 |
while i < quantity_remaining_for_order:
|
319 |
while i < quantity_remaining_for_order:
|
| 292 |
t_line_item = create_line_item(line, line.actual_price)
|
320 |
t_line_item = create_line_item(line, line.actual_price)
|
| 293 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails, line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId)
|
321 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails, line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId)
|
| 294 |
orders.append(t_order)
|
322 |
orders.append(t_order)
|
| 295 |
i += 1
|
323 |
i += 1
|
| - |
|
324 |
'''
|
| 296 |
return orders
|
325 |
return orders
|
| 297 |
|
326 |
|
| 298 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId):
|
327 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, totalshippingCost, totalCartVal):
|
| 299 |
user = User.get_by(id=userId)
|
328 |
user = User.get_by(id=userId)
|
| 300 |
address = Address.get_by(id=address_id)
|
329 |
address = Address.get_by(id=address_id)
|
| 301 |
t_order = TOrder()
|
330 |
t_order = TOrder()
|
| 302 |
|
331 |
|
| 303 |
t_order.customer_id = user.id
|
332 |
t_order.customer_id = user.id
|
| Line 337... |
Line 366... |
| 337 |
else:
|
366 |
else:
|
| 338 |
freebie_item_id = None if freebieId == 0 else freebieId
|
367 |
freebie_item_id = None if freebieId == 0 else freebieId
|
| 339 |
t_order.source = orderSource
|
368 |
t_order.source = orderSource
|
| 340 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
369 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
| 341 |
t_order.dataProtectionAmount = dataProtectionAmount
|
370 |
t_order.dataProtectionAmount = dataProtectionAmount
|
| - |
|
371 |
t_order.shippingCost = round((t_line_item.total_price/totalCartVal)*totalshippingCost, 0)
|
| 342 |
return t_order
|
372 |
return t_order
|
| 343 |
|
373 |
|
| 344 |
def create_line_item(line, final_price, quantity=1):
|
374 |
def create_line_item(line, final_price, quantity=1):
|
| 345 |
inventory_client = CatalogClient().get_client()
|
375 |
inventory_client = CatalogClient().get_client()
|
| 346 |
item = inventory_client.getItem(line.item_id)
|
376 |
item = inventory_client.getItem(line.item_id)
|