34 lines
jobs/commission_calculator.py
Computes sales rep commissions from closed deal records.
# Commission calculation for the monthly sales rep payout job.
import logging
from typing import List
 
logger = logging.getLogger(__name__)
 
# Flat commission rate applied to total closed deal value.
COMMISSION_RATE = 0.10
 
# Type alias: deal record with deal_id (str), rep_id (str), value (float).
Deal = dict
 
 
def compute_rep_commission(deals: List[Deal], rep_id: str) -> float:
    """Return the commission amount owed to rep_id for the period.
 
    Filters deals to those belonging to rep_id, sums their value,
    and multiplies by COMMISSION_RATE.
 
    Parameters
    ----------
    deals : list of Deal
        All closed deals eligible for commission in the period.
    rep_id : str
        Sales rep identifier to filter and aggregate.
 
    Returns
    -------
    float
        Commission amount for rep_id. Zero if the rep has no eligible deals.
    """
    rep_deals = [d for d in deals if d["rep_id"] == rep_id]
    total_value = sum(d["value"] for d in rep_deals)
    return total_value * 0.01