Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Simplify delivery groups #10, fix misspell
Michal Ociepkacc65272b81ba
diff --git a/cart/__init__.py b/cart/__init__.pyindex 198a86aa94..9dbc9964e3 100755--- a/cart/__init__.py+++ b/cart/__init__.py@@ -1,37 +1,27 @@from django.conf import settingsfrom django.utils.translation import ugettextfrom itertools import groupby+from order.models import DigitalDeliveryGroup, ShippedDeliveryGroupfrom prices import Price-from product.models import StockedProduct+from product.models import StockedProduct, DigitalShipfrom satchless import cartfrom satchless.item import Item, ItemLine, ItemSet, Partitionerfrom userprofile.forms import AddressFormimport 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 deliverydef get_delivery_subtotal(self, partion, **kwargs):return partion.get_delivery_total(**kwargs)diff --git a/delivery/__init__.py b/delivery/__init__.pyindex cd81c75f92..970476535e 100644--- a/delivery/__init__.py+++ b/delivery/__init__.py@@ -1,8 +1,6 @@from django.conf import settingsfrom prices import Pricefrom satchless.item import Item-from userprofile.forms import AddressForm-from product.models import PhisicalProduct, DigitalShipclass BaseDelivery(Item):diff --git a/order/models.py b/order/models.pyindex 1a9c03d7ab..5ad115d25b 100644--- a/order/models.py+++ b/order/models.py@@ -1,4 +1,3 @@-from cart import BaseDeliveryGroupfrom django.conf import settingsfrom django.db import modelsfrom 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.pyindex 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