Fix: Implement dynamic column detection to handle Excel structure changes (insertion of PM Classification). This fixes the Missing data error in Pricing Units and other views.

This commit is contained in:
Christian Vidal Wolf
2026-04-22 16:52:59 +02:00
parent 8471a69529
commit d43d9931c6
15 changed files with 176 additions and 55 deletions
+72 -20
View File
@@ -9,6 +9,7 @@ export interface AppState {
asinColumnIndex: number | null;
}
// Canonical column indices (defaults)
export const COLUMNS = {
ARTICLE_NO: 0,
ARTICLE_NAME: 2,
@@ -16,28 +17,79 @@ export const COLUMNS = {
LICENSE: 8,
DETAILS_EN: 9,
DETAILS_DE: 10,
BARCODE: 28,
TARIFF_CODE: 58,
COUNTRY_ORIGIN: 60,
LONG_DE: 62,
LONG_EN: 63,
SHORT_DE: 64,
SHORT_EN: 65,
RECOMMENDED_AGE: 67,
BARCODE: 29,
TARIFF_CODE: 60,
COUNTRY_ORIGIN: 62,
LONG_DE: 64,
LONG_EN: 65,
SHORT_DE: 66,
SHORT_EN: 67,
RECOMMENDED_AGE: 70,
CLASSIFICATION: 11,
ITEM_AVAILABLE: 14,
MOQ: 27,
UNITS_INNER: 31,
UNITS_OUTER: 32,
ASIN: 33,
INNER_W: 42,
INNER_L: 43,
INNER_H: 44,
OUTER_W: 47,
OUTER_L: 48,
OUTER_H: 49,
ITEM_AVAILABLE: 16,
MOQ: 28,
UNITS_INNER: 32,
UNITS_OUTER: 33,
ASIN: 76,
INNER_W: 43,
INNER_L: 44,
INNER_H: 45,
OUTER_W: 48,
OUTER_L: 49,
OUTER_H: 50,
VERIFIED_DIMS: 100,
VALIDATED_CHECK: 101,
VALIDATED_NOTE: 102,
PRODUCT_TYPE: 103
};
};
// Search patterns for dynamic detection
export const COLUMN_PATTERNS: Record<keyof typeof COLUMNS, string[]> = {
ARTICLE_NO: ['article', 'no'],
ARTICLE_NAME: ['article', 'name'],
LINE: ['line'],
LICENSE: ['license'],
DETAILS_EN: ['details', 'english'],
DETAILS_DE: ['details', 'german'],
BARCODE: ['article', 'barcode'],
TARIFF_CODE: ['tariff', 'code'],
COUNTRY_ORIGIN: ['country', 'origin'],
LONG_DE: ['long', 'description', 'german'],
LONG_EN: ['long', 'description', 'english'],
SHORT_DE: ['short', 'description', 'german'],
SHORT_EN: ['short', 'description', 'english'],
RECOMMENDED_AGE: ['recommended', 'age'],
CLASSIFICATION: ['classification'],
ITEM_AVAILABLE: ['item', 'available'],
MOQ: ['moq'],
UNITS_INNER: ['units', 'inner'],
UNITS_OUTER: ['units', 'outer'],
ASIN: ['asin'],
INNER_W: ['inner', 'w'],
INNER_L: ['inner', 'l'],
INNER_H: ['inner', 'h'],
OUTER_W: ['outer', 'w'],
OUTER_L: ['outer', 'l'],
OUTER_H: ['outer', 'h'],
// Virtual/Extra columns stay hardcoded or managed elsewhere
VERIFIED_DIMS: ['verified'],
VALIDATED_CHECK: ['validated'],
VALIDATED_NOTE: ['note'],
PRODUCT_TYPE: ['product', 'type']
};
export function resolveColumnIndices(headers: string[]): typeof COLUMNS {
const resolved = { ...COLUMNS };
const h = headers.map(val => String(val || '').toLowerCase());
Object.entries(COLUMN_PATTERNS).forEach(([key, patterns]) => {
const idx = h.findIndex(headerText =>
patterns.every(p => headerText.includes(p.toLowerCase()))
);
if (idx >= 0) {
resolved[key as keyof typeof COLUMNS] = idx;
}
});
return resolved;
}