added checks emergency fixed bugs
This commit is contained in:
@@ -3,13 +3,13 @@ from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from app.delivery_data import delivery_data
|
||||
from app import db
|
||||
from app.classes.customer import Customer_Customer
|
||||
from app.classes.customer import Customer_Customer, Customer_Description
|
||||
from app.classes.delivery import Delivery_Delivery
|
||||
from app.classes.employee import Employee_Employee
|
||||
from app.classes.cards import Card_Card
|
||||
from app.classes.stats_employee import Stats_Employee_Oil
|
||||
from app.classes.auto import Auto_Delivery
|
||||
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
|
||||
@delivery_data.route("/finalize/<int:delivery_id>", methods=["PUT"])
|
||||
def office_finalize_delivery(delivery_id):
|
||||
@@ -20,7 +20,7 @@ def office_finalize_delivery(delivery_id):
|
||||
"""
|
||||
Finalizes a delivery from office
|
||||
"""
|
||||
|
||||
now = datetime.utcnow()
|
||||
get_delivery = db.session \
|
||||
.query(Delivery_Delivery) \
|
||||
.filter(Delivery_Delivery.id == delivery_id) \
|
||||
@@ -31,6 +31,24 @@ def office_finalize_delivery(delivery_id):
|
||||
.filter(Customer_Customer.id == get_delivery.customer_id) \
|
||||
.first()
|
||||
|
||||
get_customer_description = db.session \
|
||||
.query(Customer_Description) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
.first()
|
||||
if get_customer_description is None:
|
||||
new_customer_desc = Customer_Description(
|
||||
customer_id = get_customer.id,
|
||||
account_number =get_customer.account_number,
|
||||
company_id = get_customer.company_id,
|
||||
fill_location = None,
|
||||
description = None,
|
||||
)
|
||||
db.session.add(new_customer_desc)
|
||||
db.session.commit()
|
||||
get_customer_description = db.session \
|
||||
.query(Customer_Description) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
.first()
|
||||
delivery_driver_id = request.json["driver_employee_id"]
|
||||
if delivery_driver_id is None:
|
||||
delivery_driver_id = 2
|
||||
@@ -42,12 +60,36 @@ def office_finalize_delivery(delivery_id):
|
||||
.filter(Employee_Employee.id == delivery_driver_id)
|
||||
.first())
|
||||
|
||||
get_stats = (db.session
|
||||
get_stats_employee = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
|
||||
if get_stats is None:
|
||||
get_stats_customer = (db.session
|
||||
.query(Stats_Customer)
|
||||
.filter(Stats_Customer.customer_id == get_customer.id)
|
||||
.first())
|
||||
if get_stats_customer is None:
|
||||
create_stats_customer = Stats_Customer(
|
||||
customer_id = get_customer.id,
|
||||
total_calls = 1,
|
||||
service_calls_total = 0,
|
||||
service_calls_total_spent = 0,
|
||||
service_calls_total_profit = 0,
|
||||
oil_deliveries = 1,
|
||||
oil_total_gallons = 0,
|
||||
oil_total_spent = 0,
|
||||
oil_total_profit = 0,
|
||||
|
||||
)
|
||||
db.session.add(create_stats_customer)
|
||||
db.session.flush()
|
||||
get_stats_customer = (db.session
|
||||
.query(Stats_Customer)
|
||||
.filter(Stats_Customer.customer_id == get_customer.id)
|
||||
.first())
|
||||
|
||||
if get_stats_employee is None:
|
||||
create_stats = Stats_Employee_Oil(
|
||||
employee_id = get_delivery.driver_employee_id,
|
||||
total_deliveries = 0,
|
||||
@@ -58,8 +100,7 @@ def office_finalize_delivery(delivery_id):
|
||||
db.session.add(create_stats)
|
||||
db.session.flush()
|
||||
|
||||
|
||||
get_stats = (db.session
|
||||
get_stats_employee = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
@@ -83,9 +124,9 @@ def office_finalize_delivery(delivery_id):
|
||||
prime_info = request.json["prime"]
|
||||
if prime_info is True:
|
||||
prime_info = 1
|
||||
current_primes = get_stats.total_primes
|
||||
current_primes = get_stats_employee.total_primes
|
||||
newprimes = current_primes + 1
|
||||
get_stats.total_primes = newprimes
|
||||
get_stats_employee.total_primes = newprimes
|
||||
else:
|
||||
prime_info = 0
|
||||
|
||||
@@ -142,11 +183,17 @@ def office_finalize_delivery(delivery_id):
|
||||
else:
|
||||
emergency_info = 0
|
||||
|
||||
fill_location = request.json["fill_location"]
|
||||
|
||||
|
||||
|
||||
# update driver
|
||||
get_delivery.driver_last_name = get_driver.employee_last_name
|
||||
get_delivery.driver_first_name = get_driver.employee_first_name
|
||||
get_delivery.driver_employee_id = get_driver.id
|
||||
|
||||
|
||||
# update delivery
|
||||
get_delivery.when_delivered = now
|
||||
get_delivery.gallons_delivered = gallons_delivered
|
||||
get_delivery.prime = prime_info
|
||||
get_delivery.emergency = emergency_info
|
||||
@@ -157,15 +204,32 @@ def office_finalize_delivery(delivery_id):
|
||||
get_delivery.check_number = check_number
|
||||
get_delivery.delivery_status = 10
|
||||
|
||||
# update stats
|
||||
current_deliveres = get_stats.total_deliveries + 1
|
||||
get_stats.total_deliveries = current_deliveres
|
||||
# update stats employee
|
||||
current_deliveres = get_stats_employee.total_deliveries + 1
|
||||
get_stats_employee.total_deliveries = current_deliveres
|
||||
|
||||
current_gallons_delivered = Decimal(get_stats.total_gallons_delivered) + Decimal(gallons_delivered)
|
||||
get_stats.total_gallons_delivered = current_gallons_delivered
|
||||
current_gallons_delivered = Decimal(get_stats_employee.total_gallons_delivered) + Decimal(gallons_delivered)
|
||||
get_stats_employee.total_gallons_delivered = current_gallons_delivered
|
||||
|
||||
# update stats customer
|
||||
current_deliveres = int(get_stats_customer.oil_deliveries) + 1
|
||||
get_stats_customer.oil_deliveries = current_deliveres
|
||||
|
||||
new_gallons = Decimal(get_stats_customer.oil_total_gallons) + Decimal(gallons_delivered)
|
||||
get_stats_customer.oil_total_gallons = new_gallons
|
||||
|
||||
new_calls = int(get_stats_customer.total_calls) + 1
|
||||
get_stats_customer.total_calls = new_calls
|
||||
|
||||
|
||||
# update fill location
|
||||
get_customer_description.fill_location = fill_location
|
||||
|
||||
db.session.add(get_customer_description)
|
||||
db.session.add(get_stats_customer)
|
||||
db.session.add(get_stats_employee)
|
||||
db.session.add(get_delivery)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user