feat: 5-tier pricing, market ticker integration, and delivery stats
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>
This commit is contained in:
@@ -51,12 +51,15 @@ class Auth_User(UserMixin, db.Model):
|
||||
self.confirmed = confirmed
|
||||
self.active = active
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_active(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_anonymous(self):
|
||||
return False
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class Auto_Update(db.Model):
|
||||
class Auto_Temp(db.Model):
|
||||
__tablename__ = 'auto_temp'
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
|
||||
id = db.Column(db.Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
@@ -38,7 +38,7 @@ class Auto_Temp_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Auto_Delivery(db.Model):
|
||||
__tablename__ = 'auto_delivery'
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
|
||||
id = db.Column(db.Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
@@ -57,12 +57,14 @@ class Auto_Delivery(db.Model):
|
||||
estimated_gallons_left_prev_day = db.Column(db.DECIMAL(6, 2))
|
||||
tank_height = db.Column(db.VARCHAR(25))
|
||||
tank_size = db.Column(db.VARCHAR(25))
|
||||
house_factor = db.Column(db.DECIMAL(5, 2))
|
||||
house_factor = db.Column(db.DECIMAL(7, 4))
|
||||
hot_water_summer = db.Column(db.Integer)
|
||||
#0 = waiting
|
||||
#1 = waiting for delivery
|
||||
auto_status = db.Column(db.INTEGER())
|
||||
open_ticket_id = db.Column(db.Integer)
|
||||
confidence_score = db.Column(db.Integer, default=20)
|
||||
k_factor_source = db.Column(db.VARCHAR(20), default='default')
|
||||
|
||||
|
||||
class Auto_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
@@ -73,7 +75,7 @@ class Auto_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Tickets_Auto_Delivery(db.Model):
|
||||
__tablename__ = 'auto_tickets'
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
|
||||
id = db.Column(db.Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
@@ -98,8 +100,9 @@ class Tickets_Auto_Delivery(db.Model):
|
||||
payment_type = db.Column(db.INTEGER, nullable=True)
|
||||
payment_card_id = db.Column(db.INTEGER, nullable=True)
|
||||
payment_status = db.Column(db.INTEGER, nullable=True)
|
||||
is_budget_fill = db.Column(db.Boolean, default=False)
|
||||
|
||||
|
||||
|
||||
class Tickets_Auto_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Tickets_Auto_Delivery
|
||||
|
||||
28
app/classes/competitor.py
Normal file
28
app/classes/competitor.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from app import db, ma
|
||||
from datetime import datetime
|
||||
|
||||
class CompanyPrice(db.Model):
|
||||
__tablename__ = "company_prices"
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
company_name = db.Column(db.String(255), nullable=False, index=True)
|
||||
town = db.Column(db.String(100), nullable=True)
|
||||
price_decimal = db.Column(db.Numeric(6, 3), nullable=False)
|
||||
scrape_date = db.Column(db.Date, nullable=False, index=True)
|
||||
zone = db.Column(db.String(50), nullable=False, default="zone10", index=True)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"company_name": self.company_name,
|
||||
"town": self.town,
|
||||
"price": float(self.price_decimal) if self.price_decimal else None,
|
||||
"date": self.scrape_date.isoformat() if self.scrape_date else None,
|
||||
"zone": self.zone
|
||||
}
|
||||
|
||||
class CompanyPriceSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = CompanyPrice
|
||||
@@ -95,7 +95,7 @@ class Customer_Description(db.Model):
|
||||
customer_id = db.Column(db.INTEGER)
|
||||
account_number = db.Column(db.VARCHAR(25))
|
||||
company_id = db.Column(db.INTEGER)
|
||||
fill_location = db.Column(db.INTEGER)
|
||||
fill_location = db.Column(db.VARCHAR(250))
|
||||
description = db.Column(db.VARCHAR(2000))
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@ class Delivery_Delivery(db.Model):
|
||||
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
|
||||
|
||||
@@ -17,9 +17,33 @@ class Pricing_Oil_Oil(db.Model):
|
||||
price_from_supplier = db.Column(db.DECIMAL(6, 2))
|
||||
price_for_customer = db.Column(db.DECIMAL(6, 2))
|
||||
price_for_employee = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
# Legacy single-tier pricing (kept for backward compatibility)
|
||||
price_same_day = db.Column(db.DECIMAL(6, 2))
|
||||
price_prime = db.Column(db.DECIMAL(6, 2))
|
||||
price_emergency = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
# New 5-tier pricing for same_day service
|
||||
price_same_day_tier1 = db.Column(db.DECIMAL(6, 2))
|
||||
price_same_day_tier2 = db.Column(db.DECIMAL(6, 2))
|
||||
price_same_day_tier3 = db.Column(db.DECIMAL(6, 2))
|
||||
price_same_day_tier4 = db.Column(db.DECIMAL(6, 2))
|
||||
price_same_day_tier5 = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
# New 5-tier pricing for prime service
|
||||
price_prime_tier1 = db.Column(db.DECIMAL(6, 2))
|
||||
price_prime_tier2 = db.Column(db.DECIMAL(6, 2))
|
||||
price_prime_tier3 = db.Column(db.DECIMAL(6, 2))
|
||||
price_prime_tier4 = db.Column(db.DECIMAL(6, 2))
|
||||
price_prime_tier5 = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
# New 5-tier pricing for emergency service
|
||||
price_emergency_tier1 = db.Column(db.DECIMAL(6, 2))
|
||||
price_emergency_tier2 = db.Column(db.DECIMAL(6, 2))
|
||||
price_emergency_tier3 = db.Column(db.DECIMAL(6, 2))
|
||||
price_emergency_tier4 = db.Column(db.DECIMAL(6, 2))
|
||||
price_emergency_tier5 = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
date = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
||||
|
||||
|
||||
|
||||
28
app/classes/ticker.py
Normal file
28
app/classes/ticker.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
from app import db, ma
|
||||
|
||||
class Ticker_Price(db.Model):
|
||||
__tablename__ = 'ticker_prices'
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
symbol = db.Column(db.String(20), nullable=False, index=True)
|
||||
price_decimal = db.Column(db.Numeric(10, 4), nullable=False)
|
||||
currency = db.Column(db.String(10), nullable=True)
|
||||
change_decimal = db.Column(db.Numeric(10, 4), nullable=True)
|
||||
percent_change_decimal = db.Column(db.Numeric(10, 4), nullable=True)
|
||||
timestamp = db.Column(db.TIMESTAMP(), default=datetime.utcnow, index=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"symbol": self.symbol,
|
||||
"price": float(self.price_decimal) if self.price_decimal is not None else None,
|
||||
"currency": self.currency,
|
||||
"change": float(self.change_decimal) if self.change_decimal is not None else None,
|
||||
"percent_change": float(self.percent_change_decimal) if self.percent_change_decimal is not None else None,
|
||||
"timestamp": self.timestamp.isoformat() if self.timestamp else None,
|
||||
}
|
||||
|
||||
class Ticker_Price_Schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Ticker_Price
|
||||
Reference in New Issue
Block a user