启动与授权-初步优化
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Sequence
|
||||
from sqlalchemy import and_, func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.fee_attachment import FeeAttachment
|
||||
from app.models.attachment import Attachment
|
||||
from app.models.special_expense import SpecialExpense
|
||||
from app.models.site import Site
|
||||
from app.schemas.special_expense import SpecialExpenseCreate, SpecialExpenseUpdate
|
||||
@@ -48,7 +48,8 @@ async def list_special_expenses(
|
||||
date_from: date | None = None,
|
||||
date_to: date | None = None,
|
||||
) -> Sequence[tuple[SpecialExpense, str | None, int]]:
|
||||
attachment_count = func.count(FeeAttachment.id).label("attachments_count")
|
||||
attachment_count = func.count(Attachment.id).label("attachments_count")
|
||||
attachment_types = ["special_expense_voucher", "special_expense_invoice", "special_expense_other"]
|
||||
stmt = (
|
||||
select(
|
||||
SpecialExpense,
|
||||
@@ -57,11 +58,11 @@ async def list_special_expenses(
|
||||
)
|
||||
.outerjoin(Site, Site.id == SpecialExpense.center_id)
|
||||
.outerjoin(
|
||||
FeeAttachment,
|
||||
Attachment,
|
||||
and_(
|
||||
FeeAttachment.entity_type == "special_expense",
|
||||
FeeAttachment.entity_id == SpecialExpense.id,
|
||||
FeeAttachment.is_deleted.is_(False),
|
||||
Attachment.entity_type.in_(attachment_types),
|
||||
Attachment.entity_id == SpecialExpense.id,
|
||||
Attachment.is_deleted.is_(False),
|
||||
),
|
||||
)
|
||||
.where(SpecialExpense.project_id == project_id)
|
||||
|
||||
Reference in New Issue
Block a user