Home Projects Portfolio Dashboard Export PDF Log in

Scaling Supplier Pricing Logic in BoxiControl

Improving Data Flexibility

In the BoxiControl project, we recently addressed the growing complexity of supply chain management by introducing a new mechanism for handling supplier price increases. As businesses scale, hard-coded pricing models quickly become a maintenance bottleneck. Our goal was to decouple pricing logic from core business services to ensure better adaptability.

The Technical Approach

To manage these price adjustments, we utilized the Repository Pattern to abstract data access. By separating the persistence layer from our domain logic, we gained the ability to inject dynamic pricing rules without modifying our primary services.

We implemented a structured data schema using Pydantic for validation and SQLAlchemy for database interactions, ensuring that incoming pricing data adheres to strict integrity constraints.

from pydantic import BaseModel
from typing import Optional

class PriceUpdateSchema(BaseModel):
    supplier_id: int
    adjustment_rate: float
    effective_date: str

def update_supplier_pricing(repo: SupplierRepository, data: PriceUpdateSchema):
    # Business logic to calculate new pricing
    new_price = repo.get_current_price(data.supplier_id) * (1 + data.adjustment_rate)
    repo.save_price(data.supplier_id, new_price)

Key Implementation Details

  1. Validation at the Edge: By using Pydantic models, we catch malformed pricing data before it ever touches the database layer.
  2. Repository Abstraction: The SupplierRepository acts as a buffer, allowing us to swap underlying database queries or even mock data during testing without breaking the feature.
  3. Test-Driven Reliability: Every update cycle is verified via Pytest, ensuring that rounding errors or invalid date formats do not propagate through the system.

Results

  • Decoupled Logic: Pricing modules now operate independently of the primary transaction engine.
  • Easier Maintenance: Adding new pricing rules requires updating a schema rather than re-writing controller logic.
  • Improved Testing: Unit tests now cover edge cases like extreme price fluctuations, which were previously difficult to simulate.

Takeaway

Next time you encounter "spaghetti" logic in your business layer, try moving the data validation and persistence into a dedicated repository. It creates a cleaner boundary, making your code significantly easier to test and extend as your requirements grow.


Generated with Gitvlg.com

Scaling Supplier Pricing Logic in BoxiControl
Facundo Puebla

Facundo Puebla

Author

Share: