feat(register status):compact with financial adjust
This commit is contained in:
@@ -23,10 +23,16 @@ class RegisterStatusRepository(BaseRepository):
|
|||||||
result = await super().create(coding)
|
result = await super().create(coding)
|
||||||
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': coding.project_id})
|
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': coding.project_id})
|
||||||
if price and coding.amount_ّfinancial:
|
if price and coding.amount_ّfinancial:
|
||||||
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
if coding.sts ==1:
|
||||||
{'project_id': coding.project_id},
|
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
||||||
{"$inc": {'amount_status': coding.amount_ّfinancial}}
|
{'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
|
return result
|
||||||
|
|
||||||
async def update(self, _id: uuid.UUID, _update: RegisterStatusModel):
|
async def update(self, _id: uuid.UUID, _update: RegisterStatusModel):
|
||||||
@@ -41,18 +47,29 @@ class RegisterStatusRepository(BaseRepository):
|
|||||||
if _old.amount_ّfinancial != _update.amount_ّfinancial:
|
if _old.amount_ّfinancial != _update.amount_ّfinancial:
|
||||||
change = _update.amount_ّfinancial - _old.amount_ّfinancial
|
change = _update.amount_ّfinancial - _old.amount_ّfinancial
|
||||||
if change != 0 :
|
if change != 0 :
|
||||||
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
if _old.sts == 1:
|
||||||
{'project_id': _update.project_id},
|
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
||||||
{"$inc": {'amount_status': change}}
|
{'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
|
return result
|
||||||
async def delete(self, _id: uuid.UUID):
|
async def delete(self, _id: uuid.UUID):
|
||||||
_old_dic = await use_collection(TaskEnv.CLN_AUDIT_STATUS).find_one({'_id': _id})
|
_old_dic = await use_collection(TaskEnv.CLN_AUDIT_STATUS).find_one({'_id': _id})
|
||||||
await super().delete(_id)
|
await super().delete(_id)
|
||||||
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': _old_dic['project_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(
|
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
||||||
{'project_id': _old_dic['project_id']},
|
{'project_id': _old_dic['project_id']},
|
||||||
{"$inc": {'amount_status': -(_old_dic['amount_ّfinancial'])}}
|
{"$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
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user