Cizz22 11 months ago
parent 51e7924008
commit 553c80d394

@ -7,12 +7,11 @@ from src.models import DefaultMixin, IdentityMixin, TimeStampMixin
class OverhaulScope(Base, DefaultMixin):
__tablename__ = "oh_ms_overhaul_scope"
type = Column(String, nullable=True)
start_date = Column(DateTime(timezone=True))
end_date = Column(DateTime(timezone=True))
type = Column(String, nullable=False) # Changed to non-nullable to match the model
start_date = Column(DateTime(timezone=True), nullable=False) # Made non-nullable to match model
end_date = Column(DateTime(timezone=True), nullable=True) # Already nullable
duration_oh = Column(Integer, nullable=True)
crew_number = Column(Integer, nullable=True, default=1)
status = Column(String, nullable=False, default="upcoming")
status = Column(String, nullable=False, default="Upcoming")
activity_equipments = relationship("OverhaulActivity", lazy="selectin")

@ -8,10 +8,10 @@ from src.models import DefultBase, Pagination
class ScopeBase(DefultBase):
duration_oh: Optional[int] = Field(None, title="Duration OH")
crew_number: Optional[int] = Field(1, title="Crew")
duration_oh: Optional[int] = Field(720, title="Duration OH")
crew_number: Optional[int] = Field(10, title="Crew")
status: Optional[str] = Field("Upcoming")
type: str
type: str = Field(..., title="Type") # Added title
class ScopeCreate(ScopeBase):

@ -12,7 +12,7 @@ from src.utils import time_now
from .model import OverhaulScope
from .schema import ScopeCreate, ScopeUpdate
from .utils import get_material_cost, get_service_cost
from datetime import datetime
async def get(
*, db_session: DbSession, overhaul_session_id: str
@ -35,12 +35,48 @@ async def get_all(*, common, scope_name: Optional[str] = None):
async def create(*, db_session: DbSession, scope_in: ScopeCreate):
"""Creates a new document."""
overhaul_session = OverhaulScope(**scope_in.model_dump())
# Ensure dates are datetime objects
if isinstance(scope_in.start_date, str):
try:
start_date = datetime.fromisoformat(scope_in.start_date.replace('Z', '+00:00'))
except ValueError:
start_date = datetime.strptime(scope_in.start_date, "%Y-%m-%d %H:%M:%S")
else:
start_date = scope_in.start_date
# Handle end_date (which could be None)
end_date = None
if scope_in.end_date:
if isinstance(scope_in.end_date, str):
try:
end_date = datetime.fromisoformat(scope_in.end_date.replace('Z', '+00:00'))
except ValueError:
end_date = datetime.strptime(scope_in.end_date, "%Y-%m-%d %H:%M:%S")
else:
end_date = scope_in.end_date
# Calculate duration in days if both dates are available
duration_days = None
if start_date and end_date:
duration_days = (end_date - start_date).days
# Create the OverhaulScope object with all hardcoded values
overhaul_session = OverhaulScope(
start_date=scope_in.start_date,
end_date=scope_in.end_date,
type=scope_in.type, # Hardcoded type
duration_oh=duration_days, # Hardcoded duration (30 days)
crew_number=scope_in.crew_number, # Hardcoded crew number
status=scope_in.status # Hardcoded status
)
# raise Exception(overhaul_session.start_date)
db_session.add(overhaul_session)
# Need to flush to get the id
await db_session.flush()
scope_name = scope_in.type
# Fix the function call - parameters were in wrong order

Loading…
Cancel
Save