You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB
Python

from sqlalchemy import UUID, Column, Float, Integer, String, ForeignKey
from src.database.core import Base
from src.models import DefaultMixin, IdentityMixin, TimeStampMixin
from sqlalchemy.orm import relationship
from src.workorder.model import MasterWorkOrder
from sqlalchemy.ext.hybrid import hybrid_property
class ScopeEquipment(Base, DefaultMixin):
__tablename__ = "oh_scope_equip"
assetnum = Column(String, nullable=True)
scope_id = Column(UUID(as_uuid=True), ForeignKey(
'oh_scope.id'), nullable=False)
scope = relationship("Scope", backref="scope_equipments", lazy="raise")
master_equipment = relationship(
"MasterEquipment",
lazy="raise",
primaryjoin="and_(ScopeEquipment.assetnum == foreign(MasterEquipment.assetnum))",
uselist=False # Add this if it's a one-to-one relationship
)
work_orders = relationship("MasterWorkOrder", lazy="selectin",
primaryjoin="and_(ScopeEquipment.assetnum == foreign(MasterWorkOrder.assetnum))")
@hybrid_property
def total_cost(self):
return sum(wo.total_cost_max for wo in self.work_orders if wo.total_cost_max)
class MasterEquipment(Base, DefaultMixin):
__tablename__ = "ms_equipment_master"
assetnum = Column(String, nullable=True)
system_tag = Column(String, nullable=True)
location_tag = Column(String, nullable=True)
name = Column(String, nullable=True)