aboutsummaryrefslogtreecommitdiff
path: root/budget/models.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-09-09 19:57:28 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-09-09 19:57:28 +0200
commit45dc6edacbc9cb771fd038cdc719fd953c1a6771 (patch)
tree2f3b7886e2cb7bd2559d0b96526d0006cfd59e81 /budget/models.py
parent801802836a648ac0865c1c932e3cf9a01e3a639e (diff)
downloadihatemoney-mirror-45dc6edacbc9cb771fd038cdc719fd953c1a6771.zip
ihatemoney-mirror-45dc6edacbc9cb771fd038cdc719fd953c1a6771.tar.gz
ihatemoney-mirror-45dc6edacbc9cb771fd038cdc719fd953c1a6771.tar.bz2
Move some logic to the models and add comments.
Diffstat (limited to 'budget/models.py')
-rw-r--r--budget/models.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/budget/models.py b/budget/models.py
index 08e46ae..8feaccb 100644
--- a/budget/models.py
+++ b/budget/models.py
@@ -36,6 +36,33 @@ class Project(db.Model):
return balances
+ def get_bills(self):
+ """Return the list of bills related to this project"""
+ return Bill.query.join(Person, Project)\
+ .filter(Bill.payer_id == Person.id)\
+ .filter(Person.project_id == Project.id)\
+ .filter(Project.id == self.id)\
+ .order_by(Bill.date.desc())
+
+ def remove_member(self, member_id):
+ """Remove a member from the project.
+
+ If the member is not bound to a bill, then he is deleted, otherwise
+ he is only deactivated.
+
+ This method returns the status DELETED or DEACTIVATED regarding the
+ changes made.
+ """
+ person = Person.query.get_or_404(member_id)
+ if person.project == self:
+ if not person.has_bills():
+ db.session.delete(person)
+ db.session.commit()
+ else:
+ person.activated = False
+ db.session.commit()
+ return person
+
def __repr__(self):
return "<Project %s>" % self.name