Files
eamco_office_api/app/reports/views.py

46 lines
1.5 KiB
Python
Executable File

import logging
from sqlalchemy.sql import func
from app.reports import reports
from app import db
from app.common.responses import success_response
from app.classes.customer import Customer_Customer
from app.classes.delivery import Delivery_Delivery
logger = logging.getLogger(__name__)
@reports.route("/oil/total", methods=["GET"])
def oil_total_gallons():
logger.info("GET /reports/oil/total - Calculating total oil delivered")
total_oil = db.session\
.query(func.sum(Delivery_Delivery.gallons_delivered))\
.group_by(Delivery_Delivery.id)\
.all()
return success_response({"oil": total_oil})
@reports.route("/customers/list", methods=["GET"])
def customer_list():
"""
Retrieve a list of customers with selected fields for printing.
Returns account number, first name, last name, address, town, and phone number.
Ordered by last name from A to Z.
"""
logger.info("GET /reports/customers/list - Fetching customer list for reports")
customers = db.session.query(Customer_Customer).order_by(Customer_Customer.customer_last_name.asc()).all()
customer_data = [
{
"account_number": customer.account_number,
"first_name": customer.customer_first_name,
"last_name": customer.customer_last_name,
"address": customer.customer_address,
"town": customer.customer_town,
"phone_number": customer.customer_phone_number
}
for customer in customers
]
return success_response({"customers": customer_data})