Major update spanning pricing, market data, and analytics: - Pricing: Replace single-price service fees with 5-tier pricing for same-day, prime, and emergency deliveries across create/edit/finalize - Market: Add Ticker_Price and CompanyPrice models with endpoints for live commodity prices (HO, CL, RB) and competitor price tracking - Stats: Add daily/weekly/monthly gallons endpoints with multi-year comparison and YoY totals for the stats dashboard - Delivery: Add map and history endpoints, fix finalize null-driver crash - Schema: Change fill_location from INTEGER to VARCHAR(250), add pre_load normalization for customer updates, fix admin auth check Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
115 lines
3.5 KiB
Python
Executable File
115 lines
3.5 KiB
Python
Executable File
|
|
from app import db, ma
|
|
from datetime import datetime
|
|
|
|
|
|
class Delivery_Delivery(db.Model):
|
|
__tablename__ = 'delivery_delivery'
|
|
__table_args__ = {"schema": "public"}
|
|
|
|
id = db.Column(db.Integer,
|
|
primary_key=True,
|
|
autoincrement=True,
|
|
unique=False)
|
|
|
|
customer_id = db.Column(db.INTEGER)
|
|
customer_name = db.Column(db.VARCHAR(1000))
|
|
customer_address = db.Column(db.VARCHAR(1000))
|
|
customer_town = db.Column(db.VARCHAR(140))
|
|
customer_state = db.Column(db.VARCHAR(140))
|
|
customer_zip = db.Column(db.INTEGER)
|
|
# how many gallons ordered
|
|
gallons_ordered = db.Column(db.INTEGER)
|
|
# if customer asked for a fill
|
|
customer_asked_for_fill = db.Column(db.INTEGER)
|
|
# integer value if delivered, waiting, cancelled etc
|
|
gallons_delivered =db.Column(db.DECIMAL(6, 2))
|
|
# if customer has a full tank
|
|
customer_filled = db.Column(db.INTEGER)
|
|
# integer value if delivered, waiting, cancelled etc
|
|
# waiting = 0
|
|
# cancelled = 1
|
|
# out for delivery = 2
|
|
# tommorrow = 3
|
|
# issue = 5
|
|
# finalized = 10
|
|
|
|
delivery_status = db.Column(db.INTEGER)
|
|
|
|
# when the call to order took place
|
|
when_ordered = db.Column(db.DATE(), default=None)
|
|
# when the delivery date happened
|
|
when_delivered = db.Column(db.DATE(), default=None)
|
|
# when the delivery is expected ie what day
|
|
expected_delivery_date = db.Column(db.DATE(), default=None)
|
|
# automatic delivery
|
|
automatic = db.Column(db.INTEGER)
|
|
automatic_id = db.Column(db.INTEGER)
|
|
# OIL info and id from table
|
|
oil_id = db.Column(db.INTEGER)
|
|
supplier_price = db.Column(db.DECIMAL(6, 2))
|
|
customer_price = db.Column(db.DECIMAL(6, 2))
|
|
# weather
|
|
customer_temperature = db.Column(db.DECIMAL(6, 2))
|
|
|
|
dispatcher_notes = db.Column(db.TEXT())
|
|
|
|
|
|
prime = db.Column(db.INTEGER)
|
|
same_day = db.Column(db.INTEGER)
|
|
emergency = db.Column(db.INTEGER)
|
|
|
|
# Pricing tier selection (1-5) for each service type
|
|
pricing_tier_same_day = db.Column(db.INTEGER, default=1)
|
|
pricing_tier_prime = db.Column(db.INTEGER, default=1)
|
|
pricing_tier_emergency = db.Column(db.INTEGER, default=1)
|
|
|
|
# cash = 0
|
|
# credit = 1
|
|
# credit/cash = 2
|
|
# check = 3
|
|
# other = 4
|
|
payment_type = db.Column(db.INTEGER)
|
|
payment_card_id = db.Column(db.INTEGER)
|
|
cash_recieved = db.Column(db.DECIMAL(6, 2))
|
|
|
|
driver_employee_id = db.Column(db.INTEGER)
|
|
driver_first_name = db.Column(db.VARCHAR(140))
|
|
driver_last_name = db.Column(db.VARCHAR(140))
|
|
|
|
pre_charge_amount = db.Column(db.DECIMAL(6, 2))
|
|
total_price = db.Column(db.DECIMAL(6, 2))
|
|
final_price = db.Column(db.DECIMAL(6, 2))
|
|
check_number = db.Column(db.VARCHAR(20))
|
|
|
|
|
|
promo_id = db.Column(db.INTEGER)
|
|
promo_money_discount = db.Column(db.DECIMAL(6, 2))
|
|
|
|
|
|
class Delivery_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
|
class Meta:
|
|
model = Delivery_Delivery
|
|
|
|
|
|
|
|
class Delivery_Notes_Driver(db.Model):
|
|
__tablename__ = 'delivery_notes'
|
|
__table_args__ = {"schema": "public"}
|
|
|
|
id = db.Column(db.Integer,
|
|
primary_key=True,
|
|
autoincrement=True,
|
|
unique=False)
|
|
|
|
delivery_id = db.Column(db.INTEGER)
|
|
driver_comments = db.Column(db.TEXT)
|
|
time_added = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
|
driver_id = db.Column(db.INTEGER)
|
|
driver_name = db.Column(db.VARCHAR(140))
|
|
|
|
|
|
class Delivery_Notes_Driver_schema(ma.SQLAlchemyAutoSchema):
|
|
class Meta:
|
|
model = Delivery_Notes_Driver
|