major update

This commit is contained in:
2024-10-17 17:01:24 -04:00
parent 8cee9dc5bf
commit 5649294be0
11 changed files with 354 additions and 91 deletions

View File

@@ -8,7 +8,9 @@ from app.classes.customer import \
Customer_Customer, \
Customer_Customer_schema,\
Customer_Description, \
Customer_Description_schema
Customer_Description_schema,\
Customer_Tank_Inspection_schema,\
Customer_Tank_Inspection
from app.classes.admin import Admin_Company
from app.classes.auto import Auto_Delivery
from app.classes.stats_customer import Stats_Customer
@@ -98,6 +100,38 @@ def get_a_customer_description(customer_id):
customer_schema = Customer_Description_schema(many=False)
return jsonify(customer_schema.dump(get_customer_description))
@customer.route("/tank/<int:customer_id>", methods=["GET"])
def get_a_customer_tank(customer_id):
"""
"""
get_customer_tank = (db.session
.query(Customer_Tank_Inspection)
.filter(Customer_Tank_Inspection.customer_id == customer_id)
.first())
if get_customer_tank is None:
new_tank = Customer_Tank_Inspection(
customer_id = customer_id,
last_tank_inspection = None,
tank_status = False,
outside_or_inside = True,
tank_size = 275,
)
db.session.add(new_tank)
db.session.commit()
get_customer_tank = (db.session
.query(Customer_Tank_Inspection)
.filter(Customer_Tank_Inspection.customer_id == customer_id)
.first())
customer_schema = Customer_Tank_Inspection_schema(many=False)
return jsonify(customer_schema.dump(get_customer_tank))
@customer.route("/create", methods=["POST"])
@login_required
def create_customer():
@@ -105,11 +139,22 @@ def create_customer():
"""
now = datetime.utcnow()
get_company = db.session.query(Admin_Company).filter(Admin_Company.id == 1).first()
last_customer = (db.session.query(Customer_Customer).order_by(Customer_Customer.id.desc()).first())
new_customer_id = last_customer.id + 1
if len(str(new_customer_id)) == 2:
new_customer_id = '000' + str(new_customer_id)
if len(str(new_customer_id)) == 3:
new_customer_id = '00' + str(new_customer_id)
if len(str(new_customer_id)) == 4:
new_customer_id = '0' + str(new_customer_id)
starter_digits = str(get_company.account_prefix) + '-' + str(new_customer_id)
starter_digits = str(get_company.account_prefix) + '-' + id_generator()
made_account_number = starter_digits
response_customer_last_name = request.json["customer_last_name"]
response_customer_first_name = request.json["customer_first_name"]
response_customer_town = request.json["customer_town"]
@@ -173,6 +218,15 @@ def create_customer():
)
db.session.add(new_description)
new_tank = Customer_Tank_Inspection(
customer_id = new_customer.id,
last_tank_inspection=None,
tank_status = False,
outside_or_inside = True,
tank_size=275,
)
db.session.add(new_tank)
new_auto = Auto_Delivery(
customer_id = new_customer.id,
account_number = made_account_number,
@@ -202,6 +256,63 @@ def create_customer():
},
}), 200
@customer.route("/edit/tank/<int:customer_id>", methods=["PUT"])
@login_required
def edit_customer_tank(customer_id):
"""
"""
get_customer = (db.session
.query(Customer_Customer)
.filter(Customer_Customer.id == customer_id)
.first())
get_customer_description = (db.session
.query(Customer_Description)
.filter(Customer_Description.customer_id == customer_id)
.first())
get_customer_tank = (db.session
.query(Customer_Tank_Inspection)
.filter(Customer_Tank_Inspection.customer_id == customer_id)
.first())
response_tank_status = request.json["tank_status"]
if response_tank_status == 'true':
get_customer_tank.tank_status = True
elif response_tank_status == 'false':
get_customer_tank.outside_or_inside = False
else:
pass
response_outside_or_inside = request.json["outside_or_inside"]
if response_outside_or_inside == 'true':
get_customer_tank.outside_or_inside = True
elif response_outside_or_inside == 'false':
get_customer_tank.outside_or_inside = False
else:
pass
response_last_tank_inspection = request.json["last_tank_inspection"]
response_tank_size = request.json["tank_size"]
response_customer_fill_location = request.json["fill_location"]
get_customer_tank.last_tank_inspection = response_last_tank_inspection
get_customer_tank.tank_size = response_tank_size
get_customer_description.fill_location = response_customer_fill_location
db.session.add(get_customer_description)
db.session.add(get_customer)
db.session.commit()
return jsonify({
"ok": True,
}), 200
@customer.route("/edit/<int:customer_id>", methods=["PUT"])
@login_required
@@ -229,7 +340,7 @@ def edit_customer(customer_id):
response_customer_description = request.json["customer_description"]
response_customer_fill_location = request.json["customer_fill_location"]
@@ -265,7 +376,7 @@ def edit_customer(customer_id):
auto = 0
if get_customer_description is not None:
get_customer_description.description = response_customer_description
get_customer_description.fill_location = response_customer_fill_location
db.session.add(get_customer_description)
@@ -360,40 +471,6 @@ def customer_automatic_status(customer_id):
}), 200
@customer.route("/description/<int:customer_id>", methods=["GET"])
@login_required
def customer_description(customer_id):
"""
"""
get_customer = (db.session
.query(Customer_Customer)
.filter(Customer_Customer.id == customer_id)
.first())
get_customer_description = (db.session
.query(Customer_Description)
.filter(Customer_Description.customer_id == customer_id)
.first())
if get_customer_description is None:
new_description = Customer_Description(
customer_id = get_customer.id,
account_number = get_customer.account_number,
description = None,
fill_location=None,
company_id=1,
)
db.session.add(new_description)
db.session.commit()
get_customer_description = (db.session
.query(Customer_Description)
.filter(Customer_Description.customer_id == customer_id)
.first())
customer_schema = Customer_Description_schema(many=False)
return jsonify(customer_schema.dump(get_customer_description))
@customer.route("/automatic/assign/<int:customer_id>", methods=["GET"])