fix: correctly format weight and kg columns to 2 decimals

This commit is contained in:
Christian Vidal Wolf
2026-03-29 14:55:30 +02:00
parent 912fb16cb0
commit 27a161bfbb
2 changed files with 22 additions and 24 deletions
+14 -15
View File
@@ -82,16 +82,15 @@ export default function App() {
const header = (rawHeaders[idx] || '').toLowerCase();
// Skip Article No, Barcodes, and other code-like fields
if (header.includes('id') || header.includes('no') || header.includes('code') ||
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
// But allow if it's a weight/measure column (e.g. Article NW (kg))
if ((header.includes('id') || header.includes('no') || header.includes('code') ||
header.includes('art.') || header.includes('barcode') || header.includes('article')) &&
!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
return val;
}
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
const isPriceCol = priceKeywords.some(kw => header.includes(kw));
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
const isWeightCol = header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg');
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
if (typeof val === 'number') {
return Number(val.toFixed(2));
@@ -100,7 +99,7 @@ export default function App() {
if (typeof val === 'string') {
const normalized = val.trim().replace(',', '.');
const num = parseFloat(normalized);
if (!isNaN(num) && (isPriceCol || isWeightCol || val.includes('.') || val.includes(','))) {
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
return num.toFixed(2);
}
}
@@ -158,14 +157,14 @@ export default function App() {
if (header.includes('id') || header.includes('no') || header.includes('code') ||
header.includes('art.') || header.includes('barcode') || header.includes('article')) {
return val;
// But allow if it's a weight/measure column (e.g. Article NW (kg))
if (!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
return val;
}
}
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
const isPriceCol = priceKeywords.some(kw => header.includes(kw));
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
const isWeightCol = header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg');
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
if (typeof val === 'number') {
return Number(val.toFixed(2));
@@ -174,7 +173,7 @@ export default function App() {
if (typeof val === 'string') {
const normalized = val.trim().replace(',', '.');
const num = parseFloat(normalized);
if (!isNaN(num) && (isPriceCol || isWeightCol || val.includes('.') || val.includes(','))) {
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
return num.toFixed(2);
}
}