tons fixes
This commit is contained in:
@@ -1,10 +1,40 @@
|
||||
from flask import jsonify
|
||||
from decimal import Decimal
|
||||
from app.info import info
|
||||
from app import db
|
||||
from app.classes.pricing import Pricing_Oil_Oil, Pricing_Oil_Oil_schema
|
||||
from app.classes.admin import Admin_Company
|
||||
|
||||
|
||||
|
||||
|
||||
@info.route("/price/oil/tiers", methods=["GET"])
|
||||
def get_pricing_tiers():
|
||||
get_price_query = (db.session
|
||||
.query(Pricing_Oil_Oil)
|
||||
.order_by(Pricing_Oil_Oil.date.desc())
|
||||
.first())
|
||||
|
||||
if not get_price_query:
|
||||
return jsonify({"error": "No pricing data available"}), 404
|
||||
|
||||
# Get the single price per gallon from the database, e.g., Decimal('2.92')
|
||||
price_per_gallon = get_price_query.price_for_customer
|
||||
|
||||
# Define the specific gallon amounts you want to display totals for
|
||||
gallon_tiers = [100, 125, 150, 175, 200, 220]
|
||||
|
||||
# Calculate the total price for each gallon amount by multiplication
|
||||
# e.g., { 100: (2.92 * 100), 125: (2.92 * 125), ... }
|
||||
pricing_totals = {
|
||||
gallons: price_per_gallon * gallons
|
||||
for gallons in gallon_tiers
|
||||
}
|
||||
|
||||
# Return the dictionary of totals
|
||||
# e.g., { "100": "292.00", "125": "365.00", ... }
|
||||
return jsonify(pricing_totals)
|
||||
|
||||
@info.route("/price/oil", methods=["GET"])
|
||||
def get_oil_price_today():
|
||||
get_price_query = (db.session
|
||||
|
||||
Reference in New Issue
Block a user