Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move shipping data to order
Patryk Zawadzkifa884f0f5ff1
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.pyindex 9a73347631..e7a22bffb4 100755--- a/saleor/cart/__init__.py+++ b/saleor/cart/__init__.py@@ -5,7 +5,7 @@ from django.utils.translation import pgettextfrom django.utils.encoding import python_2_unicode_compatible, smart_textfrom prices import Pricefrom satchless import cart-from satchless.item import ItemList+from satchless.item import ItemList, Partitionerfrom saleor.product.models import Product@@ -93,6 +93,8 @@ class Cart(cart.Cart):def create_line(self, product, quantity, data):return CartLine(product, quantity, data=data, discounts=self.discounts)+ def partition(self):+ return Partitioner(self)class SessionCartLine(cart.CartLine):diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex 75ebecf378..1cafedfb44 100755--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -4,7 +4,6 @@ from django.contrib import messagesfrom django.shortcuts import redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import ugettext as _-from satchless.item import Partitionerfrom .forms import ReplaceCartLineFormSetfrom . import Cart@@ -12,7 +11,7 @@ from . import Cartdef index(request):cart = Cart.for_session_cart(request.cart, discounts=request.discounts)- cart_partitioner = Partitioner(cart)+ cart_partitioner = cart.partition()formset = ReplaceCartLineFormSet(request.POST or None,cart=cart)if formset.is_valid():diff --git a/saleor/checkout/__init__.py b/saleor/checkout/__init__.pyindex 36bca57f2e..7df966375e 100644--- a/saleor/checkout/__init__.py+++ b/saleor/checkout/__init__.py@@ -3,11 +3,9 @@ from collections import defaultdictfrom django.conf import settingsfrom prices import Pricefrom satchless.process import ProcessManager-from satchless.item import Partitioner-from .steps import (BillingAddressStep, ShippingStep, DigitalDeliveryStep,- SummaryStep)-from ..cart import DigitalGroup, Cart+from .steps import BillingAddressStep, ShippingStep, SummaryStep+from ..cart import Cartfrom ..core import analyticsfrom ..order.models import Orderfrom ..userprofile.models import Address@@ -45,21 +43,14 @@ class Checkout(ProcessManager):self.generate_steps(self.cart)def generate_steps(self, cart):- self.items = Partitioner(cart)+ self.cart = cartself.billing = BillingAddressStep(self.request, self.get_storage('billing'))self.steps.append(self.billing)- for index, delivery_group in enumerate(self.items):- if isinstance(delivery_group, DigitalGroup):- storage = self.get_storage('digital_%s' % (index,))- step = DigitalDeliveryStep(- self.request, storage, delivery_group, _id=index)- else:- storage = self.get_storage('shipping_%s' % (index,))- step = ShippingStep(- self.request, storage, delivery_group, _id=index,- default_address=self.billing_address)- self.steps.append(step)+ self.shipping = ShippingStep(+ self.request, self.get_storage('shipping'),+ self.cart, default_address=self.billing_address)+ self.steps.append(self.shipping)summary_step = SummaryStep(self.request, self.get_storage('summary'), checkout=self)self.steps.append(summary_step)@@ -95,14 +86,32 @@ class Checkout(ProcessManager):storage = self.get_storage('billing')storage['address'] = None+ @property+ def shipping_address(self):+ storage = self.get_storage('shipping')+ address_data = storage.get('address', {})+ return Address(**address_data)++ @shipping_address.setter+ def shipping_address(self, address):+ storage = self.get_storage('shipping')+ storage['address'] = address.as_data()++ @shipping_address.deleter+ def shipping_address(self):+ storage = self.get_storage('shipping')+ storage['address'] = None+def get_storage(self, name):return self.storage[name]def get_total(self, **kwargs):zero = Price(0, currency=settings.DEFAULT_CURRENCY)- total = sum((step.group.get_total_with_delivery(**kwargs)- for step in self if step.group),- zero)+ total = sum(+ (total_with_delivery+ for delivery, delivery_cost, total_with_delivery+ in self.deliveries(**kwargs)),+ zero)return totaldef save(self):@@ -115,8 +124,12 @@ class Checkout(ProcessManager):def __iter__(self):return iter(self.steps)- def delivery_steps(self):- return [step for step in self.steps if step.group]+ def deliveries(self, **kwargs):+ for partition in self.cart.partition():+ delivery_cost = self.shipping.delivery_method.get_delivery_total(+ partition)+ total_with_delivery = partition.get_total(**kwargs) + delivery_cost+ yield partition, delivery_cost, total_with_deliverydef create_order(self):order = Order()diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.pyindex 4732a182b1..c76beb32a1 100644--- a/saleor/checkout/forms.py+++ b/saleor/checkout/forms.py@@ -2,7 +2,6 @@ from django import formsfrom django.contrib.auth.models import AnonymousUserfrom django.utils.translation import ugettext_lazy as _-from ..order.models import DigitalDeliveryGroupfrom ..userprofile.forms import AddressForm@@ -11,21 +10,6 @@ class ShippingForm(AddressForm):use_billing = forms.BooleanField(initial=True)-class DigitalDeliveryForm(forms.ModelForm):-- class Meta:- model = DigitalDeliveryGroup- fields = ['email']-- def __init__(self, *args, **kwargs):- user = kwargs.pop('user', None) or AnonymousUser()- super(DigitalDeliveryForm, self).__init__(*args, **kwargs)- email = self.fields['email']- email.required = True- if user.is_authenticated():- email.initial = user.email--class DeliveryForm(forms.Form):method = forms.ChoiceField(label=_('Shipping method'))diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.pyindex c9d0babfc2..a42835dc24 100644--- a/saleor/checkout/steps.py+++ b/saleor/checkout/steps.py@@ -4,15 +4,13 @@ from django.core.exceptions import ValidationErrorfrom django.db import modelsfrom django.db import transactionfrom django.shortcuts import redirect-from django.utils.encoding import smart_textfrom django.utils.translation import ugettext_lazy as _from satchless.process import InvalidData-from .forms import DigitalDeliveryForm, DeliveryForm+from .forms import DeliveryFormfrom ..checkout.forms import AnonymousEmailFormfrom ..core.utils import BaseStep-from ..delivery import get_delivery_choices_for_group-from ..order.models import DigitalDeliveryGroup, ShippedDeliveryGroup+from ..delivery import get_delivery_options_for_itemsfrom ..userprofile.forms import AddressFormfrom ..userprofile.models import Address, User@@ -123,7 +121,6 @@ class BillingAddressStep(BaseAddressStep):self.address.save()order.anonymous_user_email = self.anonymous_user_emailorder.billing_address = self.address- order.save()if order.user:alias = '%s, %s' % (order, self)User.objects.store_address(order.user, self.address, alias,@@ -138,11 +135,11 @@ class BillingAddressStep(BaseAddressStep):class ShippingStep(BaseAddressStep):template = 'checkout/shipping.html'- title = _('Shipping Details')+ title = _('Shipping Address')- def __init__(self, request, storage, purchased_items, _id=None,+ def __init__(self, request, storage, cart,default_address=None):- self.id = _id+ self.cart = cartaddress_data = storage.get('address', {})if not address_data and default_address:address = default_address@@ -150,23 +147,24 @@ class ShippingStep(BaseAddressStep):address = Address(**address_data)super(ShippingStep, self).__init__(request, storage, address)delivery_choices = list(- get_delivery_choices_for_group(purchased_items, address=address))- selected_delivery_name = storage.get('delivery_method')- # TODO: find cheapest not first- (selected_delivery_group_name,- selected_delivery_group) = delivery_choices[0]- for delivery_name, delivery in delivery_choices:- if delivery_name == selected_delivery_name:- selected_delivery_group = delivery- selected_delivery_group_name = delivery_name+ (m.name, m) for m in get_delivery_options_for_items(+ self.cart, address=address))+ selected_method_name = storage.get('delivery_method')+ selected_method = None+ for method_name, method in delivery_choices:+ if method_name == selected_method_name:+ selected_method = methodbreak- self.group = selected_delivery_group+ if selected_method is None:+ # TODO: find cheapest not first+ selected_method_name, selected_method = delivery_choices[0]+ self.delivery_method = selected_methodself.forms['delivery'] = DeliveryForm(delivery_choices, request.POST or None,- initial={'method': selected_delivery_group_name})+ initial={'method': selected_method_name})def __str__(self):- return 'delivery-%s' % (self.id,)+ return 'shipping-address'def save(self):delivery_form = self.forms['delivery']@@ -188,11 +186,13 @@ class ShippingStep(BaseAddressStep):def add_to_order(self, order):self.address.save()- group = ShippedDeliveryGroup.objects.create(- order=order, address=self.address,- price=self.group.get_delivery_total(),- method=self.group.name)- group.add_items_from_partition(self.group)+ order.shipping_method = self.delivery_method.name+ order.shipping_address = self.address+ order.save()+ for partition in self.cart.partition():+ group = order.groups.create(+ price=self.delivery_method.get_delivery_total(partition))+ group.add_items_from_partition(partition)if order.user:alias = '%s, %s' % (order, self)User.objects.store_address(order.user, self.address, alias,@@ -200,53 +200,10 @@ class ShippingStep(BaseAddressStep):def process(self, extra_context=None):context = dict(extra_context or {})- context['items'] = self.groupcontext['delivery_form'] = self.forms['delivery']return super(ShippingStep, self).process(extra_context=context)-class DigitalDeliveryStep(BaseCheckoutStep):-- template = 'checkout/digitaldelivery.html'- title = _('Digital Delivery')-- def __init__(self, request, storage, items_group=None, _id=None):- super(DigitalDeliveryStep, self).__init__(request, storage)- self.id = _id- self.forms['email'] = DigitalDeliveryForm(request.POST or None,- initial=self.storage,- user=request.user)- email = self.storage.get('email')- delivery_choices = list(- get_delivery_choices_for_group(items_group, email=email))- selected_delivery_group = delivery_choices[0][1]- self.storage['delivery_method'] = selected_delivery_group- self.group = selected_delivery_group-- def __str__(self):- return 'digital-delivery-%s' % (self.id,)-- def validate(self):- if not 'email' in self.storage:- raise InvalidData()-- def save(self):- self.storage.update(self.forms['email'].cleaned_data)-- def add_to_order(self, order):- group = DigitalDeliveryGroup.objects.create(- order=order, email=self.storage['email'],- price=self.group.get_delivery_total(),- method=self.group.name)- group.add_items_from_partition(self.group)-- def process(self, extra_context=None):- context = dict(extra_context or {})- context['form'] = self.forms['email']- context['items'] = self.group- return super(DigitalDeliveryStep, self).process(extra_context=context)--class SummaryStep(BaseCheckoutStep):template = 'checkout/summary.html'diff --git a/saleor/checkout/templates/checkout/shipping.html b/saleor/checkout/templates/checkout/shipping.htmlindex 13f7a1021e..02c2783ce7 100644--- a/saleor/checkout/templates/checkout/shipping.html+++ b/saleor/checkout/templates/checkout/shipping.html@@ -4,35 +4,6 @@{% load gross from prices_i18n %}{% load i18n %}-{% block step_info %}- <div class="panel panel-default">- <div class="panel-heading">- {% trans "Delivery group" %}- </div>- <div class="panel-body">- <table class="table table-striped">- <thead>- <tr>- <th class="col-sm-4">{% trans "Name" %}</th>- <th class="col-sm-2">{% trans "Price" %}</th>- <th class="col-sm-2">{% trans "Subtotal" %}</th>- </tr>- </thead>- <tbody>- {% for item in items %}- <tr>- <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>- <td class="col-sm-2">{% gross item.get_price_per_item %}</td>- <td class="col-sm-2">{% gross item.get_total %}</td>- </tr>- {% endfor %}- </tbody>- </table>- </div>- </div>- <hr>-{% endblock %}-{% block use_this_address %}<button type="submit" class="btn {% if entry.is_selected %}btn-primary{% else %}btn-default{% endif %} btn-lg col-sm-12">{% trans "Ship to this address" %}</button>{% endblock %}diff --git a/saleor/checkout/templates/checkout/summary.html b/saleor/checkout/templates/checkout/summary.htmlindex 63dde7c140..afb28d5319 100644--- a/saleor/checkout/templates/checkout/summary.html+++ b/saleor/checkout/templates/checkout/summary.html@@ -6,19 +6,11 @@{% block forms %}<div class="row">- <div class="col-sm-6">- <h3>{% trans "Order details" %}</h3>-- {% with total=checkout.get_total %}- <p>- {% trans "Order total" %}:- <strong>{% gross total %}</strong>- {% if total.tax %}- ({% blocktrans with tax=total.tax|floatformat:2 currency=total.currency %}includes {{ tax }} <span class="currency">{{ currency }}</span> tax{% endblocktrans %})- {% endif %}- </p>- {% endwith %}+ <div class="col-sm-12">+ <h1 class="page-header">{% trans "Order details" %}</h1></div>+ </div>+ <div class="row"><div class="col-sm-6"><div class="panel panel-default"><div class="panel-heading">@@ -34,68 +26,72 @@</div></div></div>+ <div class="col-sm-6">+ <div class="panel panel-default">+ <div class="panel-heading">+ {% trans "Shipping address" %}+ </div>+ <div class="panel-body">+ {% if checkout.shipping_address %}+ <address>{% include "userprofile/snippets/address-details.html" with address=checkout.shipping_address %}</address>+ {% else %}+ <p class="text-danger">{% trans "No address given yet." %}</p>+ {% endif %}+ <p><a href="{{ checkout.shipping.get_absolute_url }}">{% trans "Edit shipping details" %}</a></p>+ </div>+ </div>+ </div></div>- {% for step in checkout.delivery_steps %}+ {% for delivery, delivery_cost, total_with_delivery in checkout.deliveries %}<div class="panel panel-default"><div class="panel-heading">- {% blocktrans with number=forloop.counter %}Delivery group #{{ number }}{% endblocktrans %}+ {% blocktrans with number=forloop.counter %}Shipment #{{ number }}{% endblocktrans %}</div>- <div class="panel-body">- <table class="table table-striped">- <thead>+ <table class="table">+ <thead>+ <tr>+ <th class="col-sm-6">{% trans "Item" %}</th>+ <th class="col-sm-3 text-right">{% trans "Price" %}</th>+ <th class="col-sm-3 text-right">{% trans "Subtotal" %}</th>+ </tr>+ </thead>+ <tfoot>+ <tr>+ <th colspan="2">{% trans "Total" %}</th>+ <th class="text-right">{% gross total_with_delivery %}</th>+ </tr>+ </tfoot>+ <tbody>+ {% for item in delivery %}<tr>- <th class="col-sm-4">{% trans "Name" %}</th>- <th class="col-sm-2">{% trans "Price" %}</th>- <th class="col-sm-2">{% trans "Subtotal" %}</th>+ <td>{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>+ <td class="text-right">{% gross item.get_price_per_item %}</td>+ <td class="text-right">{% gross item.get_total %}</td></tr>- </thead>- <tfoot>+ {% endfor %}+ {% if delivery_cost.gross %}<tr>- <th class="col-sm-4"></th>- <th class="col-sm-2">{% trans "Total" %}</th>- <th class="col-sm-2">{% gross step.group.get_total_with_delivery %}</th>+ <td>+ {% trans "Shipping" %}+ </td>+ <td class="text-right">{% gross delivery_cost %}</td>+ <td class="text-right">{% gross delivery_cost %}</td></tr>- </tfoot>- <tbody>- {% for item in step.group %}- <tr>- <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>- <td class="col-sm-2">{% gross item.get_price_per_item %}</td>- <td class="col-sm-2">{% gross item.get_total %}</td>- </tr>- {% endfor %}- {% if step.group.get_delivery_total.gross %}- <tr>- <td class="col-sm-4">- {% trans "Shipping" %} ({{ step.group }})- </td>- <td class="col-sm-2">{% gross step.group.get_delivery_total %}</td>- <td class="col-sm-2">{% gross step.group.get_delivery_total %}</td>- </tr>- {% endif %}- </tbody>- </table>- {% if step.group.email %}- <p>{% trans "Will be sent to" %} {{ step.group.email }}</p>- {% elif step.group.address %}- <p>{% trans "Will be shipped to" %} {% include "userprofile/snippets/address-short.html" with address=step.group.address %}</p>- {% else %}- <p class="text-danger">{% trans "No address given yet." %}</p>- {% endif %}- <p><a href="{{ step.get_absolute_url }}">{% trans "Edit delivery details" %}</a></p>- </div>+ {% endif %}+ </tbody>+ </table></div>{% endfor %}{% with total=checkout.get_total %}- <p>+ <div class="alert alert-success">{% trans "Your total will be" %}:<strong>{% gross total %}</strong>{% if total.tax %}({% blocktrans with tax=total.tax|floatformat:2 currency=total.currency %}includes {{ tax }} <span class="currency">{{ currency }}</span> tax{% endblocktrans %}){% endif %}- </p>+ </div>{% endwith %}{% if all_steps_valid %}diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex 0d45b03b51..3d1297ed75 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -8,10 +8,8 @@ urlpatterns = patterns(url(r'^$', views.OrderListView.as_view(), name='orders'),url(r'^(?P<pk>[0-9]+)/$',views.order_details, name='order-details'),- url(r'^(?P<order_pk>[0-9]+)/address-billing/$',- views.address_view, name='address-billing-edit'),- url(r'^(?P<order_pk>[0-9]+)/address-shipping/(?P<group_pk>[0-9]+)/$',- views.address_view, name='address-shipping-edit'),+ url(r'^(?P<order_pk>[0-9]+)/address-(?P<address_type>billing|shipping)/$',+ views.address_view, name='address-edit'),url(r'^payment/(?P<pk>[0-9]+)/(?P<action>capture|refund|release)/$',views.manage_payment, name='manage-payment'),url(r'^line/(?P<pk>[0-9]+)/$', views.edit_order_line,diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 27308aa216..c23bcb177a 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -27,6 +27,10 @@ class OrderListView(StaffMemberOnlyMixin, FilterByStatusMixin, ListView):status_order = ['new', 'payment-pending', 'fully-paid', 'shipped','cancelled']+ def get_queryset(self):+ qs = super(OrderListView, self).get_queryset()+ return qs.prefetch_related('groups')+@staff_member_requireddef order_details(request, pk):@@ -160,7 +164,7 @@ def edit_order_line(request, pk, action=None):@staff_member_requireddef ship_delivery_group(request, pk):- group = get_object_or_404(DeliveryGroup.objects.select_subclasses(), pk=pk)+ group = get_object_or_404(DeliveryGroup, pk=pk)form = ShipGroupForm(request.POST or None, instance=group)if form.is_valid():with transaction.atomic():@@ -177,13 +181,11 @@ def ship_delivery_group(request, pk):@staff_member_required-def address_view(request, order_pk, group_pk=None):- address_type = 'shipping' if group_pk else 'billing'+def address_view(request, order_pk, address_type):order = Order.objects.get(pk=order_pk)if address_type == 'shipping':- group = order.get_groups().get(pk=group_pk)- address = group.address- success_msg = _('Updated shipping address for %s') % group+ address = order.shipping_address+ success_msg = _('Updated shipping address')else:address = order.billing_addresssuccess_msg = _('Updated billing address')diff --git a/saleor/dashboard/templates/dashboard/includes/_orders_table.html b/saleor/dashboard/templates/dashboard/includes/_orders_table.htmlindex 2156a1bd57..8f7ddf47f5 100644--- a/saleor/dashboard/templates/dashboard/includes/_orders_table.html+++ b/saleor/dashboard/templates/dashboard/includes/_orders_table.html@@ -20,7 +20,7 @@<a href="{% url 'dashboard:order-details' pk=order.pk %}">#{{ order.id }}</a></td><td>{{ order.created }}</td>- <td>{{ order.user|default:"Anonymous" }}</td>+ <td>{{ order.user|default:_("Guest") }}</td><td>{% render_status order.status order.get_status_display %}</td><td>{% render_status order.get_last_payment_status order.get_last_payment_status_display %}</td><td>{% gross order.get_total %}</td>diff --git a/saleor/dashboard/templates/dashboard/index.html b/saleor/dashboard/templates/dashboard/index.htmlindex a7b6c0cf5f..c6cce1df34 100644--- a/saleor/dashboard/templates/dashboard/index.html+++ b/saleor/dashboard/templates/dashboard/index.html@@ -16,69 +16,69 @@<div class="panel-heading"><span class="panel-title">{% trans "Preauthorized payments" %}</span></div>- <div class="panel-body">- {% if preauthorized_payments %}- <table class="table">- <thead>+ {% if preauthorized_payments %}+ <table class="table">+ <thead>+ <tr>+ <th>{% trans "Order number" %}</th>+ <th>{% trans "Date" %}</th>+ <th>{% trans "Customer" %}</th>+ <th class="text-right">{% trans "Amount" %}</th>+ </tr>+ </thead>+ <tbody>+ {% for payment in preauthorized_payments %}<tr>- <th>{% trans "Order number" %}</th>- <th>{% trans "Date" %}</th>- <th>{% trans "Customer" %}</th>- <th class="text-right">{% trans "Amount" %}</th>+ <td><a href="{% url "dashboard:order-details" pk=payment.order.pk %}">{{ payment.order }}</a></td>+ <td>{{ payment.created }}</td>+ <td>{{ payment.order.user|default:_("Guest") }}</td>+ <td class="text-right">{% gross payment.get_total_price %}</td></tr>- </thead>- <tbody>- {% for payment in preauthorized_payments %}- <tr>- <td><a href="{% url "dashboard:order-details" pk=payment.order.pk %}">{{ payment.order }}</a></td>- <td>{{ payment.created }}</td>- <td>{{ payment.order.user|default:_("Guest") }}</td>- <td class="text-right">{% gross payment.get_total_price %}</td>- </tr>- {% endfor %}- </tbody>- </table>- {% else %}+ {% endfor %}+ </tbody>+ </table>+ {% else %}+ <div class="panel-body"><small>{% trans "No preauthorized payments." %}</small>- {% endif %}- </div>+ </div>+ {% endif %}</div><div class="panel panel-default"><div class="panel-heading"><span class="panel-title">{% trans "Orders ready for shipment" %}</span></div>- <div class="panel-body">- {% if orders_to_ship %}- {% include "dashboard/includes/_orders_table.html" with orders=orders_to_ship %}- {% else %}+ {% if orders_to_ship %}+ {% include "dashboard/includes/_orders_table.html" with orders=orders_to_ship %}+ {% else %}+ <div class="panel-body"><small>{% trans "No orders are ready for shipment." %}</small>- {% endif %}- </div>+ </div>+ {% endif %}</div><div class="panel panel-default"><div class="panel-heading"><span class="panel-title">{% trans "Low stock" %}</span></div>- <div class="panel-body">- {% if low_stock %}- <table class="table">- <thead>+ {% if low_stock %}+ <table class="table">+ <thead>+ <tr>+ <th>{% trans "Product" %}</th>+ </tr>+ </thead>+ <tbody>+ {% for product in low_stock %}<tr>- <th>{% trans "Product" %}</th>+ <td><a href="{% url "dashboard:product-update" pk=product.pk %}">{{ product }}</a></td></tr>- </thead>- <tbody>- {% for product in low_stock %}- <tr>- <td><a href="{% url "dashboard:product-update" pk=product.pk %}">{{ product }}</a></td>- </tr>- {% endfor %}- </tbody>- </table>- {% else %}+ {% endfor %}+ </tbody>+ </table>+ {% else %}+ <div class="panel-body"><small>{% trans "No products are low in stock." %}</small>- {% endif %}- </div>+ </div>+ {% endif %}</div></div></div>diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex f7823e59ad..9c41f99fb5 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -25,7 +25,7 @@{% for group in groups %}<div class="panel panel-default"><div class="panel-heading">- <span class="panel-title">Delivery group #{{ group.pk }} <span class="pull-right">{% render_status group.status group.get_status_display %}</span></span>+ <span class="panel-title">{% blocktrans with shipment=group.id %}Shipment #{{ shipment }}{% endblocktrans %} <span class="pull-right">{% render_status group.status group.get_status_display %}</span></span></div><table class="table"><thead>@@ -40,8 +40,7 @@<tfoot><tr><td colspan="3">- <strong>{{ group.get_method }}</strong><br>- {% trans "Shipping address" %}: {% include "dashboard/includes/address_short.html" with address=group.address order_pk=order.pk group_pk=group.pk %}+ {% trans "Shipping" %} ({{ order.shipping_method }})</td><td class="text-right">{% gross group.price %}@@ -90,6 +89,9 @@{% if captured %}<p>{% trans "Captured amount" %}: {% gross captured %}</p>{% endif %}+ {% if refunded %}+ <p>{% trans "Refunded amount" %}: {% gross refunded %}</p>+ {% endif %}{% if can_capture %}<a class="btn btn-success" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk action='capture' %}" data-toggle="modal">{% trans "Capture" %}</a>{% elif can_refund %}@@ -141,13 +143,7 @@<div class="panel-body"><p>Order date: {{ order.created }}</p><p>Order status: {% render_status order.status order.get_status_display %}</p>- <p>Payment status: {% if payment %}{% render_status payment.status payment.get_status_display %}{% else %}-{% endif %}</p>- {% if captured %}- <p>Captured amount: {% gross captured %}</p>- {% endif %}- {% if refunded %}- <p>Refunded amount: {% gross refunded %}</p>- {% endif %}+ <p>Payment status: {% if payment %}{% render_status payment.status payment.get_status_display %}{% else %}{% trans "N/A" %}{% endif %}</p></div></div><div class="panel panel-default">@@ -168,7 +164,21 @@{% with order.billing_address as address %}<div class="panel-heading"><span class="panel-title">{% trans "Billing address" %}</span>- <span class="pull-right"><a href="{% url "dashboard:address-billing-edit" order_pk=order.pk %}"><i class="glyphicon glyphicon-pencil"></i> Edit</a></span>+ <span class="pull-right"><a href="{% url "dashboard:address-edit" order_pk=order.pk address_type="billing" %}"><i class="glyphicon glyphicon-pencil"></i> Edit</a></span>+ </div>+ <div class="panel-body">+ {% include 'dashboard/includes/_address.html' with address=address only %}+ <div>+ <i class="glyphicon glyphicon-envelope"></i> <a href="mailto:{{ order.get_user_email }}">{{ order.get_user_email }}</a>+ </div>+ </div>+ {% endwith %}+ </div>+ <div class="panel panel-default">+ {% with order.shipping_address as address %}+ <div class="panel-heading">+ <span class="panel-title">{% trans "Shipping address" %}</span>+ <span class="pull-right"><a href="{% url "dashboard:address-edit" order_pk=order.pk address_type="shipping" %}"><i class="glyphicon glyphicon-pencil"></i> Edit</a></span></div><div class="panel-body">{% include 'dashboard/includes/_address.html' with address=address only %}diff --git a/saleor/dashboard/templates/dashboard/order/modal_ship_delivery_group.html b/saleor/dashboard/templates/dashboard/order/modal_ship_delivery_group.htmlindex fa53dcc956..ac05a598ea 100644--- a/saleor/dashboard/templates/dashboard/order/modal_ship_delivery_group.html+++ b/saleor/dashboard/templates/dashboard/order/modal_ship_delivery_group.html@@ -7,7 +7,7 @@</div><div class="modal-body"><span>{% trans "Ship selected delivery group to the following address:" %}</span>- {% include 'dashboard/includes/_address.html' with address=group.address only %}+ {% include 'dashboard/includes/_address.html' with address=group.order.shipping_address only %}</div><div class="modal-footer"><form id="ship-delivery-group-form" class="form-inline" method="post" role="form" action="{% url 'dashboard:ship-delivery-group' pk=group.pk %}">@@ -15,4 +15,4 @@<button type="submit" class="btn btn-success">{% trans "Ship" %}</button><button data-dismiss="modal" aria-hidden="true" class="btn btn-default">{% trans "Cancel" %}</button></form>-</div>\ No newline at end of file+</div>diff --git a/saleor/delivery/__init__.py b/saleor/delivery/__init__.pyindex 00a92995fd..fb66b5eccb 100644--- a/saleor/delivery/__init__.py+++ b/saleor/delivery/__init__.py@@ -7,13 +7,9 @@ from satchless.item import ItemSetclass BaseDelivery(ItemSet):-group = Nonename = ''- def __init__(self, delivery_group):- self.group = delivery_group-def __iter__(self):return iter(self.group)@@ -28,31 +24,21 @@ class BaseDelivery(ItemSet):class DummyShipping(BaseDelivery):name = 'dummy_shipping'- def __init__(self, delivery_group, address):+ def __init__(self, address):self.address = address- super(DummyShipping, self).__init__(delivery_group)def __str__(self):return 'Dummy shipping'- def get_delivery_total(self, weight=None, **kwargs):- if weight is None:- weight = sum(line.product.get_weight() for line in self.group)- qty = sum(line.quantity for line in self.group)- return Price(qty * weight,- currency=settings.DEFAULT_CURRENCY)+ def get_delivery_total(self, items, **kwargs):+ weight = sum(+ line.product.get_weight() * line.quantity for line in items)+ return Price(weight, currency=settings.DEFAULT_CURRENCY)-def get_delivery_choices_for_group(group, **kwargs):+def get_delivery_options_for_items(items, **kwargs):if 'address' in kwargs:- shipping = DummyShipping(group, kwargs['address'])- yield (shipping.name, shipping)+ shipping = DummyShipping(kwargs['address'])+ yield shippingelse:raise ValueError('Unknown delivery type')---def get_delivery(group):- if group.method == 'dummy_shipping':- return DummyShipping(group, group.shippeddeliverygroup.address)- else:- raise ValueError('Unknown delivery method')diff --git a/saleor/order/models.py b/saleor/order/models.pyindex e772b3a4fa..ff2ea279b7 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -1,5 +1,6 @@from __future__ import unicode_literalsfrom decimal import Decimal+from itertools import chainfrom uuid import uuid4import emailit.api@@ -13,7 +14,6 @@ from django.utils.timezone import nowfrom django.utils.encoding import python_2_unicode_compatiblefrom django.utils.translation import pgettext_lazyfrom django_prices.models import PriceField-from model_utils.managers import InheritanceManagerfrom payments import PurchasedItemfrom payments.models import BasePaymentfrom prices import Price@@ -22,7 +22,7 @@ from satchless.item import ItemSet, ItemLinefrom ..core.utils import build_absolute_urifrom ..product.models import Productfrom ..userprofile.models import Address, User-from ..delivery import get_delivery+from ..delivery import get_delivery_options_for_items@python_2_unicode_compatible@@ -54,6 +54,11 @@ class Order(models.Model, ItemSet):editable=False)billing_address = models.ForeignKey(Address, related_name='+',editable=False)+ shipping_address = models.ForeignKey(Address, related_name='+',+ editable=False)+ shipping_method = models.CharField(+ pgettext_lazy('Order field', 'Delivery method'),+ max_length=255)anonymous_user_email = models.EmailField(blank=True, default='',editable=False)token = models.CharField(@@ -76,9 +81,6 @@ class Order(models.Model, ItemSet):def get_items(self):return OrderedItem.objects.filter(delivery_group__order=self)- def get_groups(self):- return self.groups.select_subclasses()-def is_fully_paid(self):total_paid = sum([payment.total for payment inself.payments.filter(status='confirmed')], Decimal())@@ -91,7 +93,7 @@ class Order(models.Model, ItemSet):return self.anonymous_user_emaildef __iter__(self):- return iter(self.groups.all().select_subclasses())+ return iter(self.groups.all())def __repr__(self):return '<Order #%r>' % (self.id,)@@ -143,20 +145,13 @@ class Order(models.Model, ItemSet):self.history.create(status=status, comment=comment, user=user)-class DeliveryGroupManager(InheritanceManager):+class DeliveryGroupManager(models.Manager):def duplicate_group(self, group):- group = self.get_subclass(pk=group.pk)- group.pk = Nonegroup.id = Nonegroup.status = 'new'- if isinstance(group, ShippedDeliveryGroup):- address = group.address- address.pk = None- address.save()- group.address = addressgroup.save()- return group.deliverygroup_ptr+ return groupclass DeliveryGroup(models.Model, ItemSet):@@ -170,9 +165,6 @@ class DeliveryGroup(models.Model, ItemSet):status = models.CharField(pgettext_lazy('Delivery group field', 'Delivery status'),max_length=32, default='new', choices=STATUS_CHOICES)- method = models.CharField(- pgettext_lazy('Delivery group field', 'Delivery method'),- max_length=255)order = models.ForeignKey(Order, related_name='groups', editable=False)price = PriceField(pgettext_lazy('Delivery group field', 'unit price'),@@ -185,7 +177,7 @@ class DeliveryGroup(models.Model, ItemSet):def __str__(self):return pgettext_lazy(- 'Delivery group str', 'Delivery group #%s') % self.pk+ 'Delivery group str', 'Shipment #%s') % self.pkdef __repr__(self):return '%s(%r)' % (self.__class__.__name__, list(self))@@ -195,9 +187,6 @@ class DeliveryGroup(models.Model, ItemSet):return iter(self.items.select_related('product').all())return super(DeliveryGroup, self).__iter__()- def get_method(self):- return smart_text(get_delivery(self))-def change_status(self, status):self.status = statusself.save()@@ -231,27 +220,7 @@ class DeliveryGroup(models.Model, ItemSet):return sum([item.get_quantity() for item in self])-@python_2_unicode_compatible-class ShippedDeliveryGroup(DeliveryGroup):-- address = models.ForeignKey(Address, related_name='+')-- def __str__(self):- return pgettext_lazy(- 'Delivery group str', 'Shipped delivery #%s') % self.pk---@python_2_unicode_compatible-class DigitalDeliveryGroup(DeliveryGroup):-- email = models.EmailField()-- def __str__(self):- return pgettext_lazy(- 'Delivery group str', 'Digital delivery #%s') % self.pk---class OrderedItemManager(InheritanceManager):+class OrderedItemManager(models.Manager):def move_to_group(self, item, target_group, quantity):try:diff --git a/saleor/order/templates/order/details.html b/saleor/order/templates/order/details.htmlindex be6721a492..75ba973acf 100644--- a/saleor/order/templates/order/details.html+++ b/saleor/order/templates/order/details.html@@ -23,20 +23,16 @@{# unless current user is owner of the order. #}<div class="row">- <div class="col-sm-6">- <h3>{% trans "Order details" %}</h3>- <p>{% trans "Order number" %}: {{ order }}</p>- {% with total=order.get_total %}- <p>- {% trans "Order total" %}:- <strong>{% gross total %}</strong>- {% if total.tax %}- ({% blocktrans with tax=total.tax|floatformat:2 currency=total.currency %}includes {{ tax }} <span class="currency">{{ currency }}</span> tax{% endblocktrans %})- {% endif %}- </p>- {% endwith %}- <p>{% trans "Status" %}: <span class="label label-default">{{ order.get_status_display }}</span></p>+ <div class="col-sm-12">+ <h1 class="page-header">+ {% blocktrans %}Order {{ order }}{% endblocktrans %}+ <span class="pull-right">+ <span class="label label-default">{{ order.get_status_display }}</span>+ </span>+ </h1></div>+ </div>+ <div class="row">{% if order.user == user %}<div class="col-sm-6"><div class="panel panel-default">@@ -48,59 +44,60 @@</div></div></div>- <h3></h3>+ <div class="col-sm-6">+ <div class="panel panel-default">+ <div class="panel-heading">+ {% trans "Shipping address" %}+ </div>+ <div class="panel-body">+ <address>{% include "userprofile/snippets/address-details.html" with address=order.shipping_address %}</address>+ </div>+ </div>+ </div>{% endif %}</div>{% for group in groups %}<div class="panel panel-default"><div class="panel-heading">- {% blocktrans with number=forloop.counter %}Delivery group #{{ number }}{% endblocktrans %}+ {% blocktrans with number=forloop.counter %}Shipment #{{ number }}{% endblocktrans %}+ <span class="pull-right">+ <span class="label label-default">{{ group.get_status_display }}</span>+ </span></div>- <div class="panel-body">- <table class="table table-striped">- <thead>+ <table class="table">+ <thead>+ <tr>+ <th class="col-sm-6">{% trans "Name" %}</th>+ <th class="col-sm-3 text-right">{% trans "Price" %}</th>+ <th class="col-sm-3 text-right">{% trans "Subtotal" %}</th>+ </tr>+ </thead>+ <tfoot>+ <tr>+ <th colspan="2">{% trans "Total" %}</th>+ <th class="text-right">{% gross group.get_total %}</th>+ </tr>+ </tfoot>+ <tbody>+ {% for item in group %}<tr>- <th class="col-sm-4">{% trans "Name" %}</th>- <th class="col-sm-2">{% trans "Price" %}</th>- <th class="col-sm-2">{% trans "Subtotal" %}</th>+ <td>{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>+ <td class="text-right">{% gross item.get_price_per_item %}</td>+ <td class="text-right">{% gross item.get_total %}</td></tr>- </thead>- <tfoot>+ {% endfor %}+ {% if group.price.gross %}<tr>- <th class="col-sm-4"></th>- <th class="col-sm-2">{% trans "Total" %}</th>- <th class="col-sm-2">{% gross group.get_total %}</th>+ <td class="col-sm-4">+ {% trans "Shipping" %}+ </td>+ <td class="text-right">{% gross group.price %}</td>+ <td class="text-right">{% gross group.price %}</td></tr>- </tfoot>- <tbody>- {% for item in group %}- <tr>- <td class="col-sm-4">{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>- <td class="col-sm-2">{% gross item.get_price_per_item %}</td>- <td class="col-sm-2">{% gross item.get_total %}</td>- </tr>- {% endfor %}- {% if group.price.gross %}- <tr>- <td class="col-sm-4">- {% trans "Shipping" %} ({{ group.get_method }})- </td>- <td class="col-sm-2">{% gross group.price %}</td>- <td class="col-sm-2">{% gross group.price %}</td>- </tr>- {% endif %}- </tbody>- </table>- {% if order.user == user %}- {% if group.email %}- <p>{% trans "Addressee" %}: {{ group.email }}</p>- {% elif group.address %}- <p>{% trans "Addressee" %}: {% include "userprofile/snippets/address-short.html" with address=group.address %}</p>{% endif %}- <p>{% trans "Status" %}: <span class="label label-default">{{ group.get_status_display }}</span></p>- {% endif %}- </div>+ </tbody>+ </table></div>{% endfor %}{% if order.user == user or not order.is_fully_paid %}diff --git a/saleor/order/views.py b/saleor/order/views.pyindex e942e7cac5..fded58dfad 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)def details(request, token):order = get_object_or_404(Order, token=token)- groups = order.groups.select_subclasses().all()+ groups = order.groups.all()payments = order.payments.all()form_data = request.POST or Nonetry:diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 1b98f23607..634cfcd889 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -21,8 +21,10 @@ def get_related_products(product):def product_details(request, slug, product_id):- product = get_object_or_404(Product.objects.select_subclasses(),- id=product_id)+ products = Product.objects.select_subclasses()+ products = products.select_related('category')+ products = products.prefetch_related('images')+ product = get_object_or_404(products, id=product_id)if product.get_slug() != slug:return HttpResponsePermanentRedirect(product.get_absolute_url())form_class = get_form_class_for_product(product)diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex ad41561e20..0b6824ef5e 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -36,7 +36,7 @@ class AddressBookManager(models.Manager):class AddressBook(models.Model):user = models.ForeignKey('User', related_name='address_book')- address = models.ForeignKey('Address', related_name='+', unique=True)+ address = models.OneToOneField('Address', related_name='+')alias = models.CharField(pgettext_lazy('Address book entry', 'short alias'),max_length=30,