]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/model/expenditure.py
Add split function that redistributes old percentages with new total
[bluechips.git] / bluechips / model / expenditure.py
index 009ba3a561a0024df244137c829d15c58fd20f11..acd77852172f595466dd34bd84c07ac2f836d178 100644 (file)
@@ -28,6 +28,16 @@ class Expenditure(object):
         split_percentage = Decimal(100) / Decimal(residents.count())
         self.split(dict((resident, split_percentage) for resident in residents))
     
+    def update_split(self):
+        """
+        Re-split an expenditure using the same percentages as what is
+        currently in the database
+        """
+        
+        old_splits = meta.Session.query(Split).filter(Split.expenditure==self)
+        split_dict = dict((s.user, Decimal(int(s.share))) for s in old_splits)
+        self.split(split_dict)
+    
     def split(self, split_dict):
         """
         Split up an expenditure.