| Total Complexity | 7 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from .model import * |
||
| 5 | class Reimbursee(account.Account): |
||
| 6 | __tablename__ = 'reimbursees' |
||
| 7 | __mapper_args__ = {'polymorphic_identity': 'reimbursee'} |
||
| 8 | |||
| 9 | id = Column(Integer, ForeignKey("accounts.id"), primary_key=True) |
||
| 10 | enabled = Column(Boolean, nullable=False, default=True) |
||
| 11 | |||
| 12 | def __init__(self, name): |
||
| 13 | self.enabled = True |
||
| 14 | self.name = name |
||
| 15 | self.balance = 0.0 |
||
| 16 | |||
| 17 | def __str__(self): |
||
| 18 | return "<Reimbursee: id {}, name {}, balance {}>".\ |
||
| 19 | format(self.id, self.name, self.balance) |
||
| 20 | |||
| 21 | @classmethod |
||
| 22 | def from_id(cls, id): |
||
| 23 | return DBSession.query(cls).filter(cls.id == id).one() |
||
| 24 | |||
| 25 | @classmethod |
||
| 26 | def all(cls): |
||
| 27 | return DBSession.query(cls)\ |
||
| 28 | .filter(cls.enabled)\ |
||
| 29 | .order_by(cls.name)\ |
||
| 30 | .all() |
||
| 31 | |||
| 32 | @classmethod |
||
| 33 | def get_owed(cls): |
||
| 34 | return DBSession.query(cls)\ |
||
| 35 | .filter(cls.enabled)\ |
||
| 36 | .filter(cls.balance != 0)\ |
||
| 37 | .order_by(cls.name)\ |
||
| 38 | .all() |
||
| 39 | |||
| 40 | @classmethod |
||
| 41 | def count(cls): |
||
| 42 | return DBSession.query(func.count(cls.id).label('c'))\ |
||
| 43 | .filter(cls.enabled == True)\ |
||
| 44 | .one().c |
||
| 45 | |||
| 46 | @classmethod |
||
| 47 | def get_outstanding_reimbursements_total(cls): |
||
| 48 | return DBSession.query(func.sum(Reimbursee.balance).label("total_balance"))\ |
||
| 49 | .one().total_balance or Decimal(0.0) |
||
| 50 |