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:
2026-02-08 17:54:30 -05:00
parent 43a14eba2c
commit 6d5f44db55
18 changed files with 995 additions and 57 deletions

28
app/classes/competitor.py Normal file
View 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