added hot water
This commit is contained in:
@@ -58,7 +58,7 @@ class Auto_Delivery(db.Model):
|
||||
tank_height = db.Column(db.VARCHAR(25))
|
||||
tank_size = db.Column(db.VARCHAR(25))
|
||||
house_factor = db.Column(db.DECIMAL(5, 2))
|
||||
|
||||
hot_water_summer = db.Column(db.Integer)
|
||||
#0 = waiting
|
||||
#1 = waiting for delivery
|
||||
auto_status = db.Column(db.INTEGER())
|
||||
|
||||
@@ -57,7 +57,7 @@ class Service_Parts(db.Model):
|
||||
oil_filter_2 = db.Column(db.VARCHAR(100))
|
||||
oil_nozzle = db.Column(db.VARCHAR(10))
|
||||
oil_nozzle_2 = db.Column(db.VARCHAR(10))
|
||||
|
||||
hot_water_tank = db.Column(db.INTEGER)
|
||||
|
||||
|
||||
class Service_Parts_schema(ma.SQLAlchemyAutoSchema):
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.classes.customer import \
|
||||
Customer_Description_schema,\
|
||||
Customer_Tank_Inspection_schema,\
|
||||
Customer_Tank_Inspection
|
||||
from app.classes.service import Service_Parts
|
||||
from app.classes.admin import Admin_Company
|
||||
from app.classes.auto import Auto_Delivery
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
@@ -468,6 +469,21 @@ def customer_automatic_status(customer_id):
|
||||
}), 200
|
||||
|
||||
|
||||
@customer.route("/automatic/deliveries", methods=["GET"])
|
||||
@login_required
|
||||
def get_all_automatic_deliveries():
|
||||
"""
|
||||
Get all automatic deliveries for the table.
|
||||
"""
|
||||
from app.classes.auto import Auto_Delivery, Auto_Delivery_schema
|
||||
try:
|
||||
deliveries = Auto_Delivery.query.all()
|
||||
schema = Auto_Delivery_schema(many=True)
|
||||
return jsonify(schema.dump(deliveries)), 200
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
|
||||
|
||||
@customer.route("/automatic/assign/<int:customer_id>", methods=["GET"])
|
||||
@@ -495,6 +511,11 @@ def customer_automatic_assignment(customer_id):
|
||||
.filter(Customer_Tank_Inspection.customer_id == customer_id)
|
||||
.first())
|
||||
|
||||
get_service_parts = (db.session
|
||||
.query(Service_Parts)
|
||||
.filter(Service_Parts.customer_id == customer_id)
|
||||
.first())
|
||||
|
||||
if get_customer.customer_automatic == 1:
|
||||
# customer becomes will call
|
||||
get_customer.customer_automatic = 0
|
||||
@@ -513,24 +534,26 @@ def customer_automatic_assignment(customer_id):
|
||||
'status': status
|
||||
}), 200
|
||||
|
||||
# customer becames an automatic
|
||||
# customer becomes an automatic
|
||||
if get_auto is None:
|
||||
hot_water_value = get_service_parts.hot_water_tank if get_service_parts and get_service_parts.hot_water_tank is not None else 0
|
||||
create_auto = Auto_Delivery(customer_id=customer_id,
|
||||
customer_full_name =get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
|
||||
customer_full_name=get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
|
||||
account_number=get_customer.account_number,
|
||||
customer_town=get_customer.customer_town,
|
||||
customer_state=get_customer.customer_state,
|
||||
customer_zip=get_customer.customer_zip,
|
||||
customer_address=get_customer.customer_address,
|
||||
last_fill = None,
|
||||
last_updated = None,
|
||||
estimated_gallons_left = 0,
|
||||
estimated_gallons_left_prev_day = 0,
|
||||
tank_height = 0,
|
||||
tank_size = get_customer_tank.tank_size,
|
||||
house_factor = 1,
|
||||
last_fill=None,
|
||||
last_updated=None,
|
||||
estimated_gallons_left=0,
|
||||
estimated_gallons_left_prev_day=0,
|
||||
tank_height=0,
|
||||
tank_size=get_customer_tank.tank_size,
|
||||
house_factor=1,
|
||||
auto_status=1,
|
||||
days_since_last_fill=0
|
||||
days_since_last_fill=0,
|
||||
hot_water_summer=hot_water_value
|
||||
)
|
||||
|
||||
db.session.add(create_auto)
|
||||
|
||||
@@ -7,7 +7,7 @@ from app.classes.service import (Service_Service,
|
||||
Service_Service_schema, Service_Parts, Service_Parts_schema,
|
||||
Service_Plans, Service_Plans_schema
|
||||
)
|
||||
|
||||
from app.classes.auto import Auto_Delivery
|
||||
|
||||
@service.route("/all", methods=["GET"])
|
||||
def get_all_service_calls():
|
||||
@@ -359,23 +359,35 @@ def get_service_parts(customer_id):
|
||||
else:
|
||||
return jsonify({
|
||||
"customer_id": customer_id, "oil_filter": "", "oil_filter_2": "",
|
||||
"oil_nozzle": "", "oil_nozzle_2": ""
|
||||
"oil_nozzle": "", "oil_nozzle_2": "", "hot_water_tank": 0
|
||||
}), 200
|
||||
|
||||
@service.route("/parts/update/<int:customer_id>", methods=["POST"])
|
||||
def update_service_parts(customer_id):
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"error": "No data provided"}), 400
|
||||
parts = Service_Parts.query.filter_by(customer_id=customer_id).first()
|
||||
if not parts:
|
||||
parts = Service_Parts(customer_id=customer_id)
|
||||
db.session.add(parts)
|
||||
parts.oil_filter = data.get('oil_filter', parts.oil_filter)
|
||||
parts.oil_filter_2 = data.get('oil_filter_2', parts.oil_filter_2)
|
||||
parts.oil_nozzle = data.get('oil_nozzle', parts.oil_nozzle)
|
||||
parts.oil_nozzle_2 = data.get('oil_nozzle_2', parts.oil_nozzle_2)
|
||||
try:
|
||||
data = request.get_json()
|
||||
|
||||
if not data:
|
||||
return jsonify({"error": "No data provided"}), 400
|
||||
|
||||
get_customer = db.session.query(Customer_Customer).filter(Customer_Customer.id == customer_id).first()
|
||||
parts = Service_Parts.query.filter_by(customer_id=customer_id).first()
|
||||
if not parts:
|
||||
parts = Service_Parts(customer_id=customer_id)
|
||||
db.session.add(parts)
|
||||
parts.oil_filter = data.get('oil_filter', parts.oil_filter)
|
||||
parts.oil_filter_2 = data.get('oil_filter_2', parts.oil_filter_2)
|
||||
parts.oil_nozzle = data.get('oil_nozzle', parts.oil_nozzle)
|
||||
parts.oil_nozzle_2 = data.get('oil_nozzle_2', parts.oil_nozzle_2)
|
||||
parts.hot_water_tank = data.get('hot_water_tank', parts.hot_water_tank if parts.hot_water_tank is not None else 0)
|
||||
|
||||
# Sync to Auto_Delivery if customer is automatic
|
||||
if get_customer and get_customer.customer_automatic == 1:
|
||||
get_auto = db.session.query(Auto_Delivery).filter(Auto_Delivery.customer_id == customer_id).first()
|
||||
if get_auto:
|
||||
get_auto.hot_water_summer = parts.hot_water_tank
|
||||
db.session.add(get_auto)
|
||||
|
||||
db.session.commit()
|
||||
return jsonify({"ok": True, "message": "Service parts updated successfully"}), 200
|
||||
except Exception as e:
|
||||
@@ -383,6 +395,7 @@ def update_service_parts(customer_id):
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
|
||||
@service.route("/payment/<int:service_id>/<int:payment_type>", methods=["PUT"])
|
||||
def process_service_payment(service_id, payment_type):
|
||||
service = db.session.query(Service_Service).filter(Service_Service.id == service_id).first()
|
||||
|
||||
Reference in New Issue
Block a user