fixed bug ##259

This commit is contained in:
Tim Gröger 2020-06-04 21:20:38 +02:00
parent 44155b9678
commit 068abb43a2
3 changed files with 33 additions and 9 deletions

View File

@ -101,6 +101,26 @@ class Base:
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def getJobKindDate(self, date, job_kind):
try:
cursor = self.db.connection.cursor()
cursor.execute("select * from job_kind_dates where daydate='{}' and job_kind={}".format(date, job_kind['id']))
item = cursor.fetchone()
if item:
item['job_kind'] = self.getJobKind(item['job_kind']) if item['job_kind'] != None else None
item['daydate'] = {'year': item['daydate'].year, 'month': item['daydate'].month, 'day': item['daydate'].day}
else:
item = {
'job_kind': self.getJobKind(1),
'daydate': {'year': date.year, 'month': date.month, 'day': date.day},
'maxpersons': 2
}
return item
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def deleteJobKindDates(self, jobkinddates):
try:
cursor = self.db.connection.cursor()

View File

@ -22,14 +22,18 @@ class Base:
cursor.execute("select * from bardienste where startdatetime='{}'".format(date))
data = cursor.fetchall()
retVal = []
# for work in data:
# user = self.getUserById(work['user_id']).toJSON()
# startdatetime = work['startdatetime']
# enddatetime = work['enddatetime']
# start = { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}
# job_kind = self.getJobKind(work['job_kind']) if work['job_kind'] != None else None
# retVal.append({'user': user, 'startdatetime': startdatetime, 'enddatetime': enddatetime, 'start': start, 'job_kind': job_kind})
# return retVal
return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}, "job_kind": self.getJobKind(work['job_kind']) if work['job_kind'] != None else None} for work in data]
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
def getWorkersWithJobKind(self, date, job_kind):
try:
cursor = self.db.connection.cursor()
cursor.execute("select * from bardienste where startdatetime='{}' and job_kind={} {}".format(date, job_kind['id'], "or job_kind='null'" if job_kind['id'] is 1 else ''))
data = cursor.fetchall()
retVal = []
return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}, "job_kind": self.getJobKind(work['job_kind']) if work['job_kind'] != None else None} for work in data]
except Exception as err:
traceback.print_exc()

View File

@ -32,7 +32,7 @@ class Base:
user = self.getUser(username)
debug.debug("user is {{ {} }}".format(user))
debug.debug("check if user has job on date")
if (not db.getWorker(user, date)):
if (not db.getWorker(user, date) and len(db.getWorkersWithJobKind(date, job_kind)) < db.getJobKindDate(date.date(), job_kind)['maxpersons']):
debug.debug("set job to user")
db.setWorker(user, date, job_kind=job_kind)
retVal = self.getWorker(date, username=username)