Improve the frontend 4
This commit is contained in:
@@ -90,6 +90,30 @@ class ProcurementPlanRepository(BaseRepository):
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def get_plans_by_tenant(
|
||||
self,
|
||||
tenant_id: uuid.UUID,
|
||||
start_date: Optional[datetime] = None,
|
||||
end_date: Optional[datetime] = None
|
||||
) -> List[ProcurementPlan]:
|
||||
"""Get all procurement plans for a tenant with optional date filters"""
|
||||
conditions = [ProcurementPlan.tenant_id == tenant_id]
|
||||
|
||||
if start_date:
|
||||
conditions.append(ProcurementPlan.created_at >= start_date)
|
||||
if end_date:
|
||||
conditions.append(ProcurementPlan.created_at <= end_date)
|
||||
|
||||
stmt = (
|
||||
select(ProcurementPlan)
|
||||
.where(and_(*conditions))
|
||||
.order_by(desc(ProcurementPlan.created_at))
|
||||
.options(selectinload(ProcurementPlan.requirements))
|
||||
)
|
||||
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def update_plan(self, plan_id: uuid.UUID, tenant_id: uuid.UUID, updates: Dict[str, Any]) -> Optional[ProcurementPlan]:
|
||||
"""Update procurement plan"""
|
||||
plan = await self.get_plan_by_id(plan_id, tenant_id)
|
||||
@@ -204,3 +228,27 @@ class ProcurementRequirementRepository(BaseRepository):
|
||||
count = result.scalar() or 0
|
||||
|
||||
return f"REQ-{count + 1:05d}"
|
||||
|
||||
async def get_requirements_by_tenant(
|
||||
self,
|
||||
tenant_id: uuid.UUID,
|
||||
start_date: Optional[datetime] = None,
|
||||
end_date: Optional[datetime] = None
|
||||
) -> List[ProcurementRequirement]:
|
||||
"""Get all procurement requirements for a tenant with optional date filters"""
|
||||
conditions = [ProcurementPlan.tenant_id == tenant_id]
|
||||
|
||||
if start_date:
|
||||
conditions.append(ProcurementRequirement.created_at >= start_date)
|
||||
if end_date:
|
||||
conditions.append(ProcurementRequirement.created_at <= end_date)
|
||||
|
||||
stmt = (
|
||||
select(ProcurementRequirement)
|
||||
.join(ProcurementPlan)
|
||||
.where(and_(*conditions))
|
||||
.order_by(desc(ProcurementRequirement.created_at))
|
||||
)
|
||||
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
Reference in New Issue
Block a user