3.7 KiB
3.7 KiB
F-072 — Implementer evidence: Active tax rates listed in product edit prices tab
Problem
PricingSection.tsx (admin product edit → pricing tab) had hardcoded VAT logic:
- Two constants:
VAT_GENERAL = 1.21andVAT_REDUCED = 1.10 - Dropdown with only two options: "21% gen." and "10% red."
- No support for super-reduced (4%) which exists in
tax_ratesDB table
The database tax_rates already had 3 active rates (4%, 10%, 21%), but the frontend only showed 2.
Changes
Backend domain
project/src/modules/pricing/domain/price.ts:
- Added
'super-reduced'toVatRatetype - Added
'super-reduced': 400toVAT_BASIS_POINTS
Backend routes
project/src/modules/pricing/api/pricing.routes.ts:
vatRateSchemaupdated fromz.enum(['general', 'reduced'])toz.enum(['general', 'reduced', 'super-reduced'])
Migration 031
project/migrations/031_vat_super_reduced.js (ESM, applied to DB):
- Updated CHECK constraint on
pricing_variant_prices.vat_rateto include 'super-reduced' - Updated CHECK constraints on
pricing_price_history.previous_vat_rateandnew_vat_rateto include 'super-reduced'
Admin types
project/apps/admin/src/types/index.ts:
VariantPrice.vatRateextended to include'super-reduced'
Admin api-client
project/apps/admin/src/lib/api-client.ts:
setVariantPriceparameter type extended to'general' | 'reduced' | 'super-reduced'
PricingSection.tsx
- Imported
taxApiandTaxRatefrom@/lib/api-client - Added
activeTaxRatesstate (TaxRate[]) - Added
useEffectto fetch active tax rates fromtaxApi.list()and filteractive === true vatRatestate type extended to include'super-reduced'- Dropdown now maps
activeTaxRates.map(r => ({ key: r.appliesTo, label: r.name + ' (' + r.ratePercent + '%)' })) - Fallback: when no active rates loaded, shows original two options
- PVP/gross calculation uses dynamic rate:
Math.round(netCents * (1 + ratePercent / 100)) - Help text updated to reference "Configuración → Tipos impositivos"
InventorySection.tsx
VariantRow.vatRatetype extended to'general' | 'reduced' | 'super-reduced'- Gross price calculation updated to handle
super-reduced(1.04 multiplier) - VAT display in non-edit mode updated to show 4%, 10%, or 21% based on rate
- VAT dropdown in edit mode added "4% (superreducido)" option
Verification
npx tsc --noEmit— backend exit 0 ✅, admin exit 0 ✅npx eslinton changed files — exit 0 ✅- Migration 031 applied to DB ✅
- Backend rebuilt and restarted ✅
- API test:
PUT /pricing/variants/:idwithvatRate: 'super-reduced'→ HTTP 200, response includes"vatRate":"super-reduced"✅ - API test:
GET /pricing/variants/:idreturns variant withvatRate: 'super-reduced'✅ - API test:
GET /admin/tax-ratesreturns all 3 active rates (4%, 10%, 21%) ✅ ./scripts/verify.sh— exit 0 ✅
Files touched
project/migrations/031_vat_super_reduced.js (new)
project/src/modules/pricing/domain/price.ts (modified)
project/src/modules/pricing/api/pricing.routes.ts (modified)
project/apps/admin/src/types/index.ts (modified)
project/apps/admin/src/lib/api-client.ts (modified)
project/apps/admin/src/features/products/components/sections/PricingSection.tsx (modified)
project/apps/admin/src/features/products/components/sections/InventorySection.tsx (modified)
work/artifacts/F-072/implementer.md (this file)