2019-04-11 21:56:55 +00:00
|
|
|
from datetime import datetime
|
2019-05-02 23:40:13 +00:00
|
|
|
from geruecht import getLogger
|
|
|
|
|
|
|
|
LOGGER = getLogger(__name__)
|
2019-12-19 17:26:41 +00:00
|
|
|
def create_empty_data():
|
|
|
|
empty_data = {'id': 0,
|
|
|
|
'jan_guthaben': 0,
|
|
|
|
'jan_schulden': 0,
|
|
|
|
'feb_guthaben': 0,
|
|
|
|
'feb_schulden': 0,
|
|
|
|
'maer_guthaben': 0,
|
|
|
|
'maer_schulden': 0,
|
|
|
|
'apr_guthaben': 0,
|
|
|
|
'apr_schulden': 0,
|
|
|
|
'mai_guthaben': 0,
|
|
|
|
'mai_schulden': 0,
|
|
|
|
'jun_guthaben': 0,
|
|
|
|
'jun_schulden': 0,
|
|
|
|
'jul_guthaben': 0,
|
|
|
|
'jul_schulden': 0,
|
|
|
|
'aug_guthaben': 0,
|
|
|
|
'aug_schulden': 0,
|
|
|
|
'sep_guthaben': 0,
|
|
|
|
'sep_schulden': 0,
|
|
|
|
'okt_guthaben': 0,
|
|
|
|
'okt_schulden': 0,
|
|
|
|
'nov_guthaben': 0,
|
|
|
|
'nov_schulden': 0,
|
|
|
|
'dez_guthaben': 0,
|
|
|
|
'dez_schulden': 0,
|
|
|
|
'last_schulden': 0,
|
|
|
|
'year_date': datetime.now().year,
|
|
|
|
'user_id': 0}
|
|
|
|
return empty_data
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 07:12:29 +00:00
|
|
|
class CreditList():
|
2019-04-17 12:46:46 +00:00
|
|
|
""" DataBase Object Credit List:
|
2019-05-01 20:43:28 +00:00
|
|
|
|
2019-04-17 12:46:46 +00:00
|
|
|
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.
|
2019-04-23 22:08:25 +00:00
|
|
|
user_id: id from the User.
|
2019-04-17 12:46:46 +00:00
|
|
|
"""
|
2019-12-19 17:26:41 +00:00
|
|
|
def __init__(self, data):
|
|
|
|
LOGGER.debug("Initialize Geruecht")
|
|
|
|
self.id = int(data['id'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.jan_guthaben = int(data['jan_guthaben'])
|
|
|
|
self.jan_schulden = int(data['jan_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.feb_guthaben = int(data['feb_guthaben'])
|
|
|
|
self.feb_schulden = int(data['feb_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.maer_guthaben = int(data['maer_guthaben'])
|
|
|
|
self.maer_schulden = int(data['maer_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.apr_guthaben = int(data['apr_guthaben'])
|
|
|
|
self.apr_schulden = int(data['apr_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.mai_guthaben = int(data['mai_guthaben'])
|
|
|
|
self.mai_schulden = int(data['mai_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.jun_guthaben = int(data['jun_guthaben'])
|
|
|
|
self.jun_schulden = int(data['jun_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.jul_guthaben = int(data['jul_guthaben'])
|
|
|
|
self.jul_schulden = int(data['jul_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.aug_guthaben = int(data['aug_guthaben'])
|
|
|
|
self.aug_schulden = int(data['aug_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.sep_guthaben = int(data['sep_guthaben'])
|
|
|
|
self.sep_schulden = int(data['sep_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.okt_guthaben = int(data['okt_guthaben'])
|
|
|
|
self.okt_schulden = int(data['okt_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.nov_guthaben = int(data['nov_guthaben'])
|
|
|
|
self.nov_schulden = int(data['nov_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.dez_guthaben = int(data['dez_guthaben'])
|
|
|
|
self.dez_schulden = int(data['dez_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.last_schulden = int(data['last_schulden'])
|
2019-04-11 21:56:55 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.year = int(data['year_date'])
|
2019-04-23 18:26:20 +00:00
|
|
|
|
2019-12-19 17:26:41 +00:00
|
|
|
self.user_id = int(data['user_id'])
|
|
|
|
|
2019-04-23 22:08:25 +00:00
|
|
|
def getSchulden(self):
|
2019-05-02 16:50:59 +00:00
|
|
|
""" Get Schulden
|
|
|
|
|
|
|
|
This function calculate the total amount of them self.
|
|
|
|
From the Credit of the Month will the Amount of the Month subtract.
|
|
|
|
Finaly all Month will added together.
|
|
|
|
At Last the amount from last year will be subtract.
|
|
|
|
|
|
|
|
If the Return Value is negativ, the User has an Credit, else the User has an amount.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
double of the calculated amount
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Calculate amount")
|
2019-04-23 22:08:25 +00:00
|
|
|
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
|
|
|
|
|
2019-05-02 00:21:50 +00:00
|
|
|
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Calculated amount is {}".format(sum))
|
2019-04-23 22:08:25 +00:00
|
|
|
return sum
|
|
|
|
|
2019-05-02 16:50:59 +00:00
|
|
|
def getMonth(self, month=datetime.now().month):
|
|
|
|
""" Get Amount from month
|
|
|
|
|
|
|
|
This function returns the amount and credit of the month.
|
|
|
|
By default is month the actual month
|
|
|
|
|
|
|
|
Args:
|
|
|
|
month: which month you want to get the amount(1-12)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
double (credit, amount)
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Get Credit and Amount from Month {}".format(month))
|
2019-04-23 22:08:25 +00:00
|
|
|
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:
|
2020-03-03 21:33:47 +00:00
|
|
|
retValue = (self.maer_guthaben, self.maer_schulden)
|
2019-04-23 22:08:25 +00:00
|
|
|
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)
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
2019-04-23 22:08:25 +00:00
|
|
|
return retValue
|
|
|
|
|
2019-05-02 00:21:50 +00:00
|
|
|
def addAmount(self, amount, month=datetime.now().month):
|
2019-05-02 16:50:59 +00:00
|
|
|
""" Add Amount
|
|
|
|
|
|
|
|
This function add an amount to a month and returns the credit and amount of the month.
|
|
|
|
By default is month the actual month.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
amount: the amount which is to add
|
|
|
|
month: in which month to add the amount (1-12)
|
2019-04-23 22:08:25 +00:00
|
|
|
|
2019-05-02 16:50:59 +00:00
|
|
|
Returns:
|
|
|
|
double (credit, amount)
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Add Amount in Month {}".format(month))
|
2019-04-23 22:08:25 +00:00
|
|
|
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)
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
2019-05-02 00:21:50 +00:00
|
|
|
return retValue
|
|
|
|
|
|
|
|
def addCredit(self, credit, month=datetime.now().month):
|
2019-05-02 16:50:59 +00:00
|
|
|
""" Add Credit
|
|
|
|
|
|
|
|
This function add an credit to a month and returns the credit and amount of the month.
|
|
|
|
By default is month the actual month.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
credit: the credit which is to add
|
|
|
|
month: in which month to add the credit (1-12)
|
2019-05-02 00:21:50 +00:00
|
|
|
|
2019-05-02 16:50:59 +00:00
|
|
|
Returns:
|
|
|
|
double (credit, amount)
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Add Credit in Month {}".format(month))
|
2019-05-02 00:21:50 +00:00
|
|
|
if month == 1:
|
|
|
|
self.jan_guthaben += credit
|
|
|
|
retValue = (self.jan_guthaben, self.jan_schulden)
|
|
|
|
elif month == 2:
|
|
|
|
self.feb_guthaben += credit
|
|
|
|
retValue = (self.feb_guthaben, self.feb_schulden)
|
|
|
|
elif month == 3:
|
|
|
|
self.maer_guthaben += credit
|
|
|
|
retValue = (self.maer_guthaben, self.maer_schulden)
|
|
|
|
elif month == 4:
|
|
|
|
self.apr_guthaben += credit
|
|
|
|
retValue = (self.apr_guthaben, self.apr_schulden)
|
|
|
|
elif month == 5:
|
|
|
|
self.mai_guthaben += credit
|
|
|
|
retValue = (self.mai_guthaben, self.mai_schulden)
|
|
|
|
elif month == 6:
|
|
|
|
self.jun_guthaben += credit
|
|
|
|
retValue = (self.jun_guthaben, self.jun_schulden)
|
|
|
|
elif month == 7:
|
|
|
|
self.jul_guthaben += credit
|
|
|
|
retValue = (self.jul_guthaben, self.jul_schulden)
|
|
|
|
elif month == 8:
|
|
|
|
self.aug_guthaben += credit
|
|
|
|
retValue = (self.aug_guthaben, self.aug_schulden)
|
|
|
|
elif month == 9:
|
|
|
|
self.sep_guthaben += credit
|
|
|
|
retValue = (self.sep_guthaben, self.sep_schulden)
|
|
|
|
elif month == 10:
|
|
|
|
self.okt_guthaben += credit
|
|
|
|
retValue = (self.okt_guthaben, self.okt_schulden)
|
|
|
|
elif month == 11:
|
|
|
|
self.nov_guthaben += credit
|
|
|
|
retValue = (self.nov_guthaben, self.nov_schulden)
|
|
|
|
elif month == 12:
|
|
|
|
self.dez_guthaben += credit
|
|
|
|
retValue = (self.dez_guthaben, self.dez_schulden)
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
2019-04-23 22:08:25 +00:00
|
|
|
return retValue
|
|
|
|
|
|
|
|
def toJSON(self):
|
|
|
|
""" Create Dic to dump in JSON
|
2019-05-01 20:43:28 +00:00
|
|
|
|
2019-04-23 22:08:25 +00:00
|
|
|
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},
|
2019-12-26 09:28:30 +00:00
|
|
|
"last": self.last_schulden
|
2019-04-23 22:08:25 +00:00
|
|
|
}
|
2019-05-01 20:43:28 +00:00
|
|
|
return dic
|
2019-05-02 23:40:13 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "CreditList(year: {}, userID: {}, amount: {})".format(self.year, self.user_id, self.toJSON())
|