added checks emergency fixed bugs
This commit is contained in:
@@ -11,9 +11,16 @@ from app.classes.customer import \
|
||||
Customer_Description_schema
|
||||
from app.classes.admin import Admin_Company
|
||||
from app.classes.auto import Auto_Delivery
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
import string
|
||||
import random
|
||||
|
||||
|
||||
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
|
||||
|
||||
@customer.route("/all", methods=["GET"])
|
||||
@login_required
|
||||
def all_customers_around():
|
||||
@@ -51,7 +58,6 @@ def all_customers(page):
|
||||
@customer.route("/<int:customer_id>", methods=["GET"])
|
||||
def get_a_customer(customer_id):
|
||||
"""
|
||||
Checks auth token to ensure user is authenticated
|
||||
"""
|
||||
get_customer = (db.session
|
||||
.query(Customer_Customer)
|
||||
@@ -60,8 +66,37 @@ def get_a_customer(customer_id):
|
||||
customer_schema = Customer_Customer_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer))
|
||||
|
||||
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
@customer.route("/description/<int:customer_id>", methods=["GET"])
|
||||
def get_a_customer_description(customer_id):
|
||||
"""
|
||||
|
||||
"""
|
||||
get_customer_description = (db.session
|
||||
.query(Customer_Description)
|
||||
.filter(Customer_Description.customer_id == customer_id)
|
||||
.first())
|
||||
if get_customer_description is None:
|
||||
get_customer = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.id == customer_id)
|
||||
.first())
|
||||
|
||||
new_description = Customer_Description(
|
||||
customer_id = customer_id,
|
||||
account_number = get_customer.account_number,
|
||||
company_id = get_customer.company_id,
|
||||
fill_location = None,
|
||||
description = None,
|
||||
)
|
||||
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("/create", methods=["POST"])
|
||||
@login_required
|
||||
@@ -115,7 +150,20 @@ def create_customer():
|
||||
)
|
||||
db.session.add(new_customer)
|
||||
db.session.flush()
|
||||
|
||||
|
||||
create_stats_customer = Stats_Customer(
|
||||
customer_id = new_customer.id,
|
||||
total_calls = 1,
|
||||
service_calls_total = 0,
|
||||
service_calls_total_spent = 0,
|
||||
service_calls_total_profit = 0,
|
||||
oil_deliveries = 0,
|
||||
oil_total_gallons = 0,
|
||||
oil_total_spent = 0,
|
||||
oil_total_profit = 0,
|
||||
)
|
||||
db.session.add(create_stats_customer)
|
||||
|
||||
new_description = Customer_Description(
|
||||
customer_id = new_customer.id,
|
||||
account_number = made_account_number,
|
||||
@@ -125,7 +173,6 @@ def create_customer():
|
||||
)
|
||||
db.session.add(new_description)
|
||||
|
||||
|
||||
new_auto = Auto_Delivery(
|
||||
customer_id = new_customer.id,
|
||||
account_number = made_account_number,
|
||||
|
||||
Reference in New Issue
Block a user