This commit is contained in:
lizandrogd
2026-01-19 21:51:23 -05:00
parent 2234a6f6e2
commit 4208c3bbf4
3 changed files with 50 additions and 3 deletions
+22
View File
@@ -22,6 +22,8 @@ class Tela extends Model
protected $casts = [
'foto' => 'string',
'valor_total' => 'decimal:2',
'costo_por_metro' => 'decimal:2',
];
public function proveedor()
@@ -33,4 +35,24 @@ class Tela extends Model
{
return $this->hasMany(OrdenProduccion::class);
}
protected static function booted()
{
static::saving(function ($tela) {
// Protección temporal: si la columna en la BD aún es integer, convertir a entero
try {
$type = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'costo_por_metro');
if ($type === 'integer') {
$tela->costo_por_metro = (int) round($tela->costo_por_metro ?? 0);
}
$typeVal = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'valor_total');
if ($typeVal === 'integer') {
$tela->valor_total = (int) round($tela->valor_total ?? 0);
}
} catch (\Exception $e) {
// Ignorar si no se puede determinar el tipo de columna (por ejemplo en pruebas antes de migraciones)
}
});
}
}