Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Grupo-4-LCS-UNGS/back
Browse files Browse the repository at this point in the history
  • Loading branch information
logos914 committed Nov 19, 2024
2 parents 1b86f31 + f9f3f37 commit 9d33f2a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion models/asignacion_repuestos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class AsignacionRepuestos(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
id_mantenimiento: Mapped[int] = mapped_column(ForeignKey('mantenimiento.id'))
id_mantenimiento: Mapped[int] = mapped_column(ForeignKey('mantenimiento.id'), nullable=True)
id_repuesto: Mapped[int] = mapped_column(ForeignKey('repuesto.id'))
cantidad: Mapped[int]
fecha: Mapped[datetime.date] = mapped_column(Date, default=func.now())
Expand Down
12 changes: 7 additions & 5 deletions models/cliente.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column
from extensiones import db

class Cliente(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
cuit: Mapped[int] = mapped_column(unique=True, nullable=False)
nombre: Mapped[str]
direccion: Mapped[str]
email: Mapped[str]
telefono: Mapped[str]
id_operador:Mapped[int] = mapped_column(ForeignKey('usuario.id'), nullable=True)
cuit: Mapped[int] = mapped_column(unique=True)
nombre: Mapped[str] = mapped_column(nullable=True)
direccion: Mapped[str] = mapped_column(nullable=True)
email: Mapped[str] = mapped_column(nullable=True)
telefono: Mapped[str] = mapped_column(nullable=True)

def serialize(self):
return {
Expand Down
10 changes: 5 additions & 5 deletions models/mantenimiento.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class Mantenimiento(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
id_vehiculo: Mapped[int] = mapped_column(ForeignKey('vehiculo.id'))
fecha_inicio: Mapped[datetime.date] = mapped_column(Date)
fecha_fin: Mapped[datetime.date] = mapped_column(Date)
estado: Mapped[str]
descripcion: Mapped[str]
tipo: Mapped[str]
fecha_inicio: Mapped[datetime.date] = mapped_column(Date, nullable=True)
fecha_fin: Mapped[datetime.date] = mapped_column(Date, nullable=True)
estado: Mapped[str] = mapped_column(nullable=True)
descripcion: Mapped[str] = mapped_column(nullable=True)
tipo: Mapped[str] = mapped_column(nullable=True)
vehiculo: Mapped['Vehiculo'] = relationship('Vehiculo', backref='mantenimientos')

def serialize(self):
Expand Down
2 changes: 1 addition & 1 deletion models/marca_vehiculo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class MarcaVehiculo(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
nombre: Mapped[str] = mapped_column(unique=True, nullable=False)
logo: Mapped[str]
logo: Mapped[str] = mapped_column(nullable=True)

def serialize(self):
return {
Expand Down
2 changes: 1 addition & 1 deletion models/orden_compra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class OrdenCompra(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
id_repuesto: Mapped[int] = mapped_column(ForeignKey('repuesto.id'))
id_proveedor: Mapped[int] = mapped_column(ForeignKey('proveedor.id'))
id_proveedor: Mapped[int] = mapped_column(ForeignKey('proveedor.id'), nullable=True)
cantidad: Mapped[int]
estado: Mapped[str]
repuesto: Mapped['Repuesto'] = relationship('Repuesto', backref='ordenes_compra')
Expand Down
1 change: 1 addition & 0 deletions models/proveedor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Proveedor(db.Model):
nombre: Mapped[str]
direccion: Mapped[str]
telefono: Mapped[str]
email: Mapped[str]
cuit: Mapped[str] = mapped_column(unique=True, nullable=False)

def serialize(self):
Expand Down
9 changes: 4 additions & 5 deletions models/vehiculo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
class Vehiculo(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
id_modelo: Mapped[int] = mapped_column(ForeignKey('modelo_vehiculo.id'))
id_operador:Mapped[int] = mapped_column(ForeignKey('usuario.id'))
id_cliente: Mapped[int] = mapped_column(ForeignKey('cliente.id'))
id_operador:Mapped[int] = mapped_column(ForeignKey('usuario.id'), nullable=True)
matricula: Mapped[str] = mapped_column(unique=True, nullable=False)
id_traccar: Mapped[int]
estado: Mapped[str]
id_traccar: Mapped[int] = mapped_column(nullable=True)
estado: Mapped[str] = mapped_column(nullable=True)
modelo: Mapped['ModeloVehiculo'] = relationship('ModeloVehiculo', backref='vehiculos')
operador: Mapped['Usuario'] = relationship('Usuario', backref='vehiculo')
cliente: Mapped['Cliente'] = relationship('Cliente', backref='vehiculo_asignado')
kilometraje:Mapped[int]
kilometraje:Mapped[int] = mapped_column(nullable=True)

def serialize(self):
return {
Expand Down
7 changes: 4 additions & 3 deletions tablas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CREATE TABLE vehiculo (
id serial,
id_modelo int,
id_operador int,
id_cliente int,
matricula text UNIQUE NOT NULL,
id_traccar int,
estado text
Expand Down Expand Up @@ -104,6 +103,7 @@ CREATE TABLE bitacora_asig_operador (

CREATE TABLE cliente (
id serial,
id_operador int,
cuit text UNIQUE NOT NULL,
nombre text,
direccion text,
Expand All @@ -130,10 +130,11 @@ CREATE TABLE bitacora_asig_cliente (
tipo text
);

ALTER TABLE cliente ADD CONSTRAINT cliente_pk PRIMARY KEY (id);

ALTER TABLE usuario ADD CONSTRAINT usuario_pk PRIMARY KEY (id);

ALTER TABLE cliente ADD CONSTRAINT cliente_pk PRIMARY KEY (id);
ALTER TABLE cliente ADD CONSTRAINT cliente_id_operador_fk FOREIGN KEY (id_operador) REFERENCES usuario(id);

ALTER TABLE proveedor ADD CONSTRAINT proveedor_pk PRIMARY KEY (id);

ALTER TABLE marca_vehiculo ADD CONSTRAINT marca_vehiculo_pk PRIMARY KEY (id);
Expand Down
22 changes: 1 addition & 21 deletions triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,4 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER actualizar_bitacora_operador_trg
AFTER UPDATE ON vehiculo
FOR EACH ROW
EXECUTE FUNCTION actualizar_bitacora_operador();

CREATE OR REPLACE FUNCTION actualizar_bitacora_cliente() RETURNS TRIGGER AS $$
DECLARE
BEGIN
IF NEW.id_cliente IS NOT NULL THEN
INSERT INTO bitacora_asig_cliente
(id_operador, id_cliente, id_vehiculo, fecha, tipo)
VALUES (NEW.id_operador, NEW.id_cliente, NEW.id, NOW(), 'ASIGNACION');
ELSIF OLD.id_cliente IS NOT NULL THEN
INSERT INTO bitacora_asig_cliente
(id_operador, id_cliente, id_vehiculo, fecha, tipo)
VALUES (NEW.id_operador, OLD.id_cliente, NEW.id, NOW(), 'DESASIGNACION');
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER actualizar_bitacora_cliente_trg
AFTER UPDATE ON vehiculo
FOR EACH ROW
EXECUTE FUNCTION actualizar_bitacora_cliente();
EXECUTE FUNCTION actualizar_bitacora_operador();

0 comments on commit 9d33f2a

Please sign in to comment.