remove items from successful physical purchase.
modified: make_post_sell/models/cart.py modified: make_post_sell/models/invoice.py modified: make_post_sell/views/cart.py
This commit is contained in:
parent
03e61e9863
commit
8e9d704f60
3 changed files with 26 additions and 3 deletions
|
|
@ -300,7 +300,6 @@ class Cart(RBase, Base):
|
|||
)
|
||||
return self._discounted_shop_totals
|
||||
|
||||
|
||||
@property
|
||||
def total_price_in_cents(self):
|
||||
"""
|
||||
|
|
@ -456,7 +455,27 @@ class Cart(RBase, Base):
|
|||
elif self.handling_option == "local_shipping":
|
||||
self.handling_cost_in_cents = shop_location.local_shipping_rate_in_cents
|
||||
elif self.handling_option == "international_shipping":
|
||||
self.handling_cost_in_cents = shop_location.international_shipping_rate_in_cents
|
||||
self.handling_cost_in_cents = (
|
||||
shop_location.international_shipping_rate_in_cents
|
||||
)
|
||||
|
||||
def update_inventory(self, shop_location):
|
||||
"""
|
||||
Update the inventory quantity for physical products in the cart.
|
||||
"""
|
||||
changed = False
|
||||
for product_id, product in self.physical_products.items():
|
||||
quantity_needed = self.cart[product_id]
|
||||
inventory = get_inventory_by_product_and_shop_location(
|
||||
self.dbsession, product_id, shop_location.uuid_str
|
||||
)
|
||||
if inventory:
|
||||
inventory.quantity -= quantity_needed
|
||||
self.dbsession.add(inventory)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
self.dbsession.flush()
|
||||
|
||||
|
||||
def get_all_carts(dbsession):
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class Invoice(RBase, Base):
|
|||
def total_in_cents(self):
|
||||
"""Calculate the total amount in cents for the invoice, including handling fee."""
|
||||
line_items_total = sum(
|
||||
item.price_in_cents * item.quantity for item in self.line_items
|
||||
item.price.price_in_cents * item.quantity for item in self.line_items
|
||||
)
|
||||
return line_items_total + (self.handling_cost_in_cents or 0)
|
||||
|
||||
|
|
|
|||
|
|
@ -465,6 +465,7 @@ def cart_complete_checkout(request):
|
|||
for shop_id, product_quantity_tuple in cart.shop_product_dict.items():
|
||||
shop = cart.shops[shop_id]
|
||||
invoice = Invoice(user=request.user)
|
||||
invoice.shop = shop
|
||||
invoice.shop_id = shop.id
|
||||
invoice.handling_option = cart.handling_option
|
||||
invoice.handling_cost_in_cents = cart.handling_cost_in_cents
|
||||
|
|
@ -522,6 +523,9 @@ def cart_complete_checkout(request):
|
|||
break
|
||||
|
||||
if successful_checkout:
|
||||
# Update inventory for physical products
|
||||
cart.update_inventory(request.shop_location)
|
||||
|
||||
# flush changes to database because charge was successful!
|
||||
request.dbsession.flush()
|
||||
msg = ("Success, you have completed the purchase!", "success")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue