Permalink
Browse files

Use Product.get_name() in create_from_cart.

It is there for extensibility so use it.
  • Loading branch information...
1 parent 05ea03a commit a3533a6bf734290f171e610cb1cf0ae0af43e115 @bmihelac bmihelac committed Sep 29, 2011
Showing with 24 additions and 2 deletions.
  1. +1 −1 shop/models/defaults/bases.py
  2. +1 −1 shop/models/defaults/managers.py
  3. +17 −0 shop/tests/order.py
  4. +5 −0 tests/testapp/project/models.py
@@ -422,5 +422,5 @@ class Meta(object):
def save(self, *args, **kwargs):
if self.product:
- self.product_name = self.product.name
+ self.product_name = self.product.get_name()
super(BaseOrderItem, self).save(*args, **kwargs)
@@ -106,7 +106,7 @@ def create_from_cart(self, cart):
i = OrderItem()
i.order = o
i.product_reference = item.product.id
- i.product_name = item.product.name
+ i.product_name = item.product.get_name()
i.product = item.product
i.unit_price = item.product.get_price()
i.quantity = item.quantity
View
@@ -201,6 +201,23 @@ def test_create_order_from_simple_cart(self):
self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
self.assertEqual(o.order_total, self.cart.total_price)
+ def test_create_order_order_items_proper_product_name(self):
+ baseproduct = BaseProduct.objects.create(
+ name="Table",
+ unit_price=self.PRODUCT_PRICE
+ )
+ variation = ProductVariation.objects.create(
+ baseproduct=baseproduct,
+ name="white"
+ )
+ self.cart.add_product(variation)
+ self.cart.update()
+ self.cart.save()
+
+ o = Order.objects.create_from_cart(self.cart)
+ ois = OrderItem.objects.filter(order=o)
+ self.assertEqual(ois[0].product_name, "Table - white")
+
def test_create_order_from_taxed_cart(self):
"""
This time assert that everything is consistent with a tax cart modifier
@@ -14,6 +14,7 @@ class CompactDiscProduct(Product):
class BaseProduct(models.Model):
+ name = models.CharField(max_length=255)
unit_price = CurrencyField()
@@ -23,4 +24,8 @@ class ProductVariation(Product):
def get_price(self):
return self.baseproduct.unit_price
+ def get_name(self):
+ return "%s - %s" % (self.baseproduct.name, self.name,)
+
+

0 comments on commit a3533a6

Please sign in to comment.