from .math_round_div import round_div def _whole_units(name: str, value: int) -> None: if isinstance(value, bool) or not isinstance(value, int) or value < 0: raise ValueError("%s must be a whole number, not negative, received %r" % (name, value)) def reorder_point(demand: int, demand_period_days: int, lead_time_days: int, safety_stock: int) -> int: """Lead-time demand, rounded up to whole units, plus safety stock. Rounding up rather than to nearest: 233.33 units of lead-time demand needs 234 in hand, or the last third of a unit is a stock-out. """ _whole_units("demand", demand) _whole_units("leadTimeDays", lead_time_days) _whole_units("safetyStock", safety_stock) if isinstance(demand_period_days, bool) or not isinstance(demand_period_days, int) or demand_period_days <= 0: raise ValueError( "demandPeriodDays must be a whole number of days, at least 1, received %r" % (demand_period_days,) ) return round_div(demand * lead_time_days, demand_period_days, "up") + safety_stock