1
0
Fork 0
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:
Feth AREZKI 2012-03-06 20:37:32 +01:00
parent 6a50e7318b
commit 9583fe3cbe

View file

@ -8,7 +8,10 @@ from sqlalchemy import orm
db = SQLAlchemy()
# define models
class Project(db.Model):
_to_serialize = ("id", "name", "password", "contact_email",
@ -28,7 +31,8 @@ class Project(db.Model):
@property
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 person in self.members:
@ -40,13 +44,14 @@ class Project(db.Model):
should_receive[bill.payer] += bill.pay_each()
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
def has_bills(self):
"""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):
"""Return the list of bills related to this project"""
@ -95,7 +100,6 @@ class Person(db.Model):
return Person.query.filter(Person.id == id)\
.filter(Project.id == project.id).one()
query_class = PersonQuery
_to_serialize = ("id", "name", "activated")
@ -126,6 +130,7 @@ billowers = db.Table('billowers',
db.Column('person_id', db.Integer, db.ForeignKey('person.id')),
)
class Bill(db.Model):
class BillQuery(BaseQuery):
@ -169,6 +174,7 @@ class Bill(db.Model):
return "<Bill of %s from %s for %s>" % (self.amount,
self.payer, ", ".join([o.name for o in self.owers]))
class Archive(db.Model):
id = db.Column(db.Integer, primary_key=True)
project_id = db.Column(db.String, db.ForeignKey("project.id"))