Skip to content

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

Remove satchless from product app

Anna Siwik7a822835d5fa
diff --git a/saleor/product/forms.py b/saleor/product/forms.py
index 8a3db2067a..59f99c536a 100644
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -17,7 +17,8 @@ class VariantChoiceField(forms.ModelChoiceField):
'Variant choice field label',
'%(variant_label)s - %(price)s') % {
'variant_label': variant_label,
- 'price': gross(obj.get_price(discounts=self.discounts))}
+ 'price': gross(
+ obj.get_price_per_item(discounts=self.discounts))}
return label
def update_field_data(self, variants, cart):
diff --git a/saleor/product/models.py b/saleor/product/models.py
index d291559711..99f7c23bd1 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -14,7 +14,7 @@ from django_prices.models import Price, PriceField
from mptt.managers import TreeManager
from mptt.models import MPTTModel
from prices import PriceRange
-from satchless.item import InsufficientStock, Item, ItemRange
+from satchless.item import InsufficientStock
from text_unidecode import unidecode
from versatileimagefield.fields import PPOIField, VersatileImageField
@@ -87,7 +87,7 @@ class ProductQuerySet(models.QuerySet):
Q(is_published=True))
-class Product(models.Model, ItemRange):
+class Product(models.Model):
product_type = models.ForeignKey(
ProductType, related_name='products', on_delete=models.CASCADE)
name = models.CharField(max_length=128)
@@ -158,19 +158,27 @@ class Product(models.Model, ItemRange):
def get_price_range(self, discounts=None, **kwargs):
if self.variants.exists():
- return super().get_price_range(discounts=discounts, **kwargs)
+ 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)
- def get_gross_price_range(self, **kwargs):
- grosses = [self.get_price_per_item(item, **kwargs) for item in self]
+ def get_gross_price_range(self, discounts=None):
+ grosses = [
+ self.get_price_per_item(variant, discounts=discounts)
+ for variant in self]
if not grosses:
return None
grosses = sorted(grosses, key=lambda x: x.tax)
return PriceRange(min(grosses), max(grosses))
-class ProductVariant(models.Model, Item):
+class ProductVariant(models.Model):
sku = models.CharField(max_length=32, unique=True)
name = models.CharField(max_length=100, blank=True)
price_override = PriceField(
@@ -195,7 +203,7 @@ class ProductVariant(models.Model, Item):
def get_stock_quantity(self):
return sum([stock.quantity_available for stock in self.stock.all()])
- def get_price_per_item(self, discounts=None, **kwargs):
+ def get_price_per_item(self, discounts=None):
price = self.price_override or self.product.price
price = calculate_discounted_price(self.product, price, discounts)
return price
diff --git a/saleor/product/templatetags/discount.py b/saleor/product/templatetags/discount.py
index 33359da591..4773d7201c 100644
--- a/saleor/product/templatetags/discount.py
+++ b/saleor/product/templatetags/discount.py
@@ -5,7 +5,7 @@ register = template.Library()
@register.filter
def discounted_price(item, discounts):
- return item.get_price(discounts=discounts)
+ return item.get_price_per_item(discounts=discounts)
@register.filter
diff --git a/templates/dashboard/product/product_variant/detail.html b/templates/dashboard/product/product_variant/detail.html
index 2dd09fc343..b18b316f8e 100644
--- a/templates/dashboard/product/product_variant/detail.html
+++ b/templates/dashboard/product/product_variant/detail.html
@@ -53,7 +53,7 @@
<p class="text-padding">{% trans "Sale price" context "Dashboard variant details view" %}</p>
</div>
<div class="col s7 m6">
- <p class="text-padding right-align">{% gross variant.get_price %}</p>
+ <p class="text-padding right-align">{% gross variant.get_price_per_item %}</p>
</div>
<div class="col s5 m6">
<p class="text-padding">{% trans "Cost price range" context "Dashboard variant details view" %}</p>