Commits

Tomas Neme  committed 23f5695

added a lot of logging. Some of it might be a little redundant, but we really need some insight

  • Participants
  • Parent commits d46fb7b

Comments (0)

Files changed (1)

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

 import operator
 import signals
 
+import traceback
+
 log = logging.getLogger('satchmo_store.shop.models')
 
+def format_traceback(count=15):
+    """
+    Return a string with the traceback up to `count` frames
+    """
+    return "".join(traceback.format_stack(limit=count))
+
 class NullConfig(object):
     """Standin for a real config when we don't have one yet."""
 
 
     def remove_all_items(self):
         """Delete all items belonging to this order."""
+        log.debug("Removing all items from Order #%d %s",
+                  self.id, format_traceback())
         for item in self.orderitem_set.all():
             item.delete()
         self.save()
     def _balance(self):
         if self.total is None:
             self.force_recalculate_total(save=True)
+        else:
+            log.debug("balance for Order #%d. Skipping recalculate %s",
+                      self.id, format_traceback())
         return trunc_decimal(self.total-self.balance_paid, 2)
 
     balance = property(fget=_balance)
 
     def _is_partially_paid(self):
         if self.total:
-            return (
+            ret = (
                 float(self.balance) > 0.0
                 and float(self.balance_paid) > 0.0
                 and self.balance != self.balance_paid
                 )
+            if ret:
+                log.debug("Order #%d partially paid: balance: %s balance_paid: %s", self.id, self.balance, self.balance_paid)
+            return ret
         else:
             return False
 
         Copy addresses from contact. If the order has just been created, set
         the create_date.
         """
+        log.debug("Saving order #%d. %s", self.id,
+                  format_traceback(10))
         if not self.pk:
             self.time_stamp = datetime.datetime.now()
             self.copy_addresses()
 
     def force_recalculate_total(self, save=True):
         """Calculates sub_total, taxes and total."""
+        log.debug("recalculate total from Order #%d\n%s",
+                  self.id, format_traceback())
         zero = Decimal("0.0000000000")
         total_discount = Decimal("0.0000000000")
 
 
     def _paid_in_full(self):
         """True if total has been paid"""
+        log.debug("Order #%d paid in full? %s", self.balance)
         return self.balance == Decimal('0.00')
     paid_in_full = property(fget=_paid_in_full)
 
     line_total = property(_get_line_total)
 
     def save(self, **kwargs):
+        log.debug("Saving OrderItem #%d for Order #%d, %s",
+                  self.id, self.order.id, format_traceback())
         self.update_tax()
         super(OrderItem, self).save(**kwargs)
 
     def update_tax(self):
+        log.debug("OrderItem #%d update_tax. Before: %s", self.tax)
         taxclass = self.product.taxClass
         processor = get_tax_processor(order=self.order)
 
         if self.product.taxable:
             self.unit_tax = processor.by_price(taxclass, self.unit_price)
             self.tax = processor.by_orderitem(self)
+        log.debug("OrderItem #%d update_tax. After: %s", self.tax)
 
     class Meta:
         verbose_name = _("Order Line Item")