From bdbfb95d73af39b13f2046408e383ab6396bf40e Mon Sep 17 00:00:00 2001 From: martsforever Date: Sat, 23 Aug 2025 17:28:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=87=BA=E6=9D=A5=E6=8A=A5=E9=94=80=E5=8D=95=E7=9A=84=E5=B7=AE?= =?UTF-8?q?=E6=97=85=E8=B4=B9=E7=94=A8=E5=AD=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/ReimburseModel.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/model/ReimburseModel.py b/app/model/ReimburseModel.py index 542ad37..47d84b0 100644 --- a/app/model/ReimburseModel.py +++ b/app/model/ReimburseModel.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, List from pydantic import computed_field from sqlalchemy.orm import selectinload @@ -6,6 +6,7 @@ from sqlmodel import Field, Relationship, select from app.model.BasicModel import BasicModel from app.model.ProjectModel import ProjectModel +from app.model.ReimburseTravelModel import ReimburseTravelModel from app.utils.create_module_service import create_model_service @@ -16,6 +17,8 @@ class ReimburseModel(BasicModel, table=True): remarks: str = Field(default=None, description="备注信息") amount: float = Field(default=None, description="报销金额") + # /*---------------------------------------project-------------------------------------------*/ + proj_id: str = Field( default=None, description="所属项目id", @@ -40,12 +43,34 @@ class ReimburseModel(BasicModel, table=True): def project(self, value: Optional[ProjectModel]) -> None: pass + # /*---------------------------------------travel_list-------------------------------------------*/ + + # 新增:与ReimburseTravelModel的一对多关系 + travel_list_rel: Optional[List["ReimburseTravelModel"]] = Relationship( + sa_relationship_kwargs={ + "foreign_keys": "ReimburseTravelModel.reimburse_id", + "primaryjoin": "ReimburseModel.id == ReimburseTravelModel.reimburse_id", + } + ) + + @computed_field + @property + def travel_list(self) -> Optional[List["ReimburseTravelModel"]]: + return self.travel_list_rel + + @travel_list.setter + def travel_list(self, value: Optional[List["ReimburseTravelModel"]]) -> None: + pass + ReimburseService = create_model_service( Cls=ReimburseModel, custom_query=lambda: select(ReimburseModel) .options( selectinload(ReimburseModel.proj_rel). - selectinload(ProjectModel.leader) + selectinload(ProjectModel.leader), + + # 新增:预加载差旅明细 + selectinload(ReimburseModel.travel_list_rel) ) )