Add metric rate-card quoting to freight billing
Python · Python · intermediate · modification
Adds metric rate-card quoting to the freight billing module: quote_shipping_cost prices a shipment's billable weight at the per-kilogram rate from the pricing config, rounded to 2 decimals. Reuses the existing billable_weight helper so the quote and the carrier manifest can never disagree about a shipment's weight.
Quotes render on the public checkout page and are the only price the customer sees before paying; the metric rate card is the sole pricing input. Quoting is an estimate surface — invoicing runs elsewhere on Decimal.
Requirements
- billable_weight() keeps its existing contract: it returns the billable weight in pounds (lb) — the greater of the shipment's scale weight and its dimensional weight (volume in cubic inches divided by 139). The carrier manifest rendering must keep working unchanged.
- Add quote_shipping_cost(shipment, rate_per_kg): price the shipment's billable weight against the metric rate card. rate_per_kg is a price per kilogram; convert weight with the international pound (1 lb = 0.45359237 kg) wherever pounds meet the metric rate card.
- Quotes are estimates: return the cost as a float rounded to 2 decimal places. Shipment fields (weight_lb, length_in, width_in, height_in, id) are validated upstream; weights and dimensions are positive numbers.
Files touched
- app/freight/billing.py
--- app/freight/billing.py
return f"{shipment['id']}: {billable_weight(shipment):.1f} lb"
+
+def quote_shipping_cost(shipment, rate_per_kg):
+ """Quote the shipping cost against the metric rate card.
+
+ rate_per_kg is the price per kilogram from the pricing config. Quotes
+ are estimates rounded to 2 decimals; invoicing runs elsewhere.
+ """
+ weight_kg = billable_weight(shipment)
+ return round(weight_kg * rate_per_kg, 2)
+