feat(register status):compact with financial adjust

This commit is contained in:
shahzeydyfah
2026-02-12 13:55:15 +03:30
parent cc7cd9876c
commit 3061b86524
+26 -9
View File
@@ -23,10 +23,16 @@ class RegisterStatusRepository(BaseRepository):
result = await super().create(coding)
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': coding.project_id})
if price and coding.amount_ّfinancial:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': coding.project_id},
{"$inc": {'amount_status': coding.amount_ّfinancial}}
)
if coding.sts ==1:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': coding.project_id},
{"$inc": {'amount_status': coding.amount_ّfinancial}}
)
elif coding.sts == 2:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': coding.project_id},
{"$inc": {'amount_adjust': coding.amount_ّfinancial}}
)
return result
async def update(self, _id: uuid.UUID, _update: RegisterStatusModel):
@@ -41,18 +47,29 @@ class RegisterStatusRepository(BaseRepository):
if _old.amount_ّfinancial != _update.amount_ّfinancial:
change = _update.amount_ّfinancial - _old.amount_ّfinancial
if change != 0 :
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': _update.project_id},
{"$inc": {'amount_status': change}}
)
if _old.sts == 1:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': _update.project_id},
{"$inc": {'amount_status': change}}
)
elif _old.sts == 2:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': _update.project_id},
{"$inc": {'amount_adjust': change}}
)
return result
async def delete(self, _id: uuid.UUID):
_old_dic = await use_collection(TaskEnv.CLN_AUDIT_STATUS).find_one({'_id': _id})
await super().delete(_id)
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': _old_dic['project_id']})
if price and 'amount_status' in price:
if price and _old_dic['sts'] == 1 and 'amount_status' in price:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': _old_dic['project_id']},
{"$inc": {'amount_status': -(_old_dic['amount_ّfinancial'])}}
)
if price and _old_dic['sts'] == 2 and 'amount_adjust' in price:
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
{'project_id': _old_dic['project_id']},
{"$inc": {'amount_adjust': -(_old_dic['amount_ّfinancial'])}}
)
return True