From 50d248871ca5c58819261f687537c5bc6a9be5eb Mon Sep 17 00:00:00 2001 From: "Ian P. Christian" Date: Thu, 16 Apr 2026 08:08:55 +0100 Subject: [PATCH] fix: reset price fields to safe defaults when switching to Octopus provider When switching from Nord Pool to Octopus Energy, the markup rate, VAT multiplier, and additional costs fields are hidden in the UI but their old values are still sent to the backend. This causes the optimizer to apply incorrect price adjustments (e.g. Swedish 25% VAT and grid fees) on top of Octopus rates that are already all-in. Reset these fields to safe defaults (markupRate=0, vatMultiplier=1, additionalCosts=0) on provider switch so the backend sees correct values. Co-Authored-By: Claude Opus 4.6 --- .../src/components/settings/PricingFormSection.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/settings/PricingFormSection.tsx b/frontend/src/components/settings/PricingFormSection.tsx index c348899a..67795c8b 100644 --- a/frontend/src/components/settings/PricingFormSection.tsx +++ b/frontend/src/components/settings/PricingFormSection.tsx @@ -26,6 +26,16 @@ export function PricingFormSection({ form, onChange }: Props) { const isOctopus = form.provider === 'octopus'; const currency = isOctopus ? 'GBP' : form.currency; + const handleChange = (next: PricingForm) => { + // When switching TO Octopus, reset fields that are hidden but still sent to + // the backend. Octopus rates are already all-in (VAT-inclusive, GBP/kWh), + // so markup / VAT / additional costs must be zero / neutral. + if (next.provider === 'octopus' && form.provider !== 'octopus') { + next = { ...next, markupRate: 0, vatMultiplier: 1, additionalCosts: 0 }; + } + onChange(next); + }; + const previewSpot = 1.0; const previewBuy = Number( ((previewSpot + form.markupRate) * form.vatMultiplier + form.additionalCosts).toFixed(4), @@ -46,7 +56,7 @@ export function PricingFormSection({ form, onChange }: Props) { { value: 'octopus', label: 'Octopus Energy' }, ], form.provider, - v => onChange({ ...form, provider: v }), + v => handleChange({ ...form, provider: v }), )} {form.provider === 'nordpool_official' && (