Added automatic stuff
This commit is contained in:
@@ -49,6 +49,10 @@ class Auto_Delivery(db.Model):
|
||||
tank_size = db.Column(db.VARCHAR(25))
|
||||
house_factor = db.Column(db.DECIMAL(5, 2))
|
||||
|
||||
#0 = waiting
|
||||
#1 = waiting for delivery
|
||||
auto_status = db.Column(db.INTEGER())
|
||||
|
||||
class Auto_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Auto_Delivery
|
||||
|
||||
@@ -129,6 +129,7 @@ def create_customer():
|
||||
customer_town = new_customer.customer_town,
|
||||
customer_state = new_customer.customer_state,
|
||||
customer_zip = new_customer.customer_zip,
|
||||
auto_status=0
|
||||
)
|
||||
|
||||
db.session.add(new_auto)
|
||||
@@ -162,13 +163,44 @@ def edit_customer(customer_id):
|
||||
response_customer_zip = request.json["customer_zip"]
|
||||
response_customer_phone_number = request.json["customer_phone_number"]
|
||||
response_customer_email = request.json["customer_email"]
|
||||
response_customer_automatic = request.json["customer_automatic"]
|
||||
response_customer_home_type = request.json["customer_home_type"]
|
||||
response_customer_address = request.json["customer_address"]
|
||||
response_customer_automatic = request.json["customer_automatic"]
|
||||
|
||||
|
||||
if response_customer_automatic is True:
|
||||
get_auto = (db.session
|
||||
.query(Auto_Delivery)
|
||||
.filter(Auto_Delivery.customer_id == customer_id)
|
||||
.first())
|
||||
|
||||
auto = 1
|
||||
# customer becames an automatic
|
||||
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,
|
||||
customer_address=get_customer.customer_address,
|
||||
last_fill = datetime.utcnow(),
|
||||
last_updated = None,
|
||||
estimated_gallons_left = 0,
|
||||
estimated_gallons_left_prev_day = 0,
|
||||
tank_height = 0,
|
||||
tank_size =275,
|
||||
house_factor = 1,
|
||||
auto_status=0
|
||||
)
|
||||
db.session.add(create_auto)
|
||||
|
||||
else:
|
||||
auto = 0
|
||||
|
||||
|
||||
get_customer.customer_address = response_customer_address
|
||||
get_customer.customer_home_type = response_customer_home_type
|
||||
get_customer.customer_automatic = response_customer_automatic
|
||||
get_customer.customer_phone_number = response_customer_phone_number
|
||||
get_customer.customer_last_name = response_customer_last_name
|
||||
get_customer.customer_first_name = response_customer_first_name
|
||||
@@ -176,6 +208,7 @@ def edit_customer(customer_id):
|
||||
get_customer.customer_state = response_customer_state
|
||||
get_customer.customer_zip = response_customer_zip
|
||||
get_customer.customer_email = response_customer_email
|
||||
get_customer.customer_automatic = auto
|
||||
|
||||
db.session.add(get_customer)
|
||||
db.session.commit()
|
||||
@@ -298,6 +331,7 @@ def customer_automatic_assignment(customer_id):
|
||||
tank_height = 0,
|
||||
tank_size =275,
|
||||
house_factor = 1,
|
||||
auto_status=0
|
||||
|
||||
)
|
||||
db.session.add(create_auto)
|
||||
|
||||
@@ -578,15 +578,11 @@ def create_a_delivery(user_id):
|
||||
# Pricing
|
||||
if customer_fill_up == 1:
|
||||
precharge_amount = (250 * get_today_price.price_for_customer)
|
||||
print(precharge_amount)
|
||||
else:
|
||||
precharge_amount = int(gallons_ordered) * get_today_price.price_for_customer
|
||||
|
||||
if same_day_asked == 1 and prime_asked == 0:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_same_day
|
||||
print(total_precharge_amount)
|
||||
print(precharge_amount)
|
||||
print(get_today_price.price_same_day)
|
||||
|
||||
elif prime_asked == 1 and same_day_asked == 0:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_prime
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from flask import request, jsonify
|
||||
from datetime import datetime
|
||||
from app.delivery_data import delivery_data
|
||||
from app import db
|
||||
from app.classes.customer import Customer_Customer
|
||||
@@ -6,7 +7,7 @@ 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, Stats_Employee_Office
|
||||
|
||||
from app.classes.auto import Auto_Delivery
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +20,8 @@ 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) \
|
||||
@@ -38,6 +41,40 @@ def office_finalize_delivery(delivery_id):
|
||||
else:
|
||||
card_payment_id = None
|
||||
|
||||
if get_delivery.automatic == 1:
|
||||
|
||||
get_auto_delivery = (db.session
|
||||
.query(Auto_Delivery)
|
||||
.filter(Auto_Delivery.customer_id == get_delivery.customer_id)
|
||||
.first())
|
||||
|
||||
customer_home_factor = get_auto_delivery.house_factor
|
||||
|
||||
if gallons_delivered == 150:
|
||||
get_auto_delivery.house_factor = customer_home_factor
|
||||
elif 200.01 >= gallons_delivered:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1
|
||||
elif 170.01 <= gallons_delivered <= 200:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1.5
|
||||
elif 150.01 <= gallons_delivered <= 199:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1.25
|
||||
elif 120.01 <= gallons_delivered <= 150:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .25
|
||||
elif 90.01 <= gallons_delivered <= 120:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .50
|
||||
elif 0.01 <= gallons_delivered <= 90:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .75
|
||||
else:
|
||||
get_auto_delivery.house_factor = customer_home_factor
|
||||
|
||||
|
||||
get_auto_delivery.tank_height = 'Full'
|
||||
get_auto_delivery.last_fill = now
|
||||
get_auto_delivery.estimated_gallons_left = 240
|
||||
get_auto_delivery.estimated_gallons_left_prev_day = 240
|
||||
|
||||
db.session.add(get_auto_delivery)
|
||||
|
||||
|
||||
if card_payment_id is not None:
|
||||
get_card = (db.session
|
||||
@@ -100,13 +137,15 @@ def driver_finalize_delivery(delivery_id):
|
||||
"""
|
||||
Finalizes a delivery from office
|
||||
"""
|
||||
print(request.json)
|
||||
|
||||
now = datetime.utcnow()
|
||||
|
||||
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.id == delivery_id)
|
||||
.first())
|
||||
|
||||
print(get_delivery.id)
|
||||
get_stats = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
@@ -124,18 +163,24 @@ def driver_finalize_delivery(delivery_id):
|
||||
.filter(Employee_Employee.id == delivery_driver_id)
|
||||
.first())
|
||||
|
||||
|
||||
if get_delivery.automatic == 0:
|
||||
customer_filled = request.json["customer_filled"]
|
||||
if customer_filled is True:
|
||||
customer_filled = 1
|
||||
else:
|
||||
customer_filled = 0
|
||||
else:
|
||||
customer_filled = 1
|
||||
|
||||
if get_delivery.automatic == 0:
|
||||
if request.json["cash_amount"]:
|
||||
cash_amount = request.json["cash_amount"]
|
||||
else:
|
||||
cash_amount = None
|
||||
else:
|
||||
cash_amount = None
|
||||
|
||||
if get_delivery.automatic == 0:
|
||||
prime_info = request.json["prime"]
|
||||
if prime_info is True:
|
||||
prime_info = 1
|
||||
@@ -144,6 +189,46 @@ def driver_finalize_delivery(delivery_id):
|
||||
get_stats.total_primes = newprimes
|
||||
else:
|
||||
prime_info = 0
|
||||
else:
|
||||
prime_info = 0
|
||||
|
||||
|
||||
## AUTOMATIC
|
||||
|
||||
if get_delivery.automatic == 1:
|
||||
|
||||
get_auto_delivery = (db.session
|
||||
.query(Auto_Delivery)
|
||||
.filter(Auto_Delivery.customer_id == get_delivery.customer_id)
|
||||
.first())
|
||||
|
||||
customer_home_factor = get_auto_delivery.house_factor
|
||||
|
||||
if gallons_delivered == 150:
|
||||
get_auto_delivery.house_factor = customer_home_factor
|
||||
elif 200.01 >= gallons_delivered:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1
|
||||
elif 170.01 <= gallons_delivered <= 200:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1.5
|
||||
elif 150.01 <= gallons_delivered <= 199:
|
||||
get_auto_delivery.house_factor = customer_home_factor + 1.25
|
||||
elif 120.01 <= gallons_delivered <= 150:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .25
|
||||
elif 90.01 <= gallons_delivered <= 120:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .50
|
||||
elif 0.01 <= gallons_delivered <= 90:
|
||||
get_auto_delivery.house_factor = customer_home_factor - .75
|
||||
else:
|
||||
get_auto_delivery.house_factor = customer_home_factor
|
||||
|
||||
|
||||
get_auto_delivery.tank_height = 'Full'
|
||||
get_auto_delivery.last_fill = now
|
||||
get_auto_delivery.estimated_gallons_left = 240
|
||||
get_auto_delivery.estimated_gallons_left_prev_day = 240
|
||||
|
||||
db.session.add(get_auto_delivery)
|
||||
|
||||
|
||||
get_delivery.gallons_delivered = gallons_delivered
|
||||
|
||||
@@ -166,14 +251,18 @@ def driver_finalize_delivery(delivery_id):
|
||||
|
||||
|
||||
# update delivery status to delivered
|
||||
if get_delivery.automatic == 0:
|
||||
if get_delivery.payment_type == 0:
|
||||
get_delivery.delivery_status = 10
|
||||
else:
|
||||
#office needs to confirm credit card
|
||||
get_delivery.delivery_status = 1
|
||||
else:
|
||||
get_delivery.delivery_status = 1
|
||||
|
||||
db.session.add(get_stats)
|
||||
db.session.add(get_delivery)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
|
||||
@@ -6,24 +6,46 @@ from app.classes.cards import Card_Card, Card_Card_schema
|
||||
from flask_login import current_user
|
||||
|
||||
|
||||
def set_card_main(user_id):
|
||||
def set_card_main(user_id, card_id):
|
||||
"""
|
||||
updates a card of a user
|
||||
"""
|
||||
get_card_count = db.session \
|
||||
.query(Card_Card) \
|
||||
.filter(Card_Card.user_id == user_id) \
|
||||
get_card_count = (
|
||||
db.session
|
||||
.query(Card_Card)
|
||||
.filter(Card_Card.user_id == user_id)
|
||||
.count()
|
||||
if get_card_count > 0:
|
||||
get_old_card = db.session \
|
||||
.query(Card_Card) \
|
||||
.filter(Card_Card.main_card == True) \
|
||||
.filter(Card_Card.user_id == user_id) \
|
||||
)
|
||||
|
||||
get_card = (
|
||||
db.session
|
||||
.query(Card_Card)
|
||||
.filter(Card_Card.user_id == user_id)
|
||||
.filter(Card_Card.id == card_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
if get_card_count > 0:
|
||||
get_old_card = (
|
||||
db.session
|
||||
.query(Card_Card)
|
||||
.filter(Card_Card.main_card == True)
|
||||
.filter(Card_Card.user_id == user_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
get_old_card.main_card = False
|
||||
get_card.main_card = True
|
||||
|
||||
db.session.add(get_old_card)
|
||||
db.session.commit()
|
||||
else:
|
||||
|
||||
|
||||
get_card.main_card = True
|
||||
|
||||
db.session.add(get_card)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@payment.route("/cards/<int:user_id>", methods=["GET"])
|
||||
@@ -105,9 +127,9 @@ def create_user_card(user_id):
|
||||
accepted_or_declined=None,
|
||||
main_card=main_card,
|
||||
)
|
||||
print(main_card)
|
||||
db.session.flush()
|
||||
if main_card is True:
|
||||
set_card_main(user_id=get_customer.id)
|
||||
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
||||
db.session.add(create_new_card)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user