Files
eamco_office_api/app/schemas/customer.py
Edwin Eames 6d5f44db55 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>
2026-02-08 17:54:30 -05:00

139 lines
4.0 KiB
Python

from marshmallow import Schema, fields, validate, EXCLUDE, pre_load
class CreateCustomerSchema(Schema):
"""Validation schema for creating a new customer"""
class Meta:
unknown = EXCLUDE
customer_last_name = fields.Str(
required=True,
validate=validate.Length(min=1, max=250),
error_messages={"required": "Last name is required"}
)
customer_first_name = fields.Str(
required=True,
validate=validate.Length(min=1, max=250),
error_messages={"required": "First name is required"}
)
customer_town = fields.Str(
required=True,
validate=validate.Length(min=1, max=140),
error_messages={"required": "Town is required"}
)
customer_state = fields.Int(
required=True,
validate=validate.Range(min=0, max=50),
error_messages={"required": "State is required"}
)
customer_zip = fields.Str(
required=True,
validate=validate.Length(min=5, max=10),
error_messages={"required": "Zip code is required"}
)
customer_email = fields.Email(
allow_none=True,
load_default=None
)
customer_home_type = fields.Int(
required=True,
validate=validate.Range(min=0, max=10),
error_messages={"required": "Home type is required"}
)
customer_phone_number = fields.Str(
allow_none=True,
validate=validate.Length(max=25),
load_default=None
)
customer_address = fields.Str(
required=True,
validate=validate.Length(min=1, max=1000),
error_messages={"required": "Address is required"}
)
customer_apt = fields.Str(
allow_none=True,
validate=validate.Length(max=140),
load_default=None
)
customer_description = fields.Str(
allow_none=True,
validate=validate.Length(max=2000),
load_default=None
)
class UpdateCustomerSchema(Schema):
"""Validation schema for updating an existing customer"""
class Meta:
unknown = EXCLUDE
@pre_load
def normalize_data(self, data, **kwargs):
# Convert empty strings to None for email
if 'customer_email' in data and data['customer_email'] == "":
data['customer_email'] = None
# Convert boolean to int for customer_automatic
if 'customer_automatic' in data:
if isinstance(data['customer_automatic'], bool):
data['customer_automatic'] = 1 if data['customer_automatic'] else 0
return data
customer_last_name = fields.Str(
validate=validate.Length(min=1, max=250)
)
customer_first_name = fields.Str(
validate=validate.Length(min=1, max=250)
)
customer_town = fields.Str(
validate=validate.Length(min=1, max=140)
)
customer_state = fields.Int(
validate=validate.Range(min=0, max=50)
)
customer_zip = fields.Str(
validate=validate.Length(min=5, max=10)
)
customer_email = fields.Email(
allow_none=True
)
customer_home_type = fields.Int(
validate=validate.Range(min=0, max=10)
)
customer_phone_number = fields.Str(
allow_none=True,
validate=validate.Length(max=25)
)
customer_address = fields.Str(
validate=validate.Length(min=1, max=1000)
)
customer_apt = fields.Str(
allow_none=True,
validate=validate.Length(max=140)
)
customer_automatic = fields.Int(
validate=validate.Range(min=0, max=10)
)
customer_description = fields.Str(
allow_none=True,
validate=validate.Length(max=2000)
)
customer_fill_location = fields.Str(
allow_none=True,
validate=validate.Length(max=250)
)
class UpdateDescriptionSchema(Schema):
"""Validation schema for updating customer description"""
class Meta:
unknown = EXCLUDE
description = fields.Str(
allow_none=True,
validate=validate.Length(max=2000)
)
fill_location = fields.Int(
allow_none=True
)