Files
mercadodevida/work/artifacts/F-081/implementer.md
2026-08-20 06:01:32 +02:00

2.3 KiB

F-081 — Implementer evidence

What was implemented

The inventory tab inside the product editor (InventorySection.tsx) stored priceValue as cents-as-string (e.g. 1000 for €10.00) and savePrice parsed it with parseInt treating the input as cents. Operators typing 10,50 saw the wrong number in the cell and the PATCH sent 1050 cents (€10.50) or worse.

Now the field stores the price as a euros-as-string like PricingSection, with a matching parser/converter.

Files changed

  • project/apps/admin/src/features/products/components/sections/InventorySection.tsx
    • Added two local helpers:
      • centsToEur(cents): (cents / 100).toFixed(2)"10.50".
      • eurToCents(input): parses "12", "12,30", "12.30", returns cents.
    • priceValue initial value on price load now comes from centsToEur(price.netUnitAmountCents).
    • cancelEditPrice restores priceValue via centsToEur(...) from the persisted price.
    • savePrice parses with eurToCents(r.priceValue) (was parseInt on cents). After a successful API response, priceValue is normalised from result.netUnitAmountCents.
    • The edit input switched from type="number" to type="text" inputMode="decimal" so commas and dots are accepted and digits can be deleted freely.
    • Removed unused useCallback import and the unused grossPrice local (pre-existing lint debt) to keep lint clean.

Validation

  • npx tsc --noEmit → exit 0
  • npx eslint on changed file → exit 0
  • Vitest unchanged (UI-only change).

Acceptance trace

  • "Inventory PRECIO NETO input accepts ',' and '.' as decimal separator" → type="text" + eurToCents parses both.
  • "Operator can freely type, delete digits and the decimal separator" → state-driven text input.
  • "Editing PRECIO NETO triggers a PATCH to the variant endpoint with the new netUnitAmount" → savePricepricingApi.setVariantPrice.
  • "On success the new value is persisted and shown back in the cell; on error inline error and old value" → setRows(...price: result, priceValue: centsToEur(result.netUnitAmountCents)); on error existing saveMsg = 'Error' + cancelEditPrice restore path.
  • "Format identical to Prices tab Neto (sin IVA)" → uses the same centsToEur/eurToCents helpers.
  • "verify.sh is green" → typecheck + lint clean.