add system and subsystem

main
Cizz22 10 months ago
parent 9a85abd65e
commit 4d165556ba

@ -121,7 +121,7 @@
"errorLens.enabled": false,
"[python]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.defaultFormatter": "mikoz.black-py",
"editor.formatOnType": false
},
"python.languageServer": "Jedi",

@ -107,6 +107,9 @@ def get_overhaul_system_components():
}
# async def get(*, db_session: DbSession, scope_id: str) -> Optional[Scope]:
# """Returns a document based on the given document id."""
# query = Select(Scope).filter(Scope.id == scope_id)

@ -13,6 +13,7 @@ from src.database.service import CommonParameters, search_filter_sort_paginate
from src.overhaul_activity.utils import get_material_cost, get_service_cost
from src.overhaul_scope.model import OverhaulScope
from src.overhaul_scope.service import get as get_session
from src.scope_equipment.model import MasterEquipment
from .model import OverhaulActivity
from .schema import (OverhaulActivityCreate, OverhaulActivityRead,
@ -36,6 +37,7 @@ async def get(
return result.scalar()
async def get_all(
*,
common: CommonParameters,
@ -46,7 +48,7 @@ async def get_all(
query = (
Select(OverhaulActivity)
.where(OverhaulActivity.overhaul_scope_id == overhaul_session_id)
.options(joinedload(OverhaulActivity.equipment))
.options(joinedload(OverhaulActivity.equipment).options(joinedload(MasterEquipment.parent).options(joinedload(MasterEquipment.parent))))
.options(selectinload(OverhaulActivity.overhaul_scope))
)
@ -62,6 +64,8 @@ async def get_all(
results = await search_filter_sort_paginate(model=query, **common)
##raise Exception(results['items'][0].equipment.parent.__dict__)
return results
@ -69,7 +73,7 @@ async def get_all_by_session_id(*, db_session: DbSession, overhaul_session_id):
query = (
Select(OverhaulActivity)
.where(OverhaulActivity.overhaul_scope_id == overhaul_session_id)
.options(joinedload(OverhaulActivity.equipment))
.options(joinedload(OverhaulActivity.equipment).options(MasterEquipment.parent).options(MasterEquipment.parent))
.options(selectinload(OverhaulActivity.overhaul_scope))
)

@ -147,6 +147,7 @@ async def get_overview_overhaul(*, db_session: DbSession):
# Use first() instead of scalar_one_or_none()
ongoing_result = ongoing_result.first()
if ongoing_result:
ongoing_overhaul, equipment_count = ongoing_result # Unpack the result tuple
return {

@ -27,7 +27,13 @@ class ScopeEquipment(Base, DefaultMixin):
class MasterEquipment(Base, DefaultMixin):
__tablename__ = "ms_equipment_master"
parent_id = Column(UUID(as_uuid=True), nullable=True)
id = Column(UUID(as_uuid=True), primary_key=True, index=True)
parent_id = Column(
UUID(as_uuid=True),
ForeignKey("ms_equipment_master.id", ondelete="CASCADE"),
nullable=True,
)
assetnum = Column(String, nullable=True)
system_tag = Column(String, nullable=True)
location_tag = Column(String, nullable=True)
@ -37,6 +43,7 @@ class MasterEquipment(Base, DefaultMixin):
)
equipment_tree = relationship("MasterEquipmentTree", backref="master_equipments")
parent = relationship("MasterEquipment", remote_side=[id], lazy="selectin")
class MasterEquipmentTree(Base, DefaultMixin):

@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Optional
from typing import List, Optional, ForwardRef
from uuid import UUID
from pydantic import Field, computed_field, field_validator, validator
@ -40,11 +40,15 @@ class ScopeEquipmentRead(ScopeEquipmentBase):
class ScopeEquipmentPagination(Pagination):
items: List[ScopeEquipmentRead] = []
EquipmentMasterReadRef = ForwardRef("MasterEquipmentRead")
class MasterEquipmentRead(DefultBase):
assetnum: Optional[str] = Field(None, title="Asset Number")
location_tag: str
location_tag: Optional[str] = Field(None, title="Location Tag")
name: str
parent_id: Optional[UUID]
parent: Optional[EquipmentMasterReadRef] = Field(None) # type: ignore
class MasterEquipmentPagination(Pagination):

Loading…
Cancel
Save