Files
eamco_office_api/app/info/views.py

87 lines
3.0 KiB
Python
Executable File

import logging
from decimal import Decimal
from app.info import info
from app import db
from app.common.responses import error_response, success_response
from app.classes.pricing import Pricing_Oil_Oil, Pricing_Oil_Oil_schema
from app.classes.admin import Admin_Company
from app.classes.delivery import Delivery_Delivery
from app.classes.service import Service_Service
from flask_login import login_required
logger = logging.getLogger(__name__)
@info.route("/price/oil/tiers", methods=["GET"])
@login_required
def get_pricing_tiers():
logger.info("GET /info/price/oil/tiers - Fetching oil 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 error_response("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
pricing_totals = {
gallons: price_per_gallon * gallons
for gallons in gallon_tiers
}
# Return the dictionary of totals
return success_response({"pricing_tiers": pricing_totals})
@info.route("/price/oil", methods=["GET"])
@login_required
def get_oil_price_today():
logger.info("GET /info/price/oil - Fetching current oil prices")
get_price_query = (db.session
.query(Pricing_Oil_Oil)
.order_by(Pricing_Oil_Oil.date.desc())
.first())
return success_response({
'price_from_supplier': get_price_query.price_from_supplier,
'price_for_customer': get_price_query.price_for_customer,
'price_for_employee': get_price_query.price_for_employee,
'price_same_day': get_price_query.price_same_day,
'price_prime': get_price_query.price_prime,
'price_emergency': get_price_query.price_emergency,
})
@info.route("/price/oil/table", methods=["GET"])
@login_required
def get_pricing():
logger.info("GET /info/price/oil/table - Fetching oil pricing table")
get_price_query = (db.session
.query(Pricing_Oil_Oil)
.order_by(Pricing_Oil_Oil.date.desc())
.first())
delivery_schema = Pricing_Oil_Oil_schema(many=False)
return success_response({"pricing": delivery_schema.dump(get_price_query)})
@info.route("/company", methods=["GET"])
@login_required
def get_company():
logger.info("GET /info/company - Fetching company information")
get_data_company = (db.session
.query(Admin_Company)
.first())
return success_response({
'name': get_data_company.company_name,
'telephone': get_data_company.company_phone_number,
})