From 068abb43a221cc9fedee703ba37938514beb6564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 4 Jun 2020 21:20:38 +0200 Subject: [PATCH] fixed bug ##259 --- .../databaseController/dbJobKindController.py | 20 +++++++++++++++++++ .../databaseController/dbWorkerController.py | 20 +++++++++++-------- .../mainController/mainWorkerController.py | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/geruecht/controller/databaseController/dbJobKindController.py b/geruecht/controller/databaseController/dbJobKindController.py index c243f0d..d131eb3 100644 --- a/geruecht/controller/databaseController/dbJobKindController.py +++ b/geruecht/controller/databaseController/dbJobKindController.py @@ -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() diff --git a/geruecht/controller/databaseController/dbWorkerController.py b/geruecht/controller/databaseController/dbWorkerController.py index 7a2e917..3d7652d 100644 --- a/geruecht/controller/databaseController/dbWorkerController.py +++ b/geruecht/controller/databaseController/dbWorkerController.py @@ -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() diff --git a/geruecht/controller/mainController/mainWorkerController.py b/geruecht/controller/mainController/mainWorkerController.py index 4ae0d16..91a3068 100644 --- a/geruecht/controller/mainController/mainWorkerController.py +++ b/geruecht/controller/mainController/mainWorkerController.py @@ -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)