feat(project):add CLN_PROJECT_PRICE_REPORT

This commit is contained in:
shahzeydyfah
2025-01-19 00:04:33 +03:30
parent 6998989e78
commit 3b349bf018
+33 -7
View File
@@ -27,6 +27,28 @@ class ProjectRepository(BaseRepository[ProjectModel]):
code = coding.design.nature + coding.design.type + code code = coding.design.nature + coding.design.type + code
return 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): async def create(self,coding:ProjectModel):
coding.counter = 1 coding.counter = 1
@@ -39,13 +61,7 @@ class ProjectRepository(BaseRepository[ProjectModel]):
if coding.monitor: if coding.monitor:
coding.monitor.code = 'S'+code coding.monitor.code = 'S'+code
coding.has_monitor = True coding.has_monitor = True
if coding.monitor.detail and coding.monitor.detail.first_amount : await self.create_report_price(coding)
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)
else: else:
coding.has_monitor = False coding.has_monitor = False
@@ -66,6 +82,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
update.monitor.code = 'S' + code update.monitor.code = 'S' + code
if update.monitor: if update.monitor:
update.has_monitor = True 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() update.u_at()
await use_collection(COLLECTION).update_one({"_id":_id},{"$set":update.mongo_dict()}) await use_collection(COLLECTION).update_one({"_id":_id},{"$set":update.mongo_dict()})
return await self.get(_id) return await self.get(_id)