Working authorize needs work
This commit is contained in:
@@ -890,11 +890,14 @@ def calculate_total(delivery_id):
|
|||||||
This will get deliveries not done
|
This will get deliveries not done
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
get_delivery = (db.session
|
get_delivery = (db.session
|
||||||
.query(Delivery_Delivery)
|
.query(Delivery_Delivery)
|
||||||
.filter(Delivery_Delivery.id == delivery_id)
|
.filter(Delivery_Delivery.id == delivery_id)
|
||||||
.first())
|
.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:
|
if get_delivery.promo_id:
|
||||||
get_promo_data = (db.session
|
get_promo_data = (db.session
|
||||||
.query(Promo_Promo)
|
.query(Promo_Promo)
|
||||||
@@ -902,14 +905,14 @@ def calculate_total(delivery_id):
|
|||||||
.first())
|
.first())
|
||||||
discount_gallon_price = get_delivery.customer_price - get_promo_data.money_off_delivery
|
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 = (gallons * get_delivery.customer_price) - total_amount_after_discount
|
||||||
discount = (get_delivery.gallons_ordered * get_delivery.customer_price) - total_amount_after_discount
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
discount = 0
|
discount = 0
|
||||||
total_amount_after_discount = 0
|
total_amount_after_discount = 0
|
||||||
|
|
||||||
get_price_query = (db.session
|
get_price_query = (db.session
|
||||||
.query(Pricing_Oil_Oil)
|
.query(Pricing_Oil_Oil)
|
||||||
.order_by(Pricing_Oil_Oil.date.desc())
|
.order_by(Pricing_Oil_Oil.date.desc())
|
||||||
@@ -930,16 +933,17 @@ def calculate_total(delivery_id):
|
|||||||
else:
|
else:
|
||||||
pricesameday = 0
|
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)
|
priceprime = round(priceprime, 2)
|
||||||
pricesameday = round(pricesameday, 2)
|
pricesameday = round(pricesameday, 2)
|
||||||
priceemergency = round(priceemergency, 2)
|
priceemergency = round(priceemergency, 2)
|
||||||
priceprime = round(priceprime, 2)
|
|
||||||
total_amount_after_discount = round(total_amount_after_discount, 2)
|
total_amount_after_discount = round(total_amount_after_discount, 2)
|
||||||
discount = round(discount, 2)
|
discount = round(discount, 2)
|
||||||
total = round(total, 2)
|
total = round(total, 2)
|
||||||
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
'priceprime': priceprime,
|
'priceprime': priceprime,
|
||||||
|
|||||||
Reference in New Issue
Block a user