ssp-fix: org_unit в списке форм
This commit is contained in:
parent
7e9fc08056
commit
772afae276
@ -69,6 +69,7 @@ async def get_forms(
|
|||||||
with_count=True,
|
with_count=True,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
load_org=True,
|
||||||
)
|
)
|
||||||
return BaseListResponse(
|
return BaseListResponse(
|
||||||
result = [
|
result = [
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import typing
|
||||||
|
|
||||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, func
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, func
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
@ -39,9 +40,9 @@ class BudgetForm(Base):
|
|||||||
# updater: Mapped[typing.Optional["AppUser"]] = relationship(
|
# updater: Mapped[typing.Optional["AppUser"]] = relationship(
|
||||||
# "AppUser", back_populates="updated_budget_forms", foreign_keys=[updated_by]
|
# "AppUser", back_populates="updated_budget_forms", foreign_keys=[updated_by]
|
||||||
# )
|
# )
|
||||||
# org_unit: Mapped[typing.Optional["OrgUnit"]] = relationship(
|
org_unit: Mapped[typing.Optional["OrgUnit"]] = relationship(
|
||||||
# "OrgUnit", back_populates="budget_forms"
|
"OrgUnit", #back_populates="budget_forms"
|
||||||
# )
|
)
|
||||||
# budget_lines: Mapped[list["BudgetLine"]] = relationship(
|
# budget_lines: Mapped[list["BudgetLine"]] = relationship(
|
||||||
# "BudgetLine", back_populates="budget_form"
|
# "BudgetLine", back_populates="budget_form"
|
||||||
# )
|
# )
|
||||||
|
|||||||
@ -172,6 +172,15 @@ class FormTypeSchemaEnum(str, enum.Enum):
|
|||||||
FORM_4 = "FORM_4"
|
FORM_4 = "FORM_4"
|
||||||
|
|
||||||
|
|
||||||
|
class OrgUnitSchema(BaseModel):
|
||||||
|
id: int
|
||||||
|
title: str
|
||||||
|
is_active: bool
|
||||||
|
is_ssp: bool
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
from_attributes = True
|
||||||
|
|
||||||
class BudgetFormResponse(BaseModel):
|
class BudgetFormResponse(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
@ -180,6 +189,7 @@ class BudgetFormResponse(BaseModel):
|
|||||||
form_type_code: FormTypeSchemaEnum
|
form_type_code: FormTypeSchemaEnum
|
||||||
year: int
|
year: int
|
||||||
org_unit_id: int
|
org_unit_id: int
|
||||||
|
org_unit: OrgUnitSchema | None = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
|
|||||||
@ -16,6 +16,7 @@ class BudgetFormRepository:
|
|||||||
limit: int | None = None,
|
limit: int | None = None,
|
||||||
org_unit: int | list[int] | None = None,
|
org_unit: int | list[int] | None = None,
|
||||||
with_count: bool = False,
|
with_count: bool = False,
|
||||||
|
load_org: bool = False,
|
||||||
) -> list[BudgetForm] | tuple[int, list[BudgetForm]]:
|
) -> list[BudgetForm] | tuple[int, list[BudgetForm]]:
|
||||||
if with_count:
|
if with_count:
|
||||||
query = select(func.count().over().label("total_count"), BudgetForm)
|
query = select(func.count().over().label("total_count"), BudgetForm)
|
||||||
@ -28,7 +29,13 @@ class BudgetFormRepository:
|
|||||||
else:
|
else:
|
||||||
where.append(BudgetForm.org_unit_id.in_(org_unit))
|
where.append(BudgetForm.org_unit_id.in_(org_unit))
|
||||||
|
|
||||||
query = query.where(*where).order_by(BudgetForm.id)
|
|
||||||
|
query = query.where(*where)
|
||||||
|
if load_org:
|
||||||
|
query = query.options(
|
||||||
|
joinedload(BudgetForm.org_unit)
|
||||||
|
)
|
||||||
|
query = query.order_by(BudgetForm.id)
|
||||||
|
|
||||||
if offset is not None:
|
if offset is not None:
|
||||||
query = query.offset(offset)
|
query = query.offset(offset)
|
||||||
|
|||||||
@ -20,13 +20,15 @@ class BudgetFormService:
|
|||||||
user: AppUser,
|
user: AppUser,
|
||||||
offset: int | None = None,
|
offset: int | None = None,
|
||||||
limit: int | None = None,
|
limit: int | None = None,
|
||||||
with_count: bool = False
|
with_count: bool = False,
|
||||||
|
load_org: bool = False,
|
||||||
) -> list[BudgetForm] | tuple[int, list[BudgetForm]]:
|
) -> list[BudgetForm] | tuple[int, list[BudgetForm]]:
|
||||||
if user.role_id == UserRoleEnum.ADMIN:
|
if user.role_id == UserRoleEnum.ADMIN:
|
||||||
return await self.bf_repo.get_list(
|
return await self.bf_repo.get_list(
|
||||||
offset=offset,
|
offset=offset,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
with_count=with_count,
|
with_count=with_count,
|
||||||
|
load_org=load_org,
|
||||||
)
|
)
|
||||||
user = await self.user_repo.get(
|
user = await self.user_repo.get(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
@ -37,6 +39,7 @@ class BudgetFormService:
|
|||||||
limit=limit,
|
limit=limit,
|
||||||
org_unit=[ou.id for ou in user.org_units],
|
org_unit=[ou.id for ou in user.org_units],
|
||||||
with_count=with_count,
|
with_count=with_count,
|
||||||
|
load_org=load_org,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get(
|
async def get(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user