feat(project):add create price for project monitor

This commit is contained in:
shahzeydyfah
2025-01-21 00:44:50 +03:30
parent 3e9f5450e6
commit 7c21ebe551
2 changed files with 28 additions and 0 deletions
+24
View File
@@ -226,3 +226,27 @@ class ProjectRepository(BaseRepository[ProjectModel]):
return res.json()
async def create_project_price(self):
projects = await use_collection(TaskEnv.CLN_PROJECT).find({'monitor.detail.first_amount':{'$exists':1}}).to_list(None)
for project in projects:
sum_status = 0
sum_adjust = 0
status = await use_collection(TaskEnv.CLN_FINANCIAL_STATUS).find({'project_id':project['_id'],'amount':{'$exists':1}}).to_list(None)
if status:
for i in status:
sum_status += i['amount']
adjust = await use_collection(TaskEnv.CLN_FINANCIAL_ADJUST).find({'project_id':project['_id'],'amount':{'$exists':1}}).to_list(None)
if adjust:
for i in adjust:
sum_adjust += i['amount']
price = {
'_id': uuid.uuid4(),
'project_id': project['_id'],
'first_amount': project['monitor']['detail']['first_amount'],
'amount_status':sum_status,
'amount_adjust':sum_adjust
}
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price)