fix: restrict actual units to forecast region scope in ForecastView

This commit is contained in:
Christian Vidal Wolf
2026-01-30 09:23:07 +01:00
parent a678880112
commit c691d4e9ba
+13 -1
View File
@@ -1654,7 +1654,19 @@ export const calculateForecastViewData = (
// Use referenceData if provided (for global weights), otherwise fallback to rawData // Use referenceData if provided (for global weights), otherwise fallback to rawData
const seasonalitySource = referenceData || rawData; const seasonalitySource = referenceData || rawData;
const historicalData = seasonalitySource.filter(r => r.year < 2026); const historicalData = seasonalitySource.filter(r => r.year < 2026);
const data2026 = seasonalitySource.filter(r => r.year === 2026);
// IMPORTANT: Actuals for 2026 must be strictly scoped to the forecast region
// to avoid mixing UK stats into Pan-EU or vice-versa.
const isForecastUKMode = filters?.customer?.includes('Amazon UK');
const data2026 = rawData.filter(r => {
if (r.year !== 2026) return false;
if (isForecastUKMode) {
return r.customer === 'Amazon UK';
} else {
// In Pan-EU mode, explicitly exclude UK units even if they are in the dataset
return r.customer !== 'Amazon UK';
}
});
// Calculate Seasonality weights for 2025 // Calculate Seasonality weights for 2025
const getWeightsInfo = (records: SalesRecord[]): { weights: number[]; monthsCount: number } | null => { const getWeightsInfo = (records: SalesRecord[]): { weights: number[]; monthsCount: number } | null => {