diff --git a/app/models.py b/app/models.py index 67af9d2..4f8d627 100644 --- a/app/models.py +++ b/app/models.py @@ -126,11 +126,14 @@ class Dessert(db.Model): class Service(db.Model): + pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) sandwitch1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) sandwitch2_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) sandwitch3_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) + commi1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) + commi2_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True) date = db.Column(db.Date, default=datetime.datetime.now().date, primary_key=True, unique=True) sandwitch1 = db.Column(db.Boolean, default=False) sandwitch2 = db.Column(db.Boolean, default=False) - sandwitch3 = db.Column(db.Boolean, default=False) \ No newline at end of file + sandwitch3 = db.Column(db.Boolean, default=False) diff --git a/app/sockets.py b/app/sockets.py index 9bf9d72..aac0e9f 100644 --- a/app/sockets.py +++ b/app/sockets.py @@ -113,7 +113,7 @@ def addcmd(json): @socketio.on("clear command") @authenticated_only def rmcmd(json): - c = Command.query.get(json["id"]) + c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first() if c: c.done = None c.give = None @@ -131,7 +131,7 @@ def rmcmd(json): @socketio.on("done command") @authenticated_only def donecmd(json): - c = Command.query.get(json["id"]) + c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first() if c: c.done = datetime.datetime.now().time() service = Service.query.filter_by(date=datetime.datetime.now().date()).first() @@ -147,9 +147,15 @@ def donecmd(json): @socketio.on("give command") @authenticated_only def givecmd(json): - c = Command.query.get(json["id"]) + c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first() if c: c.give = datetime.datetime.now().time() + service = Service.query.filter_by(date=datetime.datetime.now().date()).first() + if service and c.WIP: + sandwitchs = [service.sandwitch1_id, service.sandwitch2_id, service.sandwitch3_id] + if c.sandwitch_id in sandwitchs: + setattr(service, f"sandwitch{sandwitchs.index(c.sandwitch_id)+1}", False) + c.WIP = False db.session.commit() emit("gave command", {"id": json["id"]}, broadcast=True) @@ -157,7 +163,7 @@ def givecmd(json): @socketio.on("WIP command") @authenticated_only def wipcmd(json): - c = Command.query.get(json["id"]) + c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first() if c: c.WIP = True service = Service.query.filter_by(date=datetime.datetime.now().date()).first() @@ -177,7 +183,7 @@ def wipcmd(json): @socketio.on("error command") @authenticated_only def errcmd(json): - c = Command.query.get(json["id"]) + c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first() if c: c.error = True db.session.commit() diff --git a/app/static/js/kitchen.js b/app/static/js/kitchen.js index 5b5de84..bdf0ae6 100644 --- a/app/static/js/kitchen.js +++ b/app/static/js/kitchen.js @@ -7,27 +7,6 @@ let waiting = document.getElementById("attente"); function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) { done.insertAdjacentHTML("beforeend", `
${plate} | ${ingredient}
${sauce}
${drink}
${dessert}