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>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
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
|