From e6f85ff0144d47d5c8a1ecf4542b05b3f5a0f443 Mon Sep 17 00:00:00 2001 From: Edwin Eames Date: Mon, 23 Dec 2024 18:10:18 -0500 Subject: [PATCH] small fixes --- app/classes/query.py | 18 ++++++++++++++ app/customer/views.py | 57 +++++++++++++++++++++++++++++++++++++------ app/delivery/views.py | 52 ++++++++++++++++++++++++++++++++++----- app/promo/views.py | 43 +++++++++++++++++++++++++++++--- 4 files changed, 152 insertions(+), 18 deletions(-) diff --git a/app/classes/query.py b/app/classes/query.py index d06c394..e947809 100755 --- a/app/classes/query.py +++ b/app/classes/query.py @@ -25,6 +25,8 @@ class Query_StateList(db.Model): text = db.Column(db.VARCHAR(140)) + + class Query_StateList_Schema(ma.SQLAlchemyAutoSchema): class Meta: model = Query_StateList @@ -33,6 +35,22 @@ class Query_StateList_Schema(ma.SQLAlchemyAutoSchema): 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): __tablename__ = 'query_customer_type_list' __table_args__ = {"schema": "public"} diff --git a/app/customer/views.py b/app/customer/views.py index 04fd7df..38cb446 100755 --- a/app/customer/views.py +++ b/app/customer/views.py @@ -183,21 +183,57 @@ def create_customer(): the_state = 'MA' elif response_customer_state == 1: the_state = 'RI' - elif response_customer_state == 1: + elif response_customer_state == 2: the_state = 'NH' else: 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") - address_string = customer_address + ' ' + response_customer_town + the_state + response_customer_zip + address_string = customer_address + ' ' + response_customer_town+ ' ' + the_state try: location = geolocator.geocode(address_string) user_lat =location.latitude user_long = location.longitude cor_ad = True except: - user_lat =location.latitude - user_long = location.longitude + user_lat =None + user_long = None cor_ad = False new_customer = Customer_Customer( @@ -437,7 +473,10 @@ def customer_automatic_assignment(customer_id): .filter(Card_Card.main_card == True) .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: # customer becomes will call get_customer.customer_automatic = 0 @@ -458,7 +497,7 @@ def customer_automatic_assignment(customer_id): # customer becames an automatic if get_auto is None: - create_auto = Auto_Delivery(customer_id = customer_id, + 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, @@ -470,13 +509,15 @@ def customer_automatic_assignment(customer_id): estimated_gallons_left = 0, estimated_gallons_left_prev_day = 0, tank_height = 0, - tank_size =275, + tank_size = get_customer_tank.tank_size, house_factor = 1, auto_status=1, days_since_last_fill=0 - ) + db.session.add(create_auto) + + get_customer.customer_automatic = 1 db.session.add(get_customer) diff --git a/app/delivery/views.py b/app/delivery/views.py index 085f9e7..f25b3c7 100755 --- a/app/delivery/views.py +++ b/app/delivery/views.py @@ -489,8 +489,13 @@ def edit_a_delivery(delivery_id): .filter(Customer_Customer.id == get_delivery.customer_id) \ .first() + get_today_price = db.session\ + .query(Pricing_Oil_Oil)\ + .order_by(Pricing_Oil_Oil.id.desc())\ + .first() + if not get_delivery: - return jsonify({"ok": False}), 200 + return jsonify({"error": False}), 200 else: gallons_ordered = request.json["gallons_ordered"] 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"] card_payment = request.json["credit"] cash_payment = request.json["cash"] + emergency_info = request.json["emergency"] dispatcher_notes = request.json["dispatcher_notes_taken"] delivery_driver_id = request.json["driver_employee_id"] @@ -561,6 +567,7 @@ def edit_a_delivery(delivery_id): if customer_wants_fill is True: customer_wants_fill = 1 + gallons_ordered = 250 else: customer_wants_fill = 0 @@ -570,13 +577,42 @@ def edit_a_delivery(delivery_id): else: same_day_info = 0 + if emergency_info is True: + emergency_asked = 1 + else: + emergency_asked = 0 + prime_info = request.json["prime"] if prime_info is True: prime_info = 1 else: 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.delivery_status = delivery_status get_delivery.gallons_ordered = gallons_ordered @@ -591,8 +627,11 @@ def edit_a_delivery(delivery_id): 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 - 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.pre_charge_amount = total_precharge_amount + get_delivery.total_price = precharge_amount db.session.add(get_delivery) db.session.commit() @@ -711,6 +750,7 @@ def create_a_delivery(user_id): gallons_ordered = 250 else: customer_fill_up = 0 + gallons_ordered = request.json["gallons_ordered"] if emergency_info is True: 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 now = datetime.utcnow() + # Pricing if customer_fill_up == 1: @@ -788,9 +829,8 @@ def create_a_delivery(user_id): driver_last_name=driver_l_name, driver_first_name=driver_f_name, driver_employee_id=driver_emp_id, - - promo_id =promo_id_get_delivery, - promo_money_discount = promo_money_discount_get_delivery + promo_id=promo_id_get_delivery, + promo_money_discount=promo_money_discount_get_delivery ) diff --git a/app/promo/views.py b/app/promo/views.py index 4d27336..6a3f23b 100644 --- a/app/promo/views.py +++ b/app/promo/views.py @@ -3,9 +3,21 @@ import decimal from datetime import datetime from app.promo import promo 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("/", methods=["GET"]) def get_promo(promo_id): @@ -19,6 +31,24 @@ def get_promo(promo_id): return jsonify(query_schema.dump(get_promo_data)) +@promo.route("/promoprice/", 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"]) def get_all_promo(): """ @@ -58,9 +88,11 @@ def create_promo(): text_on_ticket = request.json["text_on_ticket"] # see if it exists + amount_off = convert_to_decimal(money_off_delivery) + new_promo = Promo_Promo( name_of_promotion = name_of_promotion, - money_off_delivery = float(money_off_delivery), + money_off_delivery = amount_off, description = description, date_created = date_created, text_on_ticket=text_on_ticket @@ -89,10 +121,13 @@ def edit_promo(promo_id): money_off_delivery = request.json["money_off_delivery"] description = request.json["description"] + + amount_off = convert_to_decimal(money_off_delivery) + get_promo_data.text_on_ticket = text_on_ticket get_promo_data.description = description 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.commit()