mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
code reread: noop, and pep8 <3
This commit is contained in:
parent
6a50e7318b
commit
9583fe3cbe
1 changed files with 12 additions and 6 deletions
|
@ -8,7 +8,10 @@ from sqlalchemy import orm
|
||||||
|
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
|
||||||
# define models
|
# define models
|
||||||
|
|
||||||
|
|
||||||
class Project(db.Model):
|
class Project(db.Model):
|
||||||
|
|
||||||
_to_serialize = ("id", "name", "password", "contact_email",
|
_to_serialize = ("id", "name", "password", "contact_email",
|
||||||
|
@ -28,7 +31,8 @@ class Project(db.Model):
|
||||||
@property
|
@property
|
||||||
def balance(self):
|
def balance(self):
|
||||||
|
|
||||||
balances, should_pay, should_receive = defaultdict(int), defaultdict(int), defaultdict(int)
|
balances, should_pay, should_receive = (defaultdict(int)
|
||||||
|
for time in (1, 2, 3))
|
||||||
|
|
||||||
# for each person
|
# for each person
|
||||||
for person in self.members:
|
for person in self.members:
|
||||||
|
@ -40,13 +44,14 @@ class Project(db.Model):
|
||||||
should_receive[bill.payer] += bill.pay_each()
|
should_receive[bill.payer] += bill.pay_each()
|
||||||
|
|
||||||
for person in self.members:
|
for person in self.members:
|
||||||
balances[person.id] = round(should_receive[person] - should_pay[person], 2)
|
balance = should_receive[person] - should_pay[person]
|
||||||
|
balances[person.id] = round(balance, 2)
|
||||||
|
|
||||||
return balances
|
return balances
|
||||||
|
|
||||||
def has_bills(self):
|
def has_bills(self):
|
||||||
"""return if the project do have bills or not"""
|
"""return if the project do have bills or not"""
|
||||||
return self.get_bills().count() != 0
|
return self.get_bills().count() > 0
|
||||||
|
|
||||||
def get_bills(self):
|
def get_bills(self):
|
||||||
"""Return the list of bills related to this project"""
|
"""Return the list of bills related to this project"""
|
||||||
|
@ -95,7 +100,6 @@ class Person(db.Model):
|
||||||
return Person.query.filter(Person.id == id)\
|
return Person.query.filter(Person.id == id)\
|
||||||
.filter(Project.id == project.id).one()
|
.filter(Project.id == project.id).one()
|
||||||
|
|
||||||
|
|
||||||
query_class = PersonQuery
|
query_class = PersonQuery
|
||||||
|
|
||||||
_to_serialize = ("id", "name", "activated")
|
_to_serialize = ("id", "name", "activated")
|
||||||
|
@ -126,6 +130,7 @@ billowers = db.Table('billowers',
|
||||||
db.Column('person_id', db.Integer, db.ForeignKey('person.id')),
|
db.Column('person_id', db.Integer, db.ForeignKey('person.id')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Bill(db.Model):
|
class Bill(db.Model):
|
||||||
|
|
||||||
class BillQuery(BaseQuery):
|
class BillQuery(BaseQuery):
|
||||||
|
@ -169,6 +174,7 @@ class Bill(db.Model):
|
||||||
return "<Bill of %s from %s for %s>" % (self.amount,
|
return "<Bill of %s from %s for %s>" % (self.amount,
|
||||||
self.payer, ", ".join([o.name for o in self.owers]))
|
self.payer, ", ".join([o.name for o in self.owers]))
|
||||||
|
|
||||||
|
|
||||||
class Archive(db.Model):
|
class Archive(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
project_id = db.Column(db.String, db.ForeignKey("project.id"))
|
project_id = db.Column(db.String, db.ForeignKey("project.id"))
|
||||||
|
|
Loading…
Reference in a new issue