mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Users are deleted when no bill is assigned to them. Fixes #5
This commit is contained in:
parent
cb05727ec3
commit
0e5bab13af
2 changed files with 16 additions and 3 deletions
|
@ -48,6 +48,14 @@ class Person(db.Model):
|
||||||
name = db.Column(db.UnicodeText)
|
name = db.Column(db.UnicodeText)
|
||||||
activated = db.Column(db.Boolean, default=True)
|
activated = db.Column(db.Boolean, default=True)
|
||||||
|
|
||||||
|
def is_used(self):
|
||||||
|
bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\
|
||||||
|
.filter("Bill.id == billowers.bill_id")\
|
||||||
|
.filter("Person.id == billowers.person_id")\
|
||||||
|
.filter(Person.id == self.id)\
|
||||||
|
.count()
|
||||||
|
return bills_as_ower_number != 0 or len(self.bills) != 0
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -134,9 +134,14 @@ def add_member(project):
|
||||||
def remove_member(project, member_id):
|
def remove_member(project, member_id):
|
||||||
person = Person.query.get_or_404(member_id)
|
person = Person.query.get_or_404(member_id)
|
||||||
if person.project == project:
|
if person.project == project:
|
||||||
person.activated = False
|
if not person.is_used():
|
||||||
db.session.commit()
|
db.session.delete(person)
|
||||||
flash("%s has been removed" % person.name)
|
db.session.commit()
|
||||||
|
flash("User '%s' has been removed" % person.name)
|
||||||
|
else:
|
||||||
|
person.activated = False
|
||||||
|
db.session.commit()
|
||||||
|
flash("User '%s' has been desactivated" % person.name)
|
||||||
return redirect(url_for("list_bills", project_id=project.id))
|
return redirect(url_for("list_bills", project_id=project.id))
|
||||||
|
|
||||||
@app.route("/<string:project_id>/add", methods=["GET", "POST"])
|
@app.route("/<string:project_id>/add", methods=["GET", "POST"])
|
||||||
|
|
Loading…
Reference in a new issue