Commits

Tomas Neme  committed 14135f9

added a method to get the shippable objects by amounts, instead of one by one

  • Participants
  • Parent commits dfb57f7

Comments (0)

Files changed (2)

File satchmo/apps/satchmo_store/shop/models.py

         for cartitem in self.cartitem_set.all():
             if cartitem.is_shippable:
                 p = cartitem.product
-                q =  int(cartitem.quantity.quantize(Decimal('0'), ROUND_CEILING))
+                q = int(cartitem.quantity.quantize(Decimal('0'), ROUND_CEILING))
                 for single in range(0, q):
                     items.append(p)
         return items
 
+    def get_shipment_by_amount(self):
+        """
+        Returna list of shippable products, with it's quantity
+        """
+        items = []
+        for cartitem in self.cartitem_set.all():
+            if cartitem.is_shippable:
+                p = cartitem.product
+                q = int(cartitem.quantity.quantize(Decimal('0'), ROUND_CEILING))
+                items.append((q,p))
+        return items
+
     class Meta:
         verbose_name = _("Shopping Cart")
         verbose_name_plural = _("Shopping Carts")

File satchmo/apps/shipping/templates/shipping/canadapost/request.xml

+
 {% load satchmo_product %}<?xml version="1.0" encoding="UTF-8" ?>
 {% spaceless %}
 <eparcel>
 		<turnAroundTime>{{config.turn_around_time}}</turnAroundTime>
 		<itemsPrice>{{cart.total}}</itemsPrice>
 		<lineItems>
-		{% for product in cart.get_shipment_list %}
+		{% for product in cart.get_shipment_by_amount %}
 			<item>
-				<quantity>1</quantity>
-				<weight>{{product|smart_attr:"weight"}}</weight>
-				<length>{{product|smart_attr:"length"}}</length>
-				<width>{{product|smart_attr:"width"}}</width>
-				<height>{{product|smart_attr:"height"}}</height>
-				<description>{{product.name}}</description>
+				<quantity>{{ product.0 }}</quantity>
+				<weight>{{product.1|smart_attr:"weight"}}</weight>
+				<length>{{product.1|smart_attr:"length"}}</length>
+				<width>{{product.1|smart_attr:"width"}}</width>
+				<height>{{product.1|smart_attr:"height"}}</height>
+				<description>{{product.1.name}}</description>
 			</item>
 		{% endfor %}
 		</lineItems>
 		<postalCode>{{contact.shipping_address.postal_code}}</postalCode>
 	</ratesAndServicesRequest>
 </eparcel>
-{% endspaceless %}
+{% endspaceless %}