From 2a266eea239183333aa368324b1381787b9d2648 Mon Sep 17 00:00:00 2001 From: Anekdotin Date: Tue, 2 Jul 2024 16:56:18 -0400 Subject: [PATCH] Updated auto --- app/classes/auto.py | 7 +++- app/classes/customer.py | 2 +- app/customer/views.py | 80 ++++++++++++++++++++++++++++++++++++++++- app/delivery/views.py | 2 ++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/app/classes/auto.py b/app/classes/auto.py index add4c92..eb04511 100755 --- a/app/classes/auto.py +++ b/app/classes/auto.py @@ -35,7 +35,12 @@ class Auto_Delivery(db.Model): autoincrement=True, unique=False) customer_id = db.Column(db.INTEGER()) - customer_full_name = db.Column(db.DECIMAL(5, 2)) + account_number = db.Column(db.VARCHAR(25)) + customer_town = db.Column(db.VARCHAR(140)) + customer_state = db.Column(db.Integer) + customer_address = db.Column(db.VARCHAR(1000)) + customer_zip = db.Column(db.VARCHAR(25)) + customer_full_name = db.Column(db.VARCHAR(250)) last_fill = db.Column(db.TIMESTAMP()) last_updated = db.Column(db.TIMESTAMP()) estimated_gallons_left = db.Column(db.INTEGER()) diff --git a/app/classes/customer.py b/app/classes/customer.py index 6e6e1c7..d591634 100755 --- a/app/classes/customer.py +++ b/app/classes/customer.py @@ -1,4 +1,4 @@ - +# from app import db, ma, login_manager from datetime import datetime diff --git a/app/customer/views.py b/app/customer/views.py index 61702fe..9f51113 100755 --- a/app/customer/views.py +++ b/app/customer/views.py @@ -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/", 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/", 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 + diff --git a/app/delivery/views.py b/app/delivery/views.py index 52b580c..a2f9d0d 100755 --- a/app/delivery/views.py +++ b/app/delivery/views.py @@ -46,6 +46,8 @@ def get_a_delivery(delivery_id): }, }), 200 + + @delivery.route("/past1/", methods=["GET"]) def get_customer_past_delivery1(customer_id):