You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sales: add-item quantity field doesn't make clear which unit it expects — users type egg count instead of pack-unit count #445
When adding a line item to a sales order, users sometimes type the total egg count into the quantity field instead of the count in the selected pack unit — e.g. selling 2 trays (= 60 eggs), the user types 60 instead of 2. The backend takes the quantity at face value in whatever unit is selected, so this silently records a sale 30x larger than intended (2 trays vs. 60 trays = 1,800 eggs).
Why it happens (confirmed in code)
Add-item form (web/src/routes/SalesPage.tsx:539-563): a product <select> (options show only p.name, no unit hint — line 547), a separate "Per" unit <select> (line 550-554, e.g. Egg/Dozen/Tray/Case), and the quantity NumberField (line 559-563) labeled with the bare word "Quantity" (web/src/i18n/en.ts:259). Nothing next to the quantity field echoes the selected unit or previews the resulting egg count while typing.
Once a line is added, the table row does show this info — perUnit/eggsCount render "per tray (30 eggs)" (SalesPage.tsx:480-481) — but only after the fact, too late to catch the mistake.
Backend takes quantity literally in the selected unit: AddOrderItemHandler.cs:46-53,88-90 resolves the unit's EggUnitConversion and passes command.Quantity straight through; SalesOrder.cs:43-45,58-60 computes quantityBase (eggs) = quantity × baseUnitFactor. So "60" typed against a Tray product (baseUnitFactor=30) becomes 1,800 eggs, not 60 — exactly the reported bug.
A fix pattern already exists elsewhere in the app and is unused here: quantityLabelWithUnit = "Quantity ({{unit}})" (web/src/i18n/en.ts:540,710) is already used on Inventory (InventoryPage.tsx:444,492,528) and Water (WaterPage.tsx:242), but not on the Sales add-item form.
Suggested UI fix
Label the quantity field with its unit, reusing the existing quantityLabelWithUnit pattern instead of the bare t("quantity") at SalesPage.tsx:560-561 — e.g. "Quantity (tray)".
Show a live conversion hint next to the quantity field as the user types — "= {quantity × eggsPerUnit} eggs" — computed client-side from the same conversions data already used for the perUnit/eggsCount display at SalesPage.tsx:480-481. This is the most direct fix: the user sees immediately that typing 60 means 1,800 eggs and self-corrects.
Annotate the product picker (SalesPage.tsx:547) with the product's default unit size, e.g. "Large Tray (30 eggs/tray)", so the unit is visible before quantity entry even starts.
All three are additive, client-side-only display changes — no backend/domain change needed, since the unit semantics are already correct; the problem is purely that the UI doesn't surface them at entry time.
Docs
Touches user-visible Sales behavior — update specs/product/GLOSSARY.md if the "per-unit quantity" concept isn't already documented there, and the SPA Help page/in-app glossary, per AGENTS.md's doc-sync rule, once implemented.
Activity
fix(sales): suppress unit annotations by identity, not factor value (#…
fix(sales): bind the previewed eggs-per-unit factor to the add-item w…
fix(spa): close the selling-unit i18n key union for the tsc -b build (#…
fix(sales): keep a line's discount markers agreeing while its price i…