From 3b349bf0182048e4e13b2a9411df46931c74cd4f Mon Sep 17 00:00:00 2001 From: shahzeydyfah Date: Sun, 19 Jan 2025 00:04:33 +0330 Subject: [PATCH] feat(project):add CLN_PROJECT_PRICE_REPORT --- app/repositories/project.py | 40 ++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/app/repositories/project.py b/app/repositories/project.py index 90b3ab7..c1d4970 100644 --- a/app/repositories/project.py +++ b/app/repositories/project.py @@ -27,6 +27,28 @@ class ProjectRepository(BaseRepository[ProjectModel]): code = coding.design.nature + coding.design.type + code return code + async def create_report_price(self, _inp: ProjectModel): + if _inp.monitor and _inp.monitor.detail and _inp.monitor.detail.first_amount: + price = { + '_id': uuid.uuid4(), + 'project_id': _inp.id, + 'first_amount': _inp.monitor.detail.first_amount + } + await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) + return True + async def update_report_price(self,update:ProjectModel): + if update.monitor and update.monitor.detail and update.monitor.detail.first_amount: + price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': update.id}) + if not price: + price = { + '_id': uuid.uuid4(), + 'project_id': update.id, + 'first_amount': update.monitor.detail.first_amount + } + await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) + else: + await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one({'project_id': update.id}, {'first_amount': update.monitor.detail.first_amount}) + return True async def create(self,coding:ProjectModel): coding.counter = 1 @@ -39,13 +61,7 @@ class ProjectRepository(BaseRepository[ProjectModel]): if coding.monitor: coding.monitor.code = 'S'+code coding.has_monitor = True - if coding.monitor.detail and coding.monitor.detail.first_amount : - price = { - '_id': uuid.uuid4(), - 'project_id': coding.id, - 'first_amount': coding.monitor.detail.first_amount - } - await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) + await self.create_report_price(coding) else: coding.has_monitor = False @@ -66,6 +82,16 @@ class ProjectRepository(BaseRepository[ProjectModel]): update.monitor.code = 'S' + code if update.monitor: update.has_monitor = True + if update.monitor.detail and update.monitor.detail.first_amount: + price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id':_id}) + if not price: + price = { + '_id': uuid.uuid4(), + 'project_id': _id, + 'first_amount': update.monitor.detail.first_amount + } + await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) + update.u_at() await use_collection(COLLECTION).update_one({"_id":_id},{"$set":update.mongo_dict()}) return await self.get(_id)