108 lines
3.5 KiB
Python
108 lines
3.5 KiB
Python
from sqlalchemy import Column, Integer, String, Date, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from app.database import Base
|
|
from app.calculations import calculate_number_of_pucks, calculate_number_of_samples
|
|
|
|
|
|
class Shipment(Base):
|
|
__tablename__ = "shipments"
|
|
|
|
shipment_id = Column(String, primary_key=True, index=True)
|
|
shipment_name = Column(String, index=True)
|
|
shipment_date = Column(Date)
|
|
shipment_status = Column(String)
|
|
comments = Column(String(200), nullable=True)
|
|
contact_person_id = Column(Integer, ForeignKey("contact_persons.id"))
|
|
return_address_id = Column(Integer, ForeignKey("addresses.id"))
|
|
proposal_id = Column(Integer, ForeignKey('proposals.id'), nullable=True)
|
|
|
|
contact_person = relationship("ContactPerson", back_populates="shipments")
|
|
return_address = relationship("Address", back_populates="shipments")
|
|
proposal = relationship("Proposal", back_populates="shipments")
|
|
dewars = relationship("Dewar", back_populates="shipment")
|
|
|
|
|
|
class ContactPerson(Base):
|
|
__tablename__ = "contact_persons"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
firstname = Column(String)
|
|
lastname = Column(String)
|
|
phone_number = Column(String)
|
|
email = Column(String)
|
|
|
|
shipments = relationship("Shipment", back_populates="contact_person")
|
|
|
|
|
|
class Address(Base):
|
|
__tablename__ = "addresses"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
street = Column(String)
|
|
city = Column(String)
|
|
zipcode = Column(String)
|
|
country = Column(String)
|
|
|
|
shipments = relationship("Shipment", back_populates="return_address")
|
|
|
|
|
|
class Dewar(Base):
|
|
__tablename__ = "dewars"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
dewar_name = Column(String)
|
|
tracking_number = Column(String)
|
|
status = Column(String)
|
|
ready_date = Column(Date, nullable=True)
|
|
shipping_date = Column(Date, nullable=True)
|
|
arrival_date = Column(Date, nullable=True)
|
|
returning_date = Column(Date, nullable=True)
|
|
qrcode = Column(String)
|
|
shipment_id = Column(String, ForeignKey("shipments.shipment_id"))
|
|
return_address_id = Column(Integer, ForeignKey("addresses.id"))
|
|
contact_person_id = Column(Integer, ForeignKey("contact_persons.id"))
|
|
|
|
shipment = relationship("Shipment", back_populates="dewars")
|
|
return_address = relationship("Address")
|
|
contact_person = relationship("ContactPerson")
|
|
pucks = relationship("Puck", back_populates="dewar")
|
|
|
|
@property
|
|
def number_of_pucks(self) -> int:
|
|
return calculate_number_of_pucks(self)
|
|
|
|
@property
|
|
def number_of_samples(self) -> int:
|
|
return calculate_number_of_samples(self)
|
|
|
|
|
|
class Proposal(Base):
|
|
__tablename__ = "proposals"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
number = Column(String)
|
|
|
|
shipments = relationship("Shipment", back_populates="proposal")
|
|
|
|
|
|
class Puck(Base):
|
|
__tablename__ = 'pucks'
|
|
|
|
id = Column(String, primary_key=True)
|
|
puck_name = Column(String)
|
|
puck_type = Column(String)
|
|
puck_location_in_dewar = Column(Integer)
|
|
dewar_id = Column(String, ForeignKey('dewars.id')) # Note: changed to String
|
|
|
|
positions = relationship("Sample", back_populates="puck")
|
|
dewar = relationship("Dewar", back_populates="pucks")
|
|
|
|
|
|
class Sample(Base):
|
|
__tablename__ = 'samples'
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
sample_name = Column(String)
|
|
puck_id = Column(Integer, ForeignKey('pucks.id'))
|
|
puck = relationship("Puck", back_populates="positions")
|