feat(register status):compact with financial status
This commit is contained in:
@@ -48,3 +48,5 @@ class RegisterStatusModel(BaseModel):
|
||||
amount: Optional[AmountStatus] = Field(description="مبالغ")
|
||||
related_to_number_start:Optional[int] = Field(description="شماره صورت وضعیت مرتبط")
|
||||
related_to_number_end:Optional[int] = Field(description="شماره صورت وضعیت مرتبط")
|
||||
date_at: Optional[datetime.datetime] = Field(description='تاریخ پرداخت')
|
||||
amount_ّfinancial: Optional[int] = Field(description='مبلغ صورت وضعیت در قسمت مالی')
|
||||
|
||||
@@ -19,3 +19,40 @@ class RegisterStatusRepository(BaseRepository):
|
||||
async def get_list(self,project_id:uuid.UUID):
|
||||
list_status = await use_collection(TaskEnv.CLN_AUDIT_STATUS).find({"project_id":project_id}).to_list(None)
|
||||
return list_status
|
||||
async def create(self, coding: RegisterStatusModel):
|
||||
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}}
|
||||
)
|
||||
return result
|
||||
|
||||
async def update(self, _id: uuid.UUID, _update: RegisterStatusModel):
|
||||
_old_dic = await use_collection(TaskEnv.CLN_AUDIT_STATUS).find_one({'_id':_id})
|
||||
change = 0
|
||||
result = await super().update(_id, _update)
|
||||
price = await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).find_one({'project_id': _update.project_id})
|
||||
if price:
|
||||
_old = RegisterStatusModel(**_old_dic)
|
||||
if 'amount_ّfinancial' not in _old_dic and _update.amount_ّfinancial:
|
||||
change = _update.amount_ّfinancial
|
||||
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}}
|
||||
)
|
||||
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:
|
||||
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one(
|
||||
{'project_id': _old_dic['project_id']},
|
||||
{"$inc": {'amount_status': -(_old_dic['amount_ّfinancial'])}}
|
||||
)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user