fix(pecas): corrigir discrepancia no calculo de peso total da tabela e da importacao
This commit is contained in:
@@ -123,12 +123,7 @@ export function ImportarPecasModal({ open, onOpenChange, onImport, pecasExistent
|
||||
});
|
||||
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 {
|
||||
convertedData[field] = numValue;
|
||||
}
|
||||
convertedData[field] = numValue;
|
||||
}
|
||||
} else {
|
||||
convertedData[field] = field.includes('componente') ? 0 : (field === 'quantidade' ? 1 : 0);
|
||||
|
||||
@@ -77,7 +77,7 @@ export function TableRow({
|
||||
</TableCell>
|
||||
|
||||
<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 className="w-16 px-2 text-muted-foreground text-xs">
|
||||
|
||||
@@ -363,8 +363,8 @@ export function usePecas() {
|
||||
marca: item.marca || '',
|
||||
descricao: item.descricao || '',
|
||||
quantidade: Number(item.quantidade) || 0,
|
||||
peso_unitario: Math.round(Number(item.peso_unitario) || 0),
|
||||
peso_total: Math.round(Number(item.peso_total) || 0),
|
||||
peso_unitario: Number(item.peso_unitario) || 0,
|
||||
peso_total: Number(item.peso_total) || 0,
|
||||
tratamento_superficial: item.tratamento_superficial || '',
|
||||
material: item.material || '',
|
||||
perfil_principal: item.perfil_principal || '',
|
||||
|
||||
@@ -177,7 +177,10 @@ export const usePecasTable = (pecas: 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);
|
||||
}, [filteredAndSortedPecas, selectedPecas]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user