Skip to content

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

Simplify delivery groups #10, fix misspell

Michal Ociepkacc65272b81ba
diff --git a/cart/__init__.py b/cart/__init__.py
index 198a86aa94..9dbc9964e3 100755
--- a/cart/__init__.py
+++ b/cart/__init__.py
@@ -1,37 +1,27 @@
from django.conf import settings
from django.utils.translation import ugettext
from itertools import groupby
+from order.models import DigitalDeliveryGroup, ShippedDeliveryGroup
from prices import Price
-from product.models import StockedProduct
+from product.models import StockedProduct, DigitalShip
from satchless import cart
from satchless.item import Item, ItemLine, ItemSet, Partitioner
from userprofile.forms import AddressForm
import datetime
-class BaseDeliveryGroup(ItemSet):
-
- def get_total(self, **kwargs):
- return (super(BaseDeliveryGroup, self).get_total(**kwargs) +
- self.get_delivery_total(**kwargs))
-
- def get_delivery_total(self, **kwargs):
- methods = self.get_delivery_methods()
- return min(method.get_price_per_item(**kwargs) for method in methods)
-
- def get_delivery_methods(self, **kwargs):
- raise NotImplemented()
-
- def __repr__(self):
- return '%s(%r)' % (self.__class__.__name__, list(self))
-
-
class CartPartitioner(Partitioner):
def __iter__(self):
- for _key, items in groupby(self.subject,
- lambda cart_item: type(cart_item.product)):
- yield BaseDeliveryGroup(items)
+ for product_class, items in groupby(
+ self.subject,
+ lambda cart_item: cart_item.product.__class__):
+ delivery_class = ShippedDeliveryGroup
+ if issubclass(product_class, DigitalShip):
+ delivery_class = DigitalDeliveryGroup
+ delivery = delivery_class()
+ delivery.extend(items)
+ yield delivery
def get_delivery_subtotal(self, partion, **kwargs):
return partion.get_delivery_total(**kwargs)
diff --git a/delivery/__init__.py b/delivery/__init__.py
index cd81c75f92..970476535e 100644
--- a/delivery/__init__.py
+++ b/delivery/__init__.py
@@ -1,8 +1,6 @@
from django.conf import settings
from prices import Price
from satchless.item import Item
-from userprofile.forms import AddressForm
-from product.models import PhisicalProduct, DigitalShip
class BaseDelivery(Item):
diff --git a/order/models.py b/order/models.py
index 1a9c03d7ab..5ad115d25b 100644
--- a/order/models.py
+++ b/order/models.py
@@ -1,4 +1,3 @@
-from cart import BaseDeliveryGroup
from django.conf import settings
from django.db import models
from django.utils.translation import pgettext_lazy
@@ -112,7 +111,7 @@ class DeliveryGroupManager(models.Manager):
return group
-class DeliveryGroup(Subtyped, BaseDeliveryGroup):
+class DeliveryGroup(Subtyped, ItemSet):
order = models.ForeignKey('order', related_name='groups', editable=False)
price = PriceField(
@@ -124,6 +123,20 @@ class DeliveryGroup(Subtyped, BaseDeliveryGroup):
objects = DeliveryGroupManager()
+ def get_total(self, **kwargs):
+ return (super(DeliveryGroup, self).get_total(**kwargs) +
+ self.get_delivery_total(**kwargs))
+
+ def get_delivery_total(self, **kwargs):
+ methods = self.get_delivery_methods()
+ return min(method.get_price_per_item(**kwargs) for method in methods)
+
+ def get_delivery_methods(self, **kwargs):
+ raise NotImplemented()
+
+ def __repr__(self):
+ return '%s(%r)' % (self.__class__.__name__, list(self))
+
class ShippedDeliveryGroup(DeliveryGroup):
diff --git a/product/models.py b/product/models.py
index 4831f8a5b8..1139693efd 100644
--- a/product/models.py
+++ b/product/models.py
@@ -135,7 +135,7 @@ class StockedProduct(models.Model):
abstract = True
-class PhisicalProduct(models.Model):
+class PhysicalProduct(models.Model):
weight = models.PositiveIntegerField()
length = models.PositiveIntegerField(blank=True, default=0)
@@ -151,6 +151,6 @@ class DigitalShip(Product):
url = models.URLField()
-class Ship(Product, StockedProduct, PhisicalProduct):
+class Ship(Product, StockedProduct, PhysicalProduct):
pass