X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=bluechips%2Fmodel%2Fexpenditure.py;h=58456fb8a71730d48c0a4936da2eabd1ee1384ca;hb=5c9f0e33552b9420736f0d733134a1e62ef8df03;hp=009ba3a561a0024df244137c829d15c58fd20f11;hpb=4d790b35771902dc80f38ec849d1bbc666cc55cc;p=bluechips.git diff --git a/bluechips/model/expenditure.py b/bluechips/model/expenditure.py index 009ba3a..58456fb 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. @@ -50,8 +60,17 @@ class Expenditure(object): total = sum(split_dict.itervalues()) - for user, share in split_dict.iteritems(): - split_dict[user] = share / total + for user, share in split_dict.items(): + if share == 0: + del split_dict[user] + else: + split_dict[user] = share / total + + for user, share in split_dict.items(): + if share == 0: + del split_dict[user] + else: + split_dict[user] = share / total amounts_dict = dict()