Working authorize needs work

This commit is contained in:
2025-09-07 17:53:13 -04:00
parent a280194079
commit 8753e3e103

View File

@@ -890,31 +890,34 @@ def calculate_total(delivery_id):
This will get deliveries not done
"""
get_delivery = (db.session
.query(Delivery_Delivery)
.filter(Delivery_Delivery.id == delivery_id)
.first())
# Use gallons_delivered if available and > 0, otherwise use gallons_ordered
gallons = get_delivery.gallons_delivered if get_delivery.gallons_delivered and get_delivery.gallons_delivered > 0 else get_delivery.gallons_ordered
if get_delivery.promo_id:
get_promo_data = (db.session
.query(Promo_Promo)
.filter(Promo_Promo.id == get_delivery.promo_id)
get_promo_data = (db.session
.query(Promo_Promo)
.filter(Promo_Promo.id == get_delivery.promo_id)
.first())
discount_gallon_price = get_delivery.customer_price - get_promo_data.money_off_delivery
total_amount_after_discount = (get_delivery.gallons_ordered * discount_gallon_price)
total_amount_after_discount = (gallons * discount_gallon_price)
discount = (get_delivery.gallons_ordered * get_delivery.customer_price) - total_amount_after_discount
discount = (gallons * get_delivery.customer_price) - total_amount_after_discount
else:
discount = 0
total_amount_after_discount = 0
get_price_query = (db.session
.query(Pricing_Oil_Oil)
.order_by(Pricing_Oil_Oil.date.desc())
.first())
if get_delivery.prime == 1:
priceprime = float(get_price_query.price_prime)
else:
@@ -929,17 +932,18 @@ def calculate_total(delivery_id):
pricesameday = float(get_price_query.price_same_day)
else:
pricesameday = 0
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday) + float(priceemergency)
# Recalculate base price using actual gallons
base_price = gallons * get_delivery.customer_price
total = float(base_price) + float(priceprime) + float(pricesameday) + float(priceemergency)
priceprime = round(priceprime, 2)
pricesameday = round(pricesameday, 2)
priceemergency = round(priceemergency, 2)
priceprime = round(priceprime, 2)
total_amount_after_discount = round(total_amount_after_discount, 2)
discount = round(discount, 2)
total = round(total, 2)
return jsonify({
"ok": True,
'priceprime': priceprime,