| Line 11... |
Line 11... |
| 11 |
from shop2020.model.v1 import user
|
11 |
from shop2020.model.v1 import user
|
| 12 |
from shop2020.model.v1.user.impl.Dataservice import Cart, Line, Address, User, \
|
12 |
from shop2020.model.v1.user.impl.Dataservice import Cart, Line, Address, User, \
|
| 13 |
Discount, InsuranceDetails
|
13 |
Discount, InsuranceDetails
|
| 14 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
14 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
| 15 |
DeliveryType
|
15 |
DeliveryType
|
| 16 |
from shop2020.thriftpy.model.v1.catalog.ttypes import Item
|
16 |
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, InsurerType
|
| 17 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as TTransaction, \
|
17 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction as TTransaction, \
|
| 18 |
TransactionStatus as TTransactionStatus, Order as TOrder, LineItem as TLineItem, \
|
18 |
TransactionStatus as TTransactionStatus, Order as TOrder, LineItem as TLineItem, \
|
| 19 |
OrderStatus, OrderSource
|
19 |
OrderStatus, OrderSource
|
| 20 |
from shop2020.thriftpy.model.v1.user.ttypes import CartStatus, LineStatus, \
|
20 |
from shop2020.thriftpy.model.v1.user.ttypes import CartStatus, LineStatus, \
|
| 21 |
ShoppingCartException, PromotionException
|
21 |
ShoppingCartException, PromotionException
|
| Line 86... |
Line 86... |
| 86 |
if not cart:
|
86 |
if not cart:
|
| 87 |
raise ShoppingCartException(101, "no cart attached to this id" + str(cart_id))
|
87 |
raise ShoppingCartException(101, "no cart attached to this id" + str(cart_id))
|
| 88 |
retval = ""
|
88 |
retval = ""
|
| 89 |
catalog_client = CatalogClient().get_client()
|
89 |
catalog_client = CatalogClient().get_client()
|
| 90 |
item = catalog_client.getItemForSource(item_id, sourceId)
|
90 |
item = catalog_client.getItemForSource(item_id, sourceId)
|
| - |
|
91 |
dataProtectionInsurer = catalog_client.getPrefferedInsurerForItem(item_id,InsurerType._NAMES_TO_VALUES.get("DATA"))
|
| 91 |
item_shipping_info = catalog_client.isActive(item_id)
|
92 |
item_shipping_info = catalog_client.isActive(item_id)
|
| 92 |
if not item_shipping_info.isActive:
|
93 |
if not item_shipping_info.isActive:
|
| 93 |
return catalog_client.getItemStatusDescription(item_id)
|
94 |
return catalog_client.getItemStatusDescription(item_id)
|
| 94 |
|
95 |
|
| 95 |
current_time = datetime.datetime.now()
|
96 |
current_time = datetime.datetime.now()
|
| Line 98... |
Line 99... |
| 98 |
if line:
|
99 |
if line:
|
| 99 |
#change the quantity only
|
100 |
#change the quantity only
|
| 100 |
line.insuranceAmount = (line.insuranceAmount/line.quantity) * quantity
|
101 |
line.insuranceAmount = (line.insuranceAmount/line.quantity) * quantity
|
| 101 |
line.quantity = quantity
|
102 |
line.quantity = quantity
|
| 102 |
line.updated_on = current_time
|
103 |
line.updated_on = current_time
|
| - |
|
104 |
line.dataProtectionAmount = (line.dataProtectionAmount/line.quantity) * quantity
|
| 103 |
else:
|
105 |
else:
|
| 104 |
line = Line()
|
106 |
line = Line()
|
| 105 |
line.cart = cart
|
107 |
line.cart = cart
|
| 106 |
line.item_id = item_id
|
108 |
line.item_id = item_id
|
| 107 |
line.quantity = quantity
|
109 |
line.quantity = quantity
|
| Line 109... |
Line 111... |
| 109 |
line.updated_on = current_time
|
111 |
line.updated_on = current_time
|
| 110 |
line.actual_price = item.sellingPrice
|
112 |
line.actual_price = item.sellingPrice
|
| 111 |
line.line_status = LineStatus.LINE_ACTIVE
|
113 |
line.line_status = LineStatus.LINE_ACTIVE
|
| 112 |
line.insurer = 0
|
114 |
line.insurer = 0
|
| 113 |
line.insuranceAmount = 0
|
115 |
line.insuranceAmount = 0
|
| - |
|
116 |
#DATA INSURER IS SET UPON ADD TO CART
|
| - |
|
117 |
line.dataProtectionInsurer = dataProtectionInsurer
|
| 114 |
session.commit()
|
118 |
session.commit()
|
| 115 |
return retval
|
119 |
return retval
|
| 116 |
|
120 |
|
| 117 |
def delete_item_from_cart(cart_id, item_id):
|
121 |
def delete_item_from_cart(cart_id, item_id):
|
| 118 |
if not item_id:
|
122 |
if not item_id:
|
| Line 266... |
Line 270... |
| 266 |
|
270 |
|
| 267 |
for discount in line.discounts:
|
271 |
for discount in line.discounts:
|
| 268 |
i = 0
|
272 |
i = 0
|
| 269 |
while i < discount.quantity:
|
273 |
while i < discount.quantity:
|
| 270 |
t_line_item = create_line_item(line.item_id, line.actual_price if isGv else (line.actual_price - discount.discount))
|
274 |
t_line_item = create_line_item(line.item_id, line.actual_price if isGv else (line.actual_price - discount.discount))
|
| 271 |
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)
|
275 |
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)
|
| 272 |
orders.append(t_order)
|
276 |
orders.append(t_order)
|
| 273 |
i += 1
|
277 |
i += 1
|
| 274 |
quantity_remaining_for_order -= discount.quantity
|
278 |
quantity_remaining_for_order -= discount.quantity
|
| 275 |
|
279 |
|
| 276 |
i = 0
|
280 |
i = 0
|
| 277 |
while i < quantity_remaining_for_order:
|
281 |
while i < quantity_remaining_for_order:
|
| 278 |
t_line_item = create_line_item(line.item_id, line.actual_price)
|
282 |
t_line_item = create_line_item(line.item_id, line.actual_price)
|
| 279 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails)
|
283 |
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)
|
| 280 |
orders.append(t_order)
|
284 |
orders.append(t_order)
|
| 281 |
i += 1
|
285 |
i += 1
|
| 282 |
return orders
|
286 |
return orders
|
| 283 |
|
287 |
|
| 284 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails):
|
288 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount):
|
| 285 |
user = User.get_by(id=userId)
|
289 |
user = User.get_by(id=userId)
|
| 286 |
address = Address.get_by(id=address_id)
|
290 |
address = Address.get_by(id=address_id)
|
| 287 |
t_order = TOrder()
|
291 |
t_order = TOrder()
|
| 288 |
|
292 |
|
| 289 |
t_order.customer_id = user.id
|
293 |
t_order.customer_id = user.id
|
| Line 295... |
Line 299... |
| 295 |
t_order.customer_address2 = address.line_2
|
299 |
t_order.customer_address2 = address.line_2
|
| 296 |
t_order.customer_city = address.city
|
300 |
t_order.customer_city = address.city
|
| 297 |
t_order.customer_state = address.state
|
301 |
t_order.customer_state = address.state
|
| 298 |
t_order.customer_mobilenumber = address.phone
|
302 |
t_order.customer_mobilenumber = address.phone
|
| 299 |
|
303 |
|
| 300 |
t_order.total_amount = t_line_item.total_price + insuranceAmount
|
304 |
t_order.total_amount = t_line_item.total_price + insuranceAmount + dataProtectionAmount
|
| 301 |
t_order.gvAmount = gvAmount
|
305 |
t_order.gvAmount = gvAmount
|
| 302 |
|
306 |
|
| 303 |
t_order.total_weight = t_line_item.total_weight
|
307 |
t_order.total_weight = t_line_item.total_weight
|
| 304 |
t_order.lineitems = [t_line_item]
|
308 |
t_order.lineitems = [t_line_item]
|
| 305 |
|
309 |
|
| Line 317... |
Line 321... |
| 317 |
catalog_client = CatalogClient().get_client()
|
321 |
catalog_client = CatalogClient().get_client()
|
| 318 |
freebie_item_id = catalog_client.getFreebieForItem(t_line_item.item_id)
|
322 |
freebie_item_id = catalog_client.getFreebieForItem(t_line_item.item_id)
|
| 319 |
if freebie_item_id:
|
323 |
if freebie_item_id:
|
| 320 |
t_order.freebieItemId = freebie_item_id
|
324 |
t_order.freebieItemId = freebie_item_id
|
| 321 |
t_order.source = OrderSource.WEBSITE
|
325 |
t_order.source = OrderSource.WEBSITE
|
| - |
|
326 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
| - |
|
327 |
t_order.dataProtectionAmount = dataProtectionAmount
|
| 322 |
return t_order
|
328 |
return t_order
|
| 323 |
|
329 |
|
| 324 |
def create_line_item(item_id, final_price, quantity=1):
|
330 |
def create_line_item(item_id, final_price, quantity=1):
|
| 325 |
inventory_client = CatalogClient().get_client()
|
331 |
inventory_client = CatalogClient().get_client()
|
| 326 |
item = inventory_client.getItem(item_id)
|
332 |
item = inventory_client.getItem(item_id)
|
| Line 425... |
Line 431... |
| 425 |
|
431 |
|
| 426 |
cart = Cart.get_by(id=cartId)
|
432 |
cart = Cart.get_by(id=cartId)
|
| 427 |
cart_lines = cart.lines
|
433 |
cart_lines = cart.lines
|
| 428 |
for line in cart_lines :
|
434 |
for line in cart_lines :
|
| 429 |
if line.insurer > 0 :
|
435 |
if line.insurer > 0 :
|
| 430 |
insure_item(line.item_id, cartId, True)
|
436 |
insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DEVICE"))
|
| 431 |
|
437 |
if line.dataProtectionInsurer > 0:
|
| - |
|
438 |
insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DATA"))
|
| 432 |
if cart.coupon_code is not None:
|
439 |
if cart.coupon_code is not None:
|
| 433 |
try:
|
440 |
try:
|
| 434 |
updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
|
441 |
updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
|
| 435 |
# totalInsuranceAmt = 0
|
442 |
# totalInsuranceAmt = 0
|
| 436 |
# for t_line in updated_cart.lines:
|
443 |
# for t_line in updated_cart.lines:
|
| Line 548... |
Line 555... |
| 548 |
if line is not None:
|
555 |
if line is not None:
|
| 549 |
return True
|
556 |
return True
|
| 550 |
else:
|
557 |
else:
|
| 551 |
return False
|
558 |
return False
|
| 552 |
|
559 |
|
| 553 |
def insure_item(itemId, cartId, toInsure):
|
560 |
def insure_item(itemId, cartId, toInsure, insurerType):
|
| 554 |
cart = Cart.get_by(id = cartId)
|
561 |
cart = Cart.get_by(id = cartId)
|
| 555 |
line = None
|
562 |
line = None
|
| 556 |
for cartLine in cart.lines:
|
563 |
for cartLine in cart.lines:
|
| 557 |
if(cartLine.item_id == itemId):
|
564 |
if(cartLine.item_id == itemId):
|
| 558 |
line = cartLine
|
565 |
line = cartLine
|
| Line 564... |
Line 571... |
| 564 |
|
571 |
|
| 565 |
try:
|
572 |
try:
|
| 566 |
if toInsure:
|
573 |
if toInsure:
|
| 567 |
csc = CatalogClient().get_client()
|
574 |
csc = CatalogClient().get_client()
|
| 568 |
item = csc.getItem(itemId)
|
575 |
item = csc.getItem(itemId)
|
| - |
|
576 |
insurerId = csc.getPrefferedInsurerForItem(itemId,insurerType)
|
| 569 |
insuranceAmount = csc.getInsuranceAmount(itemId, line.discounted_price if line.discounted_price else line.actual_price, item.preferredInsurer, line.quantity)
|
577 |
insuranceAmount = csc.getInsuranceAmount(itemId, line.discounted_price if line.discounted_price else line.actual_price, insurerId, line.quantity)
|
| - |
|
578 |
if InsurerType._VALUES_TO_NAMES.get(insurerType)=='DEVICE':
|
| - |
|
579 |
if cart.discounted_price:
|
| - |
|
580 |
cart.discounted_price = cart.discounted_price - line.insuranceAmount + insuranceAmount
|
| 570 |
line.insurer = item.preferredInsurer
|
581 |
line.insurer = insurerId
|
| 571 |
line.insuranceAmount = insuranceAmount
|
582 |
line.insuranceAmount = insuranceAmount
|
| - |
|
583 |
if InsurerType._VALUES_TO_NAMES.get(insurerType)=='DATA':
|
| - |
|
584 |
if cart.discounted_price:
|
| - |
|
585 |
cart.discounted_price = cart.discounted_price - line.dataProtectionAmount + insuranceAmount
|
| - |
|
586 |
line.dataProtectionInsurer = insurerId
|
| - |
|
587 |
line.dataProtectionAmount = insuranceAmount
|
| 572 |
cart.total_price = cart.total_price + insuranceAmount
|
588 |
cart.total_price = cart.total_price + insuranceAmount
|
| 573 |
if cart.discounted_price:
|
- |
|
| 574 |
cart.discounted_price = cart.discounted_price - line.insuranceAmount + insuranceAmount
|
- |
|
| 575 |
else:
|
589 |
else:
|
| - |
|
590 |
if InsurerType._VALUES_TO_NAMES.get(insurerType)=='DEVICE':
|
| 576 |
cart.total_price = cart.total_price - line.insuranceAmount
|
591 |
cart.total_price = cart.total_price - line.insuranceAmount
|
| 577 |
if cart.discounted_price:
|
592 |
if cart.discounted_price:
|
| 578 |
cart.discounted_price = cart.discounted_price - line.insuranceAmount
|
593 |
cart.discounted_price = cart.discounted_price - line.insuranceAmount
|
| 579 |
line.insurer = 0
|
594 |
line.insurer = 0
|
| 580 |
line.insuranceAmount = 0
|
595 |
line.insuranceAmount = 0
|
| - |
|
596 |
if InsurerType._VALUES_TO_NAMES.get(insurerType)=='DATA':
|
| - |
|
597 |
cart.total_price = cart.total_price - line.dataProtectionAmount
|
| - |
|
598 |
if cart.discounted_price:
|
| - |
|
599 |
cart.discounted_price = cart.discounted_price - line.dataProtectionAmount
|
| - |
|
600 |
line.dataProtectionInsurer = 0
|
| - |
|
601 |
line.dataProtectionAmount = 0
|
| 581 |
line.updated_on = datetime.datetime.now()
|
602 |
line.updated_on = datetime.datetime.now()
|
| 582 |
cart.updated_on = datetime.datetime.now()
|
603 |
cart.updated_on = datetime.datetime.now()
|
| 583 |
session.commit()
|
604 |
session.commit()
|
| 584 |
except:
|
605 |
except:
|
| 585 |
print("Error : Unable to insure")
|
606 |
print("Error : Unable to insure")
|
| 586 |
print("insurerId : " + str(item.preferredInsurer) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
|
607 |
print("insurerId : " + str(insurerId) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
|
| 587 |
return False
|
608 |
return False
|
| 588 |
|
609 |
|
| 589 |
return True
|
610 |
return True
|
| 590 |
|
611 |
|
| 591 |
def cancel_insurance(cartId):
|
612 |
def cancel_insurance(cartId):
|