flaschengeist/geruecht/model/creditList.py

195 lines
7.3 KiB
Python

from geruecht import db
from datetime import datetime
class CreditList(db.Model):
""" DataBase Object Credit List:
Attributes:
id: id in Database. Is the Primary Key
<month>_guthaben: Credit of the Month.
<month>_schulden: Debt of the Month.
last_schulden: Debt or Credit of last Year.
year: Year of all Credits and Debts.
user_id: id from the User.
TODO: link to user???
"""
id = db.Column(db.Integer, primary_key=True)
jan_guthaben = db.Column(db.Integer, nullable=False, default=0)
jan_schulden = db.Column(db.Integer, nullable=False, default=0)
feb_guthaben = db.Column(db.Integer, nullable=False, default=0)
feb_schulden = db.Column(db.Integer, nullable=False, default=0)
maer_guthaben = db.Column(db.Integer, nullable=False, default=0)
maer_schulden = db.Column(db.Integer, nullable=False, default=0)
apr_guthaben = db.Column(db.Integer, nullable=False, default=0)
apr_schulden = db.Column(db.Integer, nullable=False, default=0)
mai_guthaben = db.Column(db.Integer, nullable=False, default=0)
mai_schulden = db.Column(db.Integer, nullable=False, default=0)
jun_guthaben = db.Column(db.Integer, nullable=False, default=0)
jun_schulden = db.Column(db.Integer, nullable=False, default=0)
jul_guthaben = db.Column(db.Integer, nullable=False, default=0)
jul_schulden = db.Column(db.Integer, nullable=False, default=0)
aug_guthaben = db.Column(db.Integer, nullable=False, default=0)
aug_schulden = db.Column(db.Integer, nullable=False, default=0)
sep_guthaben = db.Column(db.Integer, nullable=False, default=0)
sep_schulden = db.Column(db.Integer, nullable=False, default=0)
okt_guthaben = db.Column(db.Integer, nullable=False, default=0)
okt_schulden = db.Column(db.Integer, nullable=False, default=0)
nov_guthaben = db.Column(db.Integer, nullable=False, default=0)
nov_schulden = db.Column(db.Integer, nullable=False, default=0)
dez_guthaben = db.Column(db.Integer, nullable=False, default=0)
dez_schulden = db.Column(db.Integer, nullable=False, default=0)
last_schulden = db.Column(db.Integer, nullable=False, default=0)
year = db.Column(db.Integer, nullable=False, default=datetime.now().year)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def getSchulden(self):
jan = self.jan_guthaben - self.jan_schulden
feb = self.feb_guthaben - self.feb_schulden
maer = self.maer_guthaben - self.maer_schulden
apr = self.apr_guthaben - self.apr_schulden
mai = self.mai_guthaben - self.mai_schulden
jun = self.jun_guthaben - self.jun_schulden
jul = self.jul_guthaben - self.jul_schulden
aug = self.aug_guthaben - self.aug_schulden
sep = self.sep_guthaben - self.sep_schulden
okt = self.okt_guthaben - self.okt_schulden
nov = self.nov_guthaben - self.nov_schulden
dez = self.dez_guthaben - self.dez_schulden
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez + self.last_schulden
return sum
def getMonth(self, month):
retValue = None
if month == 1:
retValue = (self.jan_guthaben, self.jan_schulden)
elif month == 2:
retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3:
retValue = (self.mear_guthaben, self.maer_schulden)
elif month == 4:
retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5:
retValue = (self.mai_guthaben, self.mai_schulden)
elif month == 6:
retValue = (self.jun_guthaben, self.jun_schulden)
elif month == 7:
retValue = (self.jul_guthaben, self.jul_schulden)
elif month == 8:
retValue = (self.aug_guthaben, self.aug_schulden)
elif month == 9:
retValue = (self.sep_guthaben, self.sep_schulden)
elif month == 10:
retValue = (self.okt_guthaben, self.okt_schulden)
elif month == 11:
retValue = (self.nov_guthaben, self.nov_schulden)
elif month == 12:
retValue = (self.dez_guthaben, self.dez_schulden)
return retValue
def addAmount(self, amount):
month = datetime.now().month
if month == 1:
self.jan_schulden += amount
retValue = (self.jan_guthaben, self.jan_schulden)
elif month == 2:
self.feb_schulden += amount
retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3:
self.maer_schulden += amount
retValue = (self.maer_guthaben, self.maer_schulden)
elif month == 4:
self.apr_schulden += amount
retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5:
self.mai_schulden += amount
retValue = (self.mai_guthaben, self.mai_schulden)
elif month == 6:
self.jun_schulden += amount
retValue = (self.jun_guthaben, self.jun_schulden)
elif month == 7:
self.jul_schulden += amount
retValue = (self.jul_guthaben, self.jul_schulden)
elif month == 8:
self.aug_schulden += amount
retValue = (self.aug_guthaben, self.aug_schulden)
elif month == 9:
self.sep_schulden += amount
retValue = (self.sep_guthaben, self.sep_schulden)
elif month == 10:
self.okt_schulden += amount
retValue = (self.okt_guthaben, self.okt_schulden)
elif month == 11:
self.nov_schulden += amount
retValue = (self.nov_guthaben, self.nov_schulden)
elif month == 12:
self.dez_schulden += amount
retValue = (self.dez_guthaben, self.dez_schulden)
return retValue
def toJSON(self):
""" Create Dic to dump in JSON
Returns:
A Dic with static Attributes.
"""
dic = {
"jan": {
"credit": self.jan_guthaben,
"depts": self.jan_schulden},
"feb": {
"credit": self.feb_guthaben,
"depts": self.feb_schulden},
"maer": {
"credit": self.maer_guthaben,
"depts": self.maer_schulden},
"apr": {
"credit": self.apr_guthaben,
"depts": self.apr_schulden},
"mai": {
"credit": self.mai_guthaben,
"depts": self.mai_schulden},
"jun": {
"credit": self.jun_guthaben,
"depts": self.jun_schulden},
"jul": {
"credit": self.jul_guthaben,
"depts": self.jul_schulden},
"aug": {
"credit": self.aug_guthaben,
"depts": self.aug_schulden},
"sep": {
"credit": self.sep_guthaben,
"depts": self.sep_schulden},
"okt": {
"credit": self.okt_guthaben,
"depts": self.okt_schulden},
"nov": {
"credit": self.nov_guthaben,
"depts": self.nov_schulden},
"dez": {
"credit": self.dez_guthaben,
"depts": self.dez_schulden},
}
return dic