DEV Community

Tidy Cents
Tidy Cents

Posted on

Cost per usable unit: comparing supplier quotes in Python without assuming 100% yield

Comparing supplier quotes by unit price is the classic mistake. What you actually pay for is a usable unit: price plus freight and duty, divided by the share of units that pass inspection.

from decimal import Decimal, ROUND_HALF_UP

def cents(x):
    return x.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)

def cost_per_usable_unit(price, freight_duty, usable_share):
    if usable_share is None:
        return None          # unknown yield is "insufficient data", never 100 %
    return cents((Decimal(price) + Decimal(freight_duty)) / Decimal(usable_share))

a = cost_per_usable_unit("10.00", "1.20", "0.98")
b = cost_per_usable_unit("9.20", "2.10", "0.92")
print(a, b, b - a)   # 11.43 12.28 0.85
print(cost_per_usable_unit("9.20", "2.10", None))  # None
Enter fullscreen mode Exit fullscreen mode

Two rules are baked into that tiny function:

  1. An unknown yield returns None, not a number. Defaulting to 100% makes the riskiest offer look best. Make "insufficient data" a first-class result.
  2. Money is Decimal and rounded once, at the end, to cents.

With the example numbers, the $9.20 quote is $0.85 more expensive per usable unit than the $10.00 quote. On 10,000 units that is $8,500.

Next steps if you build this out:

  • keep each quote in its own currency and store the FX rate with its direction ("1 EUR = X USD") and an expiry date;
  • treat recoverable import tax as a cash timing item, not part of unit cost;
  • add one-off switching costs (samples, tooling, overlap stock) and compute payback in units.

The full tool we ship for this is here (paid, with a free demo): https://gettidycents.com/product/supplier-switch-landed-cost-lab

What do you default missing inputs to in your own calculators — zero, None, or a hard error?

Top comments (1)

Collapse
 
zubair933 profile image
Md Zubair •

Using Python Decimal and factoring scrap/yield rate directly into unit economics instead of naive unit price comparisons catches hidden margin leaks immediately! Really practical real-world modeling.