Private
Public Access
44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/datatypes"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Stock struct {
|
|
ID uint64 `gorm:"primaryKey" json:"id"`
|
|
EmpresaID uint64 `gorm:"not null;default:1;index;uniqueIndex:uq_stock_empresa_repuesto_almacen,priority:1" json:"empresaId"`
|
|
|
|
Cantidad float64 `gorm:"type:decimal(15,3);not null;default:0;check:cantidad >= 0" json:"cantidad"`
|
|
CantidadReservada float64 `gorm:"type:decimal(15,3);not null;default:0;check:cantidad_reservada >= 0" json:"cantidadReservada"`
|
|
RepuestoID uint64 `gorm:"not null;uniqueIndex:uq_stock_empresa_repuesto_almacen,priority:2" json:"repuestoId"`
|
|
Repuesto Repuesto `gorm:"foreignKey:RepuestoID" json:"repuesto"`
|
|
AlmacenID uint `gorm:"not null;uniqueIndex:uq_stock_empresa_repuesto_almacen,priority:3" json:"almacenId"`
|
|
Almacen Almacen `gorm:"foreignKey:AlmacenID" json:"almacen,omitempty"`
|
|
Observacion string `gorm:"type:varchar(60)" json:"observacion"`
|
|
|
|
// MovimientosLegacy conserva el JSON histórico de la versión anterior.
|
|
// La fuente de verdad pasa a ser la tabla movimiento_stock.
|
|
MovimientosLegacy datatypes.JSONSlice[MovimientoStockLegacy] `gorm:"column:movimientos;type:json" json:"movimientosLegacy,omitempty"`
|
|
Movimientos []MovimientoStock `gorm:"foreignKey:StockID" json:"-"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt,omitempty"`
|
|
}
|
|
|
|
// MovimientoStockLegacy es el formato anterior embebido en stock.movimientos.
|
|
// Solo se usa para migrar datos existentes.
|
|
type MovimientoStockLegacy struct {
|
|
Fecha time.Time `json:"fecha"`
|
|
Tipo string `json:"tipo"`
|
|
Cantidad float64 `json:"cantidad"`
|
|
UsuarioID uint `json:"usuarioId"`
|
|
}
|
|
|
|
func (Stock) TableName() string {
|
|
return "stock"
|
|
}
|