Repository: saleor/saleor

Issue:
Save sku in OrderItem



Discussion:

Resolving patch:
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.py
--- a/saleor/checkout/steps.py
+++ b/saleor/checkout/steps.py
@@ -4,6 +4,7 @@
 from django.core.exceptions import ValidationError
 from django.db import models
 from django.shortcuts import redirect
+from django.utils.encoding import smart_text
 from satchless.process import InvalidData
 
 from .forms import DigitalDeliveryForm, DeliveryForm
@@ -190,7 +191,8 @@ def add_to_order(self, order):
         delivery_method = self.group['delivery_method']
         group = ShippedDeliveryGroup.objects.create(
             order=order, address=self.address,
-            price=delivery_method.get_price())
+            price=delivery_method.get_price(),
+            method=smart_text(delivery_method))
         group.add_items_from_partition(self.delivery_group)
 
     def is_default_address(self, entry, user):
@@ -236,7 +238,8 @@ def add_to_order(self, order):
         delivery_method = self.group['delivery_method']
         group = DigitalDeliveryGroup.objects.create(
             order=order, email=self.group['email'],
-            price=delivery_method.get_price())
+            price=delivery_method.get_price(),
+            method=smart_text(delivery_method))
         group.add_items_from_partition(self.delivery_group)
 
     def process(self, extra_context=None):
diff --git a/saleor/delivery/__init__.py b/saleor/delivery/__init__.py
--- a/saleor/delivery/__init__.py
+++ b/saleor/delivery/__init__.py
@@ -28,4 +28,5 @@ def get_price_per_item(self, **kwargs):
 
 class DigitalDelivery(BaseDelivery):
 
-    pass
+    def __unicode__(self):
+        return 'Digital delivery'
diff --git a/saleor/order/models.py b/saleor/order/models.py
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -122,6 +122,9 @@ class DeliveryGroup(Subtyped, 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'),
@@ -147,13 +150,14 @@ def get_total(self, **kwargs):
 
     def add_items_from_partition(self, partition):
         for item_line in partition:
-            product_name = smart_text(item_line.product)
+            product = item_line.product
             price = item_line.get_price_per_item()
             self.items.create(
-                product=item_line.product,
+                product=product,
                 quantity=item_line.get_quantity(),
                 unit_price_net=price.net,
-                product_name=product_name,
+                product_name=smart_text(product),
+                product_sku=product.sku,
                 unit_price_gross=price.gross)
 
 
@@ -183,6 +187,8 @@ class OrderedItem(models.Model, ItemLine):
         verbose_name=pgettext_lazy('OrderedItem field', 'product'))
     product_name = models.CharField(
         pgettext_lazy('OrderedItem field', 'product name'), max_length=128)
+    product_sku = models.CharField(pgettext_lazy('OrderedItem field', 'sku'),
+                                   max_length=32, unique=True)
     quantity = models.DecimalField(
         pgettext_lazy('OrderedItem field', 'quantity'),
         max_digits=10, decimal_places=4)


Test patch: