small fixes

This commit is contained in:
2024-12-23 18:10:18 -05:00
parent 86ec25a499
commit e6f85ff014
4 changed files with 152 additions and 18 deletions

View File

@@ -25,6 +25,8 @@ class Query_StateList(db.Model):
text = db.Column(db.VARCHAR(140)) text = db.Column(db.VARCHAR(140))
class Query_StateList_Schema(ma.SQLAlchemyAutoSchema): class Query_StateList_Schema(ma.SQLAlchemyAutoSchema):
class Meta: class Meta:
model = Query_StateList model = Query_StateList
@@ -33,6 +35,22 @@ class Query_StateList_Schema(ma.SQLAlchemyAutoSchema):
value = ma.auto_field() value = ma.auto_field()
class Query_TownList(db.Model):
__tablename__ = 'query_town_list'
__table_args__ = {"schema": "public"}
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
value = db.Column(db.INTEGER)
text = db.Column(db.VARCHAR(140))
class Query_TownList_Schema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Query_TownList
id = ma.auto_field()
text = ma.auto_field()
value = ma.auto_field()
class Query_CustomerTypeList(db.Model): class Query_CustomerTypeList(db.Model):
__tablename__ = 'query_customer_type_list' __tablename__ = 'query_customer_type_list'
__table_args__ = {"schema": "public"} __table_args__ = {"schema": "public"}

View File

@@ -183,21 +183,57 @@ def create_customer():
the_state = 'MA' the_state = 'MA'
elif response_customer_state == 1: elif response_customer_state == 1:
the_state = 'RI' the_state = 'RI'
elif response_customer_state == 1: elif response_customer_state == 2:
the_state = 'NH' the_state = 'NH'
else: else:
the_state = 'MA' the_state = 'MA'
if response_customer_town == 0:
the_town = 'Auburn'
elif response_customer_state == 1:
the_town = 'Charlton'
elif response_customer_state == 2:
the_town = 'Cherry Valley'
elif response_customer_state == 3:
the_town = 'Dudley'
elif response_customer_state == 4:
the_town = 'Grafton'
elif response_customer_state == 5:
the_town = 'Leicester'
elif response_customer_state == 6:
the_town = 'Millbury'
elif response_customer_state == 7:
the_town = 'N Oxford'
elif response_customer_state == 8:
the_town = 'Oxford'
elif response_customer_state == 9:
the_town = 'Rochdale'
elif response_customer_state == 10:
the_town = 'Shrewsbury'
elif response_customer_state == 11:
the_town = 'Southbridge'
elif response_customer_state == 12:
the_town = 'Spencer'
elif response_customer_state == 13:
the_town = 'Sturbridge'
elif response_customer_state == 14:
the_town = 'Webster'
elif response_customer_state == 15:
the_town = 'Worcester'
else:
the_town = 'NA'
geolocator = Nominatim(user_agent="auburnoil") geolocator = Nominatim(user_agent="auburnoil")
address_string = customer_address + ' ' + response_customer_town + the_state + response_customer_zip address_string = customer_address + ' ' + response_customer_town+ ' ' + the_state
try: try:
location = geolocator.geocode(address_string) location = geolocator.geocode(address_string)
user_lat =location.latitude user_lat =location.latitude
user_long = location.longitude user_long = location.longitude
cor_ad = True cor_ad = True
except: except:
user_lat =location.latitude user_lat =None
user_long = location.longitude user_long = None
cor_ad = False cor_ad = False
new_customer = Customer_Customer( new_customer = Customer_Customer(
@@ -437,7 +473,10 @@ def customer_automatic_assignment(customer_id):
.filter(Card_Card.main_card == True) .filter(Card_Card.main_card == True)
.first()) .first())
get_customer_tank = (db.session
.query(Customer_Tank_Inspection)
.filter(Customer_Tank_Inspection.customer_id == customer_id)
.first())
if get_customer.customer_automatic == 1: if get_customer.customer_automatic == 1:
# customer becomes will call # customer becomes will call
get_customer.customer_automatic = 0 get_customer.customer_automatic = 0
@@ -470,13 +509,15 @@ def customer_automatic_assignment(customer_id):
estimated_gallons_left = 0, estimated_gallons_left = 0,
estimated_gallons_left_prev_day = 0, estimated_gallons_left_prev_day = 0,
tank_height = 0, tank_height = 0,
tank_size =275, tank_size = get_customer_tank.tank_size,
house_factor = 1, house_factor = 1,
auto_status=1, auto_status=1,
days_since_last_fill=0 days_since_last_fill=0
) )
db.session.add(create_auto) db.session.add(create_auto)
get_customer.customer_automatic = 1 get_customer.customer_automatic = 1
db.session.add(get_customer) db.session.add(get_customer)

View File

@@ -489,8 +489,13 @@ def edit_a_delivery(delivery_id):
.filter(Customer_Customer.id == get_delivery.customer_id) \ .filter(Customer_Customer.id == get_delivery.customer_id) \
.first() .first()
get_today_price = db.session\
.query(Pricing_Oil_Oil)\
.order_by(Pricing_Oil_Oil.id.desc())\
.first()
if not get_delivery: if not get_delivery:
return jsonify({"ok": False}), 200 return jsonify({"error": False}), 200
else: else:
gallons_ordered = request.json["gallons_ordered"] gallons_ordered = request.json["gallons_ordered"]
delivery_status = request.json["delivery_status"] delivery_status = request.json["delivery_status"]
@@ -499,6 +504,7 @@ def edit_a_delivery(delivery_id):
customer_wants_fill = request.json["customer_asked_for_fill"] customer_wants_fill = request.json["customer_asked_for_fill"]
card_payment = request.json["credit"] card_payment = request.json["credit"]
cash_payment = request.json["cash"] cash_payment = request.json["cash"]
emergency_info = request.json["emergency"]
dispatcher_notes = request.json["dispatcher_notes_taken"] dispatcher_notes = request.json["dispatcher_notes_taken"]
delivery_driver_id = request.json["driver_employee_id"] delivery_driver_id = request.json["driver_employee_id"]
@@ -561,6 +567,7 @@ def edit_a_delivery(delivery_id):
if customer_wants_fill is True: if customer_wants_fill is True:
customer_wants_fill = 1 customer_wants_fill = 1
gallons_ordered = 250
else: else:
customer_wants_fill = 0 customer_wants_fill = 0
@@ -570,13 +577,42 @@ def edit_a_delivery(delivery_id):
else: else:
same_day_info = 0 same_day_info = 0
if emergency_info is True:
emergency_asked = 1
else:
emergency_asked = 0
prime_info = request.json["prime"] prime_info = request.json["prime"]
if prime_info is True: if prime_info is True:
prime_info = 1 prime_info = 1
else: else:
prime_info = 0 prime_info = 0
dispatcher_notes # Pricing
if customer_wants_fill == 1:
# Fill
precharge_amount = (250 * get_today_price.price_for_customer)
else:
# Gallons
precharge_amount = int(gallons_ordered) * get_today_price.price_for_customer
# if prime/emergency/sameday
if same_day_info == 1 and prime_info == 0:
total_precharge_amount = precharge_amount + get_today_price.price_same_day
elif prime_info == 1 and same_day_info == 0:
total_precharge_amount = precharge_amount + get_today_price.price_prime
elif emergency_asked == 1:
total_precharge_amount = precharge_amount + get_today_price.price_emergency
else:
total_precharge_amount = precharge_amount + get_today_price.price_prime + get_today_price.price_same_day
get_delivery.dispatcher_notes = dispatcher_notes get_delivery.dispatcher_notes = dispatcher_notes
get_delivery.delivery_status = delivery_status get_delivery.delivery_status = delivery_status
get_delivery.gallons_ordered = gallons_ordered get_delivery.gallons_ordered = gallons_ordered
@@ -594,6 +630,9 @@ def edit_a_delivery(delivery_id):
get_delivery.promo_id = promo_id_get_delivery get_delivery.promo_id = promo_id_get_delivery
get_delivery.promo_money_discount = promo_money_discount_get_delivery get_delivery.promo_money_discount = promo_money_discount_get_delivery
get_delivery.pre_charge_amount = total_precharge_amount
get_delivery.total_price = precharge_amount
db.session.add(get_delivery) db.session.add(get_delivery)
db.session.commit() db.session.commit()
@@ -711,6 +750,7 @@ def create_a_delivery(user_id):
gallons_ordered = 250 gallons_ordered = 250
else: else:
customer_fill_up = 0 customer_fill_up = 0
gallons_ordered = request.json["gallons_ordered"]
if emergency_info is True: if emergency_info is True:
emergency_asked = 1 emergency_asked = 1
@@ -731,6 +771,7 @@ def create_a_delivery(user_id):
customer_filled_name = get_customer.customer_first_name + ' ' + get_customer.customer_last_name customer_filled_name = get_customer.customer_first_name + ' ' + get_customer.customer_last_name
now = datetime.utcnow() now = datetime.utcnow()
# Pricing # Pricing
if customer_fill_up == 1: if customer_fill_up == 1:
@@ -788,7 +829,6 @@ def create_a_delivery(user_id):
driver_last_name=driver_l_name, driver_last_name=driver_l_name,
driver_first_name=driver_f_name, driver_first_name=driver_f_name,
driver_employee_id=driver_emp_id, driver_employee_id=driver_emp_id,
promo_id=promo_id_get_delivery, promo_id=promo_id_get_delivery,
promo_money_discount=promo_money_discount_get_delivery promo_money_discount=promo_money_discount_get_delivery

View File

@@ -3,8 +3,20 @@ import decimal
from datetime import datetime from datetime import datetime
from app.promo import promo from app.promo import promo
from app import db from app import db
from app.classes.promo import Promo_Promo, Promo_Promo_schema from app.classes.promo import (
Promo_Promo,
Promo_Promo_schema)
from app.classes.delivery import (Delivery_Delivery,
Delivery_Delivery_schema,
Delivery_Notes_Driver,
)
def convert_to_decimal(text):
try:
number = float(text)
return round(number, 2)
except ValueError:
return "0"
@promo.route("/<int:promo_id>", methods=["GET"]) @promo.route("/<int:promo_id>", methods=["GET"])
@@ -19,6 +31,24 @@ def get_promo(promo_id):
return jsonify(query_schema.dump(get_promo_data)) return jsonify(query_schema.dump(get_promo_data))
@promo.route("/promoprice/<int:delivery_id>", methods=["GET"])
def get_promo_price(delivery_id):
"""
"""
get_delivery = (db.session
.query(Delivery_Delivery)
.filter(Delivery_Delivery.id == delivery_id)
.first())
price = get_delivery.customer_price - get_delivery.promo_money_discount
price = convert_to_decimal(price)
return jsonify({
"ok": True,
"price": price,
}), 200
@promo.route("/all", methods=["GET"]) @promo.route("/all", methods=["GET"])
def get_all_promo(): def get_all_promo():
""" """
@@ -58,9 +88,11 @@ def create_promo():
text_on_ticket = request.json["text_on_ticket"] text_on_ticket = request.json["text_on_ticket"]
# see if it exists # see if it exists
amount_off = convert_to_decimal(money_off_delivery)
new_promo = Promo_Promo( new_promo = Promo_Promo(
name_of_promotion = name_of_promotion, name_of_promotion = name_of_promotion,
money_off_delivery = float(money_off_delivery), money_off_delivery = amount_off,
description = description, description = description,
date_created = date_created, date_created = date_created,
text_on_ticket=text_on_ticket text_on_ticket=text_on_ticket
@@ -89,10 +121,13 @@ def edit_promo(promo_id):
money_off_delivery = request.json["money_off_delivery"] money_off_delivery = request.json["money_off_delivery"]
description = request.json["description"] description = request.json["description"]
amount_off = convert_to_decimal(money_off_delivery)
get_promo_data.text_on_ticket = text_on_ticket get_promo_data.text_on_ticket = text_on_ticket
get_promo_data.description = description get_promo_data.description = description
get_promo_data.name_of_promotion = name_of_promotion get_promo_data.name_of_promotion = name_of_promotion
get_promo_data.money_off_delivery = float(money_off_delivery) get_promo_data.money_off_delivery = amount_off
db.session.add(get_promo_data) db.session.add(get_promo_data)
db.session.commit() db.session.commit()