Private
Public Access
Fix GORM foreign keys and column types in models
This commit is contained in:
1 parent
fce21846bc
commit
8d5e191d7d
21 files changed
+48
-39
No files matched your search
@@ -1,9 +1,9 @@
|
||||
package models
|
||||
|
||||
type Almacen struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(5)" json:"id"`
|
||||
Ubicacion string `gorm:"type:varchar(40)" json:"ubicacion"`
|
||||
Stocks []Stock `gorm:"foreignKey:repuestoID" json:"stocks,omitempty"`
|
||||
ID string `gorm:"primaryKey;type:varchar(5)" json:"id"`
|
||||
Ubicacion string `gorm:"type:varchar(40)" json:"ubicacion"`
|
||||
Stocks []Stock `gorm:"foreignKey:AlmacenID" json:"stocks,omitempty"`
|
||||
}
|
||||
|
||||
func (Almacen) TableName() string {
|
||||
|
||||
@@ -11,6 +11,6 @@ type Cliente struct {
|
||||
Nombre string `gorm:"type:varchar(40)" json:"nombre"`
|
||||
Cuit string `gorm:"type:varchar(11);uniqueIndex;not null" json:"cuit"`
|
||||
Email sql.NullString `gorm:"type:varchar(80)" json:"email"`
|
||||
Facturas []Factura `gorm:"foreignKey:facturaID" json:"facturas,omitempty"`
|
||||
Recibos []Recibo `gorm:"foreignKey:reciboID"`
|
||||
Facturas []Factura `gorm:"foreignKey:ClienteID" json:"facturas,omitempty"`
|
||||
Recibos []Recibo `gorm:"foreignKey:ClienteID" json:"recibos,omitempty"`
|
||||
}
|
||||
@@ -13,5 +13,5 @@ type Comprobante struct {
|
||||
Estado string `gorm:"type:varchar(20);not null" json:"estado"`
|
||||
Total float64 `gorm:"type:decimal(15,2);not null" json:"total"`
|
||||
ResponsableID uint `gorm:"column:usuarioID"`
|
||||
Responsable models_seguridad.Usuario `gorm:"foreignKey:usuarioID" json:"usuario"`
|
||||
Responsable models_seguridad.Usuario `gorm:"foreignKey:ResponsableID" json:"usuario"`
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import "gorm.io/gorm"
|
||||
|
||||
type AsientoContable struct {
|
||||
gorm.Model
|
||||
ComprobanteTipo string `gorm:"type:varchar(20),not null"`
|
||||
ComprobanteTipo string `gorm:"type:varchar(20);not null"`
|
||||
ComprobanteID uint
|
||||
Movimientos []MovimientoContable `gorm:"foreignKey:movimientoID"`
|
||||
Movimientos []MovimientoContable `gorm:"foreignKey:AsientoID"`
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import "gorm.io/gorm"
|
||||
|
||||
type CuentaContable struct {
|
||||
gorm.Model
|
||||
Nombre string `gorm:"type:varchar(30),not null"`
|
||||
Tipo string `gorm:"type:varchar(12),not null"`
|
||||
Movimientos []MovimientoContable `gorm:"foreignKey:movimientoID"`
|
||||
Nombre string `gorm:"type:varchar(30);not null"`
|
||||
Tipo string `gorm:"type:varchar(12);not null"`
|
||||
Movimientos []MovimientoContable `gorm:"foreignKey:CuentaID"`
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import "gorm.io/gorm"
|
||||
type MovimientoContable struct {
|
||||
gorm.Model
|
||||
AsientoID uint `gorm:"column:asientoID"`
|
||||
Asiento AsientoContable `gorm:"foreignKey:asientoID"`
|
||||
Asiento AsientoContable `gorm:"foreignKey:AsientoID"`
|
||||
CuentaID uint `gorm:"column:cuentaID"`
|
||||
Cuenta CuentaContable `gorm:"foreignKey:cuentaID"`
|
||||
Cuenta CuentaContable `gorm:"foreignKey:CuentaID"`
|
||||
Debe float64 `gorm:"type:decimal(10,2)"`
|
||||
Haber float64 `gorm:"type:decimal(10,2)"`
|
||||
Descripcion string `gorm:"type:varchar(50)"`
|
||||
|
||||
@@ -2,9 +2,9 @@ package models
|
||||
|
||||
type Devolucion struct {
|
||||
Comprobante
|
||||
Motivo string `gorm:"type:varchar(200);not null" json:"motivo"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:FacturaOrigenID" json:"facturaOrigen"`
|
||||
FacturaOrigenID uint `gorm:"column:facturaOrigenID;not null" json:"facturaOrigenId"`
|
||||
Motivo string `gorm:"type:varchar(200);not null" json:"motivo"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:FacturaOrigenID" json:"facturaOrigen"`
|
||||
FacturaOrigenID uint `gorm:"column:facturaOrigenID;not null" json:"facturaOrigenId"`
|
||||
}
|
||||
|
||||
func (Devolucion) TableName() string {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package models
|
||||
|
||||
|
||||
type Factura struct {
|
||||
Comprobante
|
||||
ClienteID uint `gorm:"column:ClienteID"`
|
||||
Cliente Cliente `gorm:"foreignKey:ClienteID" json:"cliente"`
|
||||
SeAviso bool `gorm:"" json:"seAviso"`
|
||||
Detalles []FacturaDetalle `gorm:"type:json" json:"detalles,omitempty"`
|
||||
ClienteID uint `gorm:"column:ClienteID"`
|
||||
Cliente Cliente `gorm:"foreignKey:ClienteID" json:"cliente"`
|
||||
ProveedorID *uint `json:"proveedorId,omitempty"`
|
||||
Proveedor *Proveedor `gorm:"foreignKey:ProveedorID" json:"proveedor,omitempty"`
|
||||
SeAviso bool `gorm:"" json:"seAviso"`
|
||||
Detalles []FacturaDetalle `gorm:"type:json" json:"detalles,omitempty"`
|
||||
}
|
||||
|
||||
func (Factura) TableName() string {
|
||||
|
||||
@@ -4,8 +4,9 @@ import "gorm.io/gorm"
|
||||
|
||||
type FormaDePago struct {
|
||||
gorm.Model
|
||||
Descripcion string `gorm:"type:varchar(20),not null" json:"desripcion" `
|
||||
Descripcion string `gorm:"type:varchar(20);not null" json:"desripcion" `
|
||||
}
|
||||
|
||||
func (FormaDePago) TableName() string {
|
||||
return "forma_de_pago"
|
||||
}
|
||||
@@ -15,7 +15,6 @@ type Log struct {
|
||||
Detalles datatypes.JSONSlice[LogDetalle] `gorm:"type:json" json:"detalles,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Usuario models_seguridad.Usuario `gorm:"foreignKey:UsuarioID" json:"usuario,omitempty"`
|
||||
|
||||
}
|
||||
|
||||
func (Log) TableName() string {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
type Marca struct {
|
||||
gorm.Model
|
||||
Nombre string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"nombre"`
|
||||
Repuestos []Repuesto `gorm:"foreignKey:MarcaID" json:"repuestos"`
|
||||
Nombre string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"nombre"`
|
||||
Repuestos []Repuesto `gorm:"foreignKey:MarcaID" json:"repuestos"`
|
||||
}
|
||||
|
||||
func (Marca) TableName() string {
|
||||
|
||||
@@ -2,10 +2,11 @@ package models
|
||||
|
||||
type NotaCredito struct {
|
||||
Comprobante
|
||||
Motivo string `gorm:"type:varchar(40),not null"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:facturaID" json:"factura"`
|
||||
Motivo string `gorm:"type:varchar(40);not null"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:FacturaOrigenID" json:"factura"`
|
||||
FacturaOrigenID uint `gorm:"column:facturaID"`
|
||||
}
|
||||
|
||||
func (NotaCredito) TableName() string {
|
||||
return "nota_credito"
|
||||
}
|
||||
@@ -2,10 +2,11 @@ package models
|
||||
|
||||
type NotaDebito struct {
|
||||
Comprobante
|
||||
Motivo string `gorm:"type:varchar(40),not null"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:facturaID" json:"factura"`
|
||||
Motivo string `gorm:"type:varchar(40);not null"`
|
||||
FacturaOrigen Factura `gorm:"foreignKey:FacturaOrigenID" json:"factura"`
|
||||
FacturaOrigenID uint `gorm:"column:facturaID"`
|
||||
}
|
||||
|
||||
func (NotaDebito) TableName() string {
|
||||
return "nota_debito"
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package models
|
||||
|
||||
type OrdenCompra struct {
|
||||
Comprobante
|
||||
Proveedor Proveedor `gorm:"foreignKey:proveedorID" json:"Proveedor"`
|
||||
ProveedorID uint `gorm:"column:proveedorID"`
|
||||
Detalles []OrdenCompraDetalle `gorm:"type:json" json:"detalles,omitempty"`
|
||||
Proveedor Proveedor `gorm:"foreignKey:ProveedorID" json:"Proveedor"`
|
||||
ProveedorID uint `gorm:"column:proveedorID"`
|
||||
Detalles []OrdenCompraDetalle `gorm:"type:json" json:"detalles,omitempty"`
|
||||
}
|
||||
|
||||
func (OrdenCompra) TableName() string {
|
||||
|
||||
@@ -6,6 +6,8 @@ type Pago struct {
|
||||
gorm.Model
|
||||
FormaDePagoID uint `gorm:"column:formaDePagoID"`
|
||||
FormaDePago FormaDePago `gorm:"foreignKey:FormaDePagoID"`
|
||||
ReciboID uint `json:"reciboId"`
|
||||
Recibo Recibo `gorm:"foreignKey:ReciboID" json:"recibo,omitempty"`
|
||||
Importe float64 `gorm:"type:decimal(10,2)"`
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@ import "gorm.io/gorm"
|
||||
|
||||
type Proveedor struct {
|
||||
gorm.Model
|
||||
Nombre string `gorm:"type:varchar(40)" json:"nombre"`
|
||||
Facturas []Factura `gorm:"foreignKey:FacturaID" json:"facturas,omitempty"`
|
||||
Nombre string `gorm:"type:varchar(40)" json:"nombre"`
|
||||
Facturas []Factura `gorm:"foreignKey:ProveedorID" json:"facturas,omitempty"`
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package models
|
||||
|
||||
type Recibo struct {
|
||||
Comprobante
|
||||
Pagos []Pago `gorm:"foreignKey:pagoId" json:"pagos"`
|
||||
ClienteID uint `json:"clienteId"`
|
||||
Cliente Cliente `gorm:"foreignKey:ClienteID" json:"cliente,omitempty"`
|
||||
Pagos []Pago `gorm:"foreignKey:ReciboID" json:"pagos"`
|
||||
}
|
||||
|
||||
func (Recibo) TableName() string {
|
||||
|
||||
@@ -13,7 +13,7 @@ type Remito struct {
|
||||
EmisorID uint `gorm:"not null" json:"emisorId"`
|
||||
ReceptorID uint `gorm:"not null" json:"receptorId"`
|
||||
|
||||
AlmacenOrigenID *uint `gorm:"column:almacen_origen_id" json:"almacenOrigenId,omitempty"`
|
||||
AlmacenOrigenID *string `gorm:"column:almacen_origen_id;type:varchar(5)" json:"almacenOrigenId,omitempty"`
|
||||
AlmacenOrigen *Almacen `gorm:"foreignKey:AlmacenOrigenID" json:"almacenOrigen,omitempty"`
|
||||
|
||||
Detalles datatypes.JSONSlice[RemitoDetalle] `gorm:"type:json" json:"detalles,omitempty"`
|
||||
|
||||
@@ -11,8 +11,8 @@ type Repuesto struct {
|
||||
Precio float64 `gorm:"not null;type:decimal(10,2)" json:"precio" binding:"required"`
|
||||
StockMinimo int64 `gorm:"not null;type:bigint" json:"stockMinimo" binding:"required"`
|
||||
Descripcion string `gorm:"uniqueIndex;not null;type:varchar(70)" json:"descripcion" binding:"required"`
|
||||
MarcaID uint `gorm:"column:marcaID"`
|
||||
Marca Marca `gorm:"foreignKey:marcaID"`
|
||||
MarcaID uint `gorm:"column:marcaID"`
|
||||
Marca Marca `gorm:"foreignKey:MarcaID" json:"marca"`
|
||||
Aliases datatypes.JSONSlice[string] `gorm:"type:json" json:"aliases,omitempty"`
|
||||
Stocks []Stock `gorm:"foreignKey:RepuestoID" json:"stocks,omitempty"`
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type Reserva struct {
|
||||
|
||||
RepuestoID uint `gorm:"not null;index:idx_reserva_repuesto_almacen" json:"repuesto_id"`
|
||||
Repuesto Repuesto `gorm:"foreignKey:RepuestoID" json:"repuesto,omitempty"`
|
||||
AlmacenID uint `gorm:"not null;index:idx_reserva_repuesto_almacen" json:"almacen_id"`
|
||||
AlmacenID string `gorm:"type:varchar(5);not null;index:idx_reserva_repuesto_almacen" json:"almacen_id"`
|
||||
Almacen Almacen `gorm:"foreignKey:AlmacenID" json:"almacen,omitempty"`
|
||||
Cantidad float64 `gorm:"not null;check:cantidad > 0" json:"cantidad"`
|
||||
Estado EstadoReserva `gorm:"type:varchar(20);not null;default:'activa';index" json:"estado"`
|
||||
|
||||
@@ -12,6 +12,8 @@ type Stock struct {
|
||||
CantidadReservada uint `gorm:"not null:default:0" json:"cantidadReservada"`
|
||||
RepuestoID uint64 `gorm:"index;not null" json:"repuestoId"`
|
||||
Repuesto Repuesto `gorm:"foreignKey:RepuestoID" json:"repuesto"`
|
||||
AlmacenID string `gorm:"type:varchar(5);index" json:"almacenId"`
|
||||
Almacen Almacen `gorm:"foreignKey:AlmacenID" json:"almacen,omitempty"`
|
||||
Observacion string `gorm:"type:varchar(60)" json:"observacion"`
|
||||
|
||||
Movmientos datatypes.JSONSlice[MovimientoStock] `gorm:"type:json" json:"movimientos,omitempty"`
|
||||
|
||||
Reference in new issue
Block a user