Send and save price of command
This commit is contained in:
parent
1589c70984
commit
4d41098481
3 changed files with 18 additions and 3 deletions
|
@ -42,6 +42,7 @@ class Command(db.Model):
|
||||||
sandwich_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
sandwich_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
client_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
client_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
||||||
|
|
||||||
|
price = db.Column(db.Float, nullable=False)
|
||||||
date = db.Column(db.Date, default=datetime.datetime.now().date)
|
date = db.Column(db.Date, default=datetime.datetime.now().date)
|
||||||
take = db.Column(db.Time, default=datetime.datetime.now().time)
|
take = db.Column(db.Time, default=datetime.datetime.now().time)
|
||||||
done = db.Column(db.Time)
|
done = db.Column(db.Time)
|
||||||
|
@ -63,7 +64,7 @@ class Plate(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
price = db.Column(db.Integer, default=0)
|
price = db.Column(db.Float, default=0)
|
||||||
avoid_ingredient = db.Column(db.Boolean, default=False)
|
avoid_ingredient = db.Column(db.Boolean, default=False)
|
||||||
avoid_sauce = db.Column(db.Boolean, default=False)
|
avoid_sauce = db.Column(db.Boolean, default=False)
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,6 @@ def addcmd(json):
|
||||||
Command.number.desc()).first().number + 1
|
Command.number.desc()).first().number + 1
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
c.number = 1
|
c.number = 1
|
||||||
c.pc_id = json["pc"]
|
|
||||||
if all(i in json and json[i] for i in ["firstname", "lastname", "client"]):
|
if all(i in json and json[i] for i in ["firstname", "lastname", "client"]):
|
||||||
db.session.add(User(username=json["client"], firstname=json["firstname"], lastname=json["lastname"]))
|
db.session.add(User(username=json["client"], firstname=json["firstname"], lastname=json["lastname"]))
|
||||||
if "client" in json:
|
if "client" in json:
|
||||||
|
@ -80,6 +79,18 @@ def addcmd(json):
|
||||||
c.client_id = User.query.filter_by(username=json["client"]).first().id
|
c.client_id = User.query.filter_by(username=json["client"]).first().id
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
c.client_id = User.query.filter_by(username="dummy").first().id
|
c.client_id = User.query.filter_by(username="dummy").first().id
|
||||||
|
if "pc" in json:
|
||||||
|
try:
|
||||||
|
c.pc_id = User.query.filter_by(username=json["pc"]).first().id
|
||||||
|
except AttributeError:
|
||||||
|
c.pc_id = User.query.filter_by(username="dummy").first().id
|
||||||
|
if "price" in json:
|
||||||
|
try:
|
||||||
|
c.price = json["price"]
|
||||||
|
except AttributeError:
|
||||||
|
c.price = -1
|
||||||
|
else:
|
||||||
|
c.price = -1
|
||||||
if "plate" in json:
|
if "plate" in json:
|
||||||
try:
|
try:
|
||||||
c.plate_id = Plate.query.get(json["plate"]).id
|
c.plate_id = Plate.query.get(json["plate"]).id
|
||||||
|
|
|
@ -175,6 +175,7 @@ function price () {
|
||||||
}
|
}
|
||||||
p = p.toFixed(2);
|
p = p.toFixed(2);
|
||||||
document.querySelector("#resume h2").innerHTML = p+"€";
|
document.querySelector("#resume h2").innerHTML = p+"€";
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on("connect", data => {
|
socket.on("connect", data => {
|
||||||
|
@ -296,6 +297,7 @@ document.querySelector(".validation").addEventListener("click", ev => {
|
||||||
|
|
||||||
current["client"] = user.value;
|
current["client"] = user.value;
|
||||||
current["pc"] = pc_id;
|
current["pc"] = pc_id;
|
||||||
|
current["price"] = price();
|
||||||
socket.emit("add command", current);
|
socket.emit("add command", current);
|
||||||
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
|
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
|
||||||
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
|
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
|
||||||
|
@ -311,6 +313,7 @@ document.querySelector(".validation").addEventListener("click", ev => {
|
||||||
user.value = "";
|
user.value = "";
|
||||||
user.style.color = "";
|
user.style.color = "";
|
||||||
document.getElementById("user_list").innerHTML = "";
|
document.getElementById("user_list").innerHTML = "";
|
||||||
|
document.querySelector("#resume h2").innerHTML = "0€";
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("user").addEventListener("keyup", ev => {hinter(ev)});
|
document.getElementById("user").addEventListener("keyup", ev => {hinter(ev)});
|
||||||
|
|
Reference in a new issue