Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix issues after refactoring

Anna Siwik1d8e14896706
diff --git a/saleor/cart/models.py b/saleor/cart/models.py
index 90a92b9a8b..405d254f62 100644
--- a/saleor/cart/models.py
+++ b/saleor/cart/models.py
@@ -36,6 +36,13 @@ class ProductGroup(list):
"""Return `True` if any product in group requires shipping."""
return any(p.is_shipping_required() for p in self)
+ def get_total(self, discounts=None):
+ subtotals = [line.get_total(discounts) for line in self]
+ if not subtotals:
+ raise AttributeError(
+ 'Calling get_total() on an empty product group')
+ return sum(subtotals[1:], subtotals[0])
+
class CartQueryset(models.QuerySet):
"""A specialized queryset for dealing with carts."""
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 641a8e13ce..e6b9400de0 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -156,14 +156,14 @@ class Product(models.Model):
def set_attribute(self, pk, value_pk):
self.attributes[smart_text(pk)] = smart_text(value_pk)
- def get_price_range(self, discounts=None, **kwargs):
+ def get_price_per_item(self, item, discounts=None):
+ return item.get_price_per_item(discounts)
+
+ def get_price_range(self, discounts=None):
if self.variants.exists():
prices = [
self.get_price_per_item(variant, discounts=discounts)
for variant in self]
- if not prices:
- raise AttributeError(
- 'Calling get_price_range() on a product without variants')
return PriceRange(min(prices), max(prices))
price = calculate_discounted_price(self, self.price, discounts)
return PriceRange(price, price)
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index e77805ec8c..0e702bbda4 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -44,8 +44,7 @@ def test_variant_discounts(product_in_stock):
type=DiscountValueType.FIXED,
value=50)
high_discount.products.add(product_in_stock)
- final_price = variant.get_price_per_item(
- discounts=Sale.objects.all())
+ final_price = variant.get_price_per_item(discounts=Sale.objects.all())
assert final_price.gross == 0
applied_discount = final_price.history.right
assert isinstance(applied_discount, FixedDiscount)