Updated auto

This commit is contained in:
2024-07-02 16:56:18 -04:00
parent ca3ebf9f9b
commit 2a266eea23
4 changed files with 88 additions and 3 deletions

View File

@@ -109,6 +109,7 @@ def create_customer():
customer_address=customer_address,
customer_apt=customer_apt,
company_id=1,
)
db.session.add(new_customer)
@@ -117,7 +118,7 @@ def create_customer():
new_auto = Auto_Delivery(
customer_id = new_customer.id,
account_number = made_account_number,
customer_full_name = new_customer.response_customer_last_name + " " + new_customer.response_customer_first_name,
customer_full_name = new_customer.customer_last_name + " " + new_customer.customer_first_name,
last_fill = None,
last_updated = None,
estimated_gallons_left = None,
@@ -125,6 +126,9 @@ def create_customer():
tank_height = None,
tank_size = None,
house_factor = 1,
customer_town = new_customer.customer_town,
customer_state = new_customer.customer_state,
customer_zip = new_customer.customer_zip,
)
db.session.add(new_auto)
@@ -149,6 +153,8 @@ def edit_customer(customer_id):
.query(Customer_Customer)
.filter(Customer_Customer.id == customer_id)
.first())
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"]
@@ -228,3 +234,75 @@ def customer_count():
}), 200
@customer.route("/automatic/status/<int:customer_id>", methods=["GET"])
@login_required
def customer_automatic_status(customer_id):
"""
"""
get_customer = (db.session
.query(Customer_Customer)
.filter(Customer_Customer.id == customer_id)
.first())
if get_customer.customer_automatic == 1:
status = 1
if get_customer.customer_automatic == 0:
status = 0
return jsonify({
"ok": True,
'status': status
}), 200
@customer.route("/automatic/assign/<int:customer_id>", methods=["GET"])
@login_required
def customer_automatic_assignment(customer_id):
"""
"""
get_customer = (db.session
.query(Customer_Customer)
.filter(Customer_Customer.id == customer_id)
.first())
get_auto = (db.session
.query(Auto_Delivery)
.filter(Auto_Delivery.customer_id == customer_id)
.first())
if get_auto is None:
create_auto = Auto_Delivery(customer_id = customer_id,
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,
last_fill = datetime.utcnow(),
last_updated = None,
estimated_gallons_left = 0,
estimated_gallons_left_prev_day = None,
tank_height = None,
tank_size =None,
house_factor = None,
)
db.session.add(create_auto)
if get_customer.customer_automatic == 1:
get_customer.customer_automatic = 0
status = 0
db.session.add(get_customer)
else:
get_customer.customer_automatic = 1
status = 1
db.session.add(get_customer)
db.session.commit()
return jsonify({
"ok": True,
'status': status
}), 200