| Line 240... |
Line 240... |
| 240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
| 241 |
cart = get_cart_by_id(cart_id)
|
241 |
cart = get_cart_by_id(cart_id)
|
| 242 |
#now we have a cart. Need to create a transaction with it
|
242 |
#now we have a cart. Need to create a transaction with it
|
| 243 |
totalCartVal = 0
|
243 |
totalCartVal = 0
|
| 244 |
totalQty = 0
|
244 |
totalQty = 0
|
| - |
|
245 |
itemIds = []
|
| - |
|
246 |
for line in cart.lines:
|
| - |
|
247 |
itemIds.append(line.item_id)
|
| - |
|
248 |
inventory_client = CatalogClient().get_client()
|
| - |
|
249 |
itemsMap = inventory_client.getItems(itemIds)
|
| 245 |
for lineObj in cart.lines:
|
250 |
for lineObj in cart.lines:
|
| - |
|
251 |
item = itemsMap.get(lineObj.item_id)
|
| 246 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
252 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
| - |
|
253 |
if item.category in [10006, 10010]:
|
| 247 |
totalQty += lineObj.quantity
|
254 |
totalQty += lineObj.quantity
|
| 248 |
txn = TTransaction()
|
255 |
txn = TTransaction()
|
| 249 |
txn.shoppingCartid = cart_id
|
256 |
txn.shoppingCartid = cart_id
|
| 250 |
txn.customer_id = userId
|
257 |
txn.customer_id = userId
|
| 251 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
258 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
| 252 |
txn.transactionStatus = TTransactionStatus.INIT
|
259 |
txn.transactionStatus = TTransactionStatus.INIT
|
| Line 266... |
Line 273... |
| 266 |
perUnitShippingCost = 60
|
273 |
perUnitShippingCost = 60
|
| 267 |
|
274 |
|
| 268 |
|
275 |
|
| 269 |
txn.totalShippingCost = perUnitShippingCost * totalQty
|
276 |
txn.totalShippingCost = perUnitShippingCost * totalQty
|
| 270 |
|
277 |
|
| 271 |
txnOrders = create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal)
|
278 |
txnOrders = create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal, itemsMap)
|
| 272 |
# shippingCostInOrders = 0
|
279 |
# shippingCostInOrders = 0
|
| 273 |
# for order in txnOrders:
|
280 |
# for order in txnOrders:
|
| 274 |
# shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
281 |
# shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
| 275 |
|
282 |
|
| 276 |
#diff = totalshippingCost - shippingCostInOrders
|
283 |
#diff = totalshippingCost - shippingCostInOrders
|
| Line 287... |
Line 294... |
| 287 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
294 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
| 288 |
session.commit()
|
295 |
session.commit()
|
| 289 |
|
296 |
|
| 290 |
return txn_id
|
297 |
return txn_id
|
| 291 |
|
298 |
|
| 292 |
def create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal):
|
299 |
def create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal, itemsMap):
|
| 293 |
cart_lines = cart.lines
|
300 |
cart_lines = cart.lines
|
| 294 |
orders = []
|
301 |
orders = []
|
| 295 |
isGv = False
|
302 |
isGv = False
|
| 296 |
if cart.coupon_code:
|
303 |
if cart.coupon_code:
|
| 297 |
try:
|
304 |
try:
|
| Line 299... |
Line 306... |
| 299 |
isGv = pc.isGiftVoucher(cart.coupon_code)
|
306 |
isGv = pc.isGiftVoucher(cart.coupon_code)
|
| 300 |
except:
|
307 |
except:
|
| 301 |
isGv = False
|
308 |
isGv = False
|
| 302 |
|
309 |
|
| 303 |
insuranceDetails = InsuranceDetails.get_by(addressId = cart.address_id)
|
310 |
insuranceDetails = InsuranceDetails.get_by(addressId = cart.address_id)
|
| 304 |
itemIds = []
|
- |
|
| 305 |
for line in cart_lines:
|
- |
|
| 306 |
itemIds.append(line.item_id)
|
- |
|
| 307 |
inventory_client = CatalogClient().get_client()
|
- |
|
| 308 |
itemsMap = inventory_client.getItems(itemIds)
|
- |
|
| - |
|
311 |
|
| 309 |
for line in cart_lines:
|
312 |
for line in cart_lines:
|
| 310 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
313 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
| 311 |
quantity_remaining_for_order = line.quantity
|
314 |
quantity_remaining_for_order = line.quantity
|
| 312 |
|
315 |
|
| 313 |
for discount in line.discounts:
|
316 |
for discount in line.discounts:
|
| 314 |
#i = 0
|
317 |
#i = 0
|
| 315 |
#while i < discount.quantity:
|
318 |
#while i < discount.quantity:
|
| 316 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount), line.quantity, itemsMap.get(line.item_id))
|
319 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount), line.quantity, itemsMap.get(line.item_id))
|
| 317 |
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, perUnitShippingCost, totalCartVal)
|
320 |
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, perUnitShippingCost, itemsMap.get(line.item_id))
|
| 318 |
orders.append(t_order)
|
321 |
orders.append(t_order)
|
| 319 |
#i += 1
|
322 |
#i += 1
|
| 320 |
quantity_remaining_for_order -= discount.quantity
|
323 |
quantity_remaining_for_order -= discount.quantity
|
| 321 |
|
324 |
|
| 322 |
if quantity_remaining_for_order > 0:
|
325 |
if quantity_remaining_for_order > 0:
|
| 323 |
t_line_item = create_line_item(line, line.actual_price, quantity_remaining_for_order, itemsMap.get(line.item_id))
|
326 |
t_line_item = create_line_item(line, line.actual_price, quantity_remaining_for_order, itemsMap.get(line.item_id))
|
| 324 |
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, perUnitShippingCost, totalCartVal)
|
327 |
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, perUnitShippingCost, totalCartVal)
|
| 325 |
orders.append(t_order)
|
328 |
orders.append(t_order)
|
| 326 |
'''
|
- |
|
| 327 |
i = 0
|
- |
|
| 328 |
while i < quantity_remaining_for_order:
|
- |
|
| 329 |
t_line_item = create_line_item(line, line.actual_price)
|
- |
|
| 330 |
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)
|
329 |
|
| 331 |
orders.append(t_order)
|
- |
|
| 332 |
i += 1
|
- |
|
| 333 |
'''
|
- |
|
| 334 |
|
330 |
|
| 335 |
wallet_amount = cart.wallet_amount
|
331 |
wallet_amount = cart.wallet_amount
|
| 336 |
if wallet_amount is None:
|
332 |
if wallet_amount is None:
|
| 337 |
wallet_amount = 0
|
333 |
wallet_amount = 0
|
| 338 |
print "adjusting wallet_amount ***",wallet_amount
|
334 |
print "adjusting wallet_amount ***",wallet_amount
|
| Line 344... |
Line 340... |
| 344 |
|
340 |
|
| 345 |
order.net_payable_amount = order.total_amount+ order.shippingCost - order.gvAmount - order.wallet_amount
|
341 |
order.net_payable_amount = order.total_amount+ order.shippingCost - order.gvAmount - order.wallet_amount
|
| 346 |
wallet_amount = wallet_amount - order.wallet_amount
|
342 |
wallet_amount = wallet_amount - order.wallet_amount
|
| 347 |
return orders
|
343 |
return orders
|
| 348 |
|
344 |
|
| 349 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, perUnitShippingCost, totalCartVal):
|
345 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, perUnitShippingCost, item):
|
| 350 |
user = User.get_by(id=userId)
|
346 |
user = User.get_by(id=userId)
|
| 351 |
address = Address.get_by(id=address_id)
|
347 |
address = Address.get_by(id=address_id)
|
| 352 |
t_order = TOrder()
|
348 |
t_order = TOrder()
|
| 353 |
|
349 |
|
| 354 |
t_order.customer_id = user.id
|
350 |
t_order.customer_id = user.id
|
| Line 388... |
Line 384... |
| 388 |
else:
|
384 |
else:
|
| 389 |
freebie_item_id = None if freebieId == 0 else freebieId
|
385 |
freebie_item_id = None if freebieId == 0 else freebieId
|
| 390 |
t_order.source = orderSource
|
386 |
t_order.source = orderSource
|
| 391 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
387 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
| 392 |
t_order.dataProtectionAmount = dataProtectionAmount
|
388 |
t_order.dataProtectionAmount = dataProtectionAmount
|
| 393 |
#t_order.shippingCost = round((t_line_item.total_price*totalshippingCost)/totalCartVal, 0)
|
389 |
if item.category in [10006, 10010]:
|
| 394 |
t_order.shippingCost = perUnitShippingCost*t_line_item.quantity
|
390 |
t_order.shippingCost = perUnitShippingCost*t_line_item.quantity
|
| 395 |
return t_order
|
391 |
return t_order
|
| 396 |
|
392 |
|
| 397 |
def create_line_item(line, final_price, quantity=1, item=None):
|
393 |
def create_line_item(line, final_price, quantity=1, item=None):
|
| 398 |
if item is None:
|
394 |
if item is None:
|
| 399 |
inventory_client = CatalogClient().get_client()
|
395 |
inventory_client = CatalogClient().get_client()
|