]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Fix division of currency
authorAlejandro R. Sedeño <asedeno@mit.edu>
Fri, 19 Mar 2010 05:52:56 +0000 (01:52 -0400)
committerEvan Broder <broder@mit.edu>
Fri, 26 Mar 2010 14:25:52 +0000 (10:25 -0400)
Wrong:
>>> x=Currency('110')
>>> x/2.9
Currency("$55.00")

Right:
>>> x=Currency('110')
>>> x/2.9
Currency("$37.93")

bluechips/model/types.py

index 8cea5e8b107d781fe716e26f572f4eda3694bdc5..59f3d35bf8d150e0cc368e939db1058f46b0378a 100644 (file)
@@ -122,6 +122,18 @@ class Currency(object):
         argument to an int
         """
         return self.__mul__(other)
+    def __div__(self, other):
+        """
+        If I don't define this, SmartSubclass will convert the other
+        argument to an int
+        """
+        return Currency(self.value / other)
+    def __truediv__(self, other):
+        """
+        If I don't define this, SmartSubclass will convert the other
+        argument to an int
+        """
+        return Currency(self.value / other)
     
     def __repr__(self):
         return '%s("%s")' % (self.__class__.__name__, str(self))