Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions ecommerce/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,18 @@ def __str__(self):

@property
def shipping(self):
shipping = False
orderitems = self.orderitem_set.all()
for i in orderitems:
if i.product.digital == False:
shipping = True
return shipping
return any(i.product.digital == False for i in orderitems)
Comment on lines -42 to +43
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Order.shipping refactored with the following changes:


@property
def get_cart_total(self):
orderitems = self.orderitem_set.all()
total = sum([item.get_total for item in orderitems])
return total
return sum(item.get_total for item in orderitems)
Comment on lines -52 to +48
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Order.get_cart_total refactored with the following changes:


@property
def get_cart_items(self):
orderitems = self.orderitem_set.all()
total = sum([item.quantity for item in orderitems])
return total
return sum(item.quantity for item in orderitems)
Comment on lines -58 to +53
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Order.get_cart_items refactored with the following changes:


class OrderItem(models.Model):
product = models.ForeignKey(Product,on_delete=models.SET_NULL, blank=True, null=True)
Expand All @@ -66,8 +60,7 @@ class OrderItem(models.Model):

@property
def get_total(self):
total = self.product.price * self.quantity
return total
return self.product.price * self.quantity
Comment on lines -69 to +63
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OrderItem.get_total refactored with the following changes:




Expand Down
4 changes: 2 additions & 2 deletions ecommerce/store/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def cookieCart(request):
order = {'get_cart_total': 0, 'get_cart_items': 0, 'shipping': False}
cartItems = order['get_cart_items']

for i in cart:
for i, value in cart.items():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function cookieCart refactored with the following changes:

try:
cartItems += cart[i]['quantity']

product = Product.objects.get(id=i)
total = (product.price * cart[i]['quantity'])

order['get_cart_total'] += total
order['get_cart_items'] += cart[i]['quantity']
order['get_cart_items'] += value['quantity']

item = {
'product': {
Expand Down