From 3d792554b7aafe995f8dd46ece45207bf7745e71 Mon Sep 17 00:00:00 2001 From: shahzeydyfah Date: Thu, 22 May 2025 15:11:29 +0330 Subject: [PATCH] fix(monitor physical):add before in last --- app/models/monito_physical_progress.py | 1 + app/repositories/monitor_physical_progress.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/monito_physical_progress.py b/app/models/monito_physical_progress.py index dde3449..c8a2500 100644 --- a/app/models/monito_physical_progress.py +++ b/app/models/monito_physical_progress.py @@ -24,5 +24,6 @@ class PhysicalProgressModel(BaseModel): class LastRecord(pydantic.BaseModel): project_id:Optional[uuid.UUID] = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد") date_at:Optional[datetime.datetime] = Field(description='تاریخ وارد شده') + id:Optional[uuid.UUID] = Field(description='شناسه رکورد') diff --git a/app/repositories/monitor_physical_progress.py b/app/repositories/monitor_physical_progress.py index 15677e9..b0ba940 100644 --- a/app/repositories/monitor_physical_progress.py +++ b/app/repositories/monitor_physical_progress.py @@ -34,10 +34,16 @@ class PhysicalProgressRepository(BaseRepository): async def last_record(self, _inp: LastRecord): send = {'month': {}, 'three_month': {}, 'before':{}} - before = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({ - 'project_id': _inp.project_id, - 'date_at': {'$lt': _inp.date_at} - }).sort("$natural", -1).to_list(None) + if _inp.id: + find_record = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find_one({"_id":_inp.id}) + if _inp.id: + before = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({ + 'project_id': _inp.project_id, + 'created_at': {'$lt': find_record['created_at']}}).sort("$natural", -1).to_list(None) + else: + before = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({ + 'project_id': _inp.project_id, + }).sort("$natural", -1).to_list(None) if before: send['before'] = before[0] last = await self.search_last(TaskEnv.CLN_MONITOR_PYSICAL, _inp, 35, 25)