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