small fixes

This commit is contained in:
2024-12-23 18:10:18 -05:00
parent 86ec25a499
commit e6f85ff014
4 changed files with 152 additions and 18 deletions

View File

@@ -3,9 +3,21 @@ import decimal
from datetime import datetime
from app.promo import promo
from app import db
from app.classes.promo import Promo_Promo, Promo_Promo_schema
from app.classes.promo import (
Promo_Promo,
Promo_Promo_schema)
from app.classes.delivery import (Delivery_Delivery,
Delivery_Delivery_schema,
Delivery_Notes_Driver,
)
def convert_to_decimal(text):
try:
number = float(text)
return round(number, 2)
except ValueError:
return "0"
@promo.route("/<int:promo_id>", methods=["GET"])
def get_promo(promo_id):
@@ -19,6 +31,24 @@ def get_promo(promo_id):
return jsonify(query_schema.dump(get_promo_data))
@promo.route("/promoprice/<int:delivery_id>", methods=["GET"])
def get_promo_price(delivery_id):
"""
"""
get_delivery = (db.session
.query(Delivery_Delivery)
.filter(Delivery_Delivery.id == delivery_id)
.first())
price = get_delivery.customer_price - get_delivery.promo_money_discount
price = convert_to_decimal(price)
return jsonify({
"ok": True,
"price": price,
}), 200
@promo.route("/all", methods=["GET"])
def get_all_promo():
"""
@@ -58,9 +88,11 @@ def create_promo():
text_on_ticket = request.json["text_on_ticket"]
# see if it exists
amount_off = convert_to_decimal(money_off_delivery)
new_promo = Promo_Promo(
name_of_promotion = name_of_promotion,
money_off_delivery = float(money_off_delivery),
money_off_delivery = amount_off,
description = description,
date_created = date_created,
text_on_ticket=text_on_ticket
@@ -89,10 +121,13 @@ def edit_promo(promo_id):
money_off_delivery = request.json["money_off_delivery"]
description = request.json["description"]
amount_off = convert_to_decimal(money_off_delivery)
get_promo_data.text_on_ticket = text_on_ticket
get_promo_data.description = description
get_promo_data.name_of_promotion = name_of_promotion
get_promo_data.money_off_delivery = float(money_off_delivery)
get_promo_data.money_off_delivery = amount_off
db.session.add(get_promo_data)
db.session.commit()