From: Evan Broder Date: Fri, 25 Jul 2008 04:26:08 +0000 (+0000) Subject: Add split function that redistributes old percentages with new total X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=54a4d9536f79008479ef41bfc328038945436a7b;hp=fcebca671ea178d753339d22c972dc7c1a4bcc80;p=bluechips.git Add split function that redistributes old percentages with new total --- diff --git a/bluechips/model/expenditure.py b/bluechips/model/expenditure.py index 009ba3a..acd7785 100644 --- a/bluechips/model/expenditure.py +++ b/bluechips/model/expenditure.py @@ -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.