fix(pecas): corrigir discrepancia no calculo de peso total da tabela e da importacao

This commit is contained in:
2026-08-21 13:42:18 +00:00
parent 0a274502e7
commit 9d999fe0a5
4 changed files with 8 additions and 10 deletions
@@ -122,14 +122,9 @@ export function ImportarPecasModal({ open, onOpenChange, onImport, pecasExistent
canAutoFix: /^[\d,\.]+$/.test(value.toString()) canAutoFix: /^[\d,\.]+$/.test(value.toString())
}); });
convertedData[field] = 0; convertedData[field] = 0;
} else {
// Para peso_unitario e peso_total, arredondar para integer
if (field === 'peso_unitario' || field === 'peso_total') {
convertedData[field] = Math.round(numValue);
} else { } else {
convertedData[field] = numValue; convertedData[field] = numValue;
} }
}
} else { } else {
convertedData[field] = field.includes('componente') ? 0 : (field === 'quantidade' ? 1 : 0); convertedData[field] = field.includes('componente') ? 0 : (field === 'quantidade' ? 1 : 0);
} }
+1 -1
View File
@@ -77,7 +77,7 @@ export function TableRow({
</TableCell> </TableCell>
<TableCell className="w-16 px-2 text-right font-medium text-foreground text-xs"> <TableCell className="w-16 px-2 text-right font-medium text-foreground text-xs">
{(peca.quantidade * peca.peso_unitario).toFixed(2)} kg {(peca.peso_total || (peca.quantidade * peca.peso_unitario)).toFixed(2)} kg
</TableCell> </TableCell>
<TableCell className="w-16 px-2 text-muted-foreground text-xs"> <TableCell className="w-16 px-2 text-muted-foreground text-xs">
+2 -2
View File
@@ -363,8 +363,8 @@ export function usePecas() {
marca: item.marca || '', marca: item.marca || '',
descricao: item.descricao || '', descricao: item.descricao || '',
quantidade: Number(item.quantidade) || 0, quantidade: Number(item.quantidade) || 0,
peso_unitario: Math.round(Number(item.peso_unitario) || 0), peso_unitario: Number(item.peso_unitario) || 0,
peso_total: Math.round(Number(item.peso_total) || 0), peso_total: Number(item.peso_total) || 0,
tratamento_superficial: item.tratamento_superficial || '', tratamento_superficial: item.tratamento_superficial || '',
material: item.material || '', material: item.material || '',
perfil_principal: item.perfil_principal || '', perfil_principal: item.perfil_principal || '',
+4 -1
View File
@@ -177,7 +177,10 @@ export const usePecasTable = (pecas: Peca[]) => {
} }
return pecasParaCalcular.reduce((total, peca) => { return pecasParaCalcular.reduce((total, peca) => {
return total + (peca.peso_total || 0); const pTotal = (peca.peso_total && peca.peso_total > 0)
? peca.peso_total
: (peca.quantidade || 1) * (peca.peso_unitario || 0);
return total + pTotal;
}, 0); }, 0);
}, [filteredAndSortedPecas, selectedPecas]); }, [filteredAndSortedPecas, selectedPecas]);