added pucks and samples
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
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"
|
||||
@ -19,6 +21,7 @@ class Shipment(Base):
|
||||
proposal = relationship("Proposal", back_populates="shipments")
|
||||
dewars = relationship("Dewar", back_populates="shipment")
|
||||
|
||||
|
||||
class ContactPerson(Base):
|
||||
__tablename__ = "contact_persons"
|
||||
|
||||
@ -30,6 +33,7 @@ class ContactPerson(Base):
|
||||
|
||||
shipments = relationship("Shipment", back_populates="contact_person")
|
||||
|
||||
|
||||
class Address(Base):
|
||||
__tablename__ = "addresses"
|
||||
|
||||
@ -41,14 +45,13 @@ class Address(Base):
|
||||
|
||||
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)
|
||||
number_of_pucks = Column(Integer)
|
||||
number_of_samples = Column(Integer)
|
||||
status = Column(String)
|
||||
ready_date = Column(Date, nullable=True)
|
||||
shipping_date = Column(Date, nullable=True)
|
||||
@ -56,12 +59,22 @@ class Dewar(Base):
|
||||
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")) # Added
|
||||
contact_person_id = Column(Integer, ForeignKey("contact_persons.id")) # Added
|
||||
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"
|
||||
@ -69,4 +82,25 @@ class Proposal(Base):
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
number = Column(String)
|
||||
|
||||
shipments = relationship("Shipment", back_populates="proposal")
|
||||
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")
|
||||
|
Reference in New Issue
Block a user