43 lines
1.3 KiB
Python
Executable File
43 lines
1.3 KiB
Python
Executable File
from flask import jsonify
|
|
from sqlalchemy.sql import func
|
|
from app.reports import reports
|
|
from app import db
|
|
|
|
from app.classes.customer import Customer_Customer
|
|
|
|
from app.classes.delivery import Delivery_Delivery
|
|
|
|
|
|
@reports.route("/oil/total", methods=["GET"])
|
|
def oil_total_gallons():
|
|
total_oil = db.session\
|
|
.query(func.sum(Delivery_Delivery.gallons_delivered))\
|
|
.group_by(Delivery_Delivery.id)\
|
|
.all()
|
|
|
|
return jsonify({"ok": True, "oil": total_oil }), 200
|
|
|
|
@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.
|
|
"""
|
|
|
|
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
|
|
]
|
|
response = jsonify({"ok": True, "customers": customer_data})
|
|
|
|
return response, 200
|