feat(project):add delay date in update
This commit is contained in:
+25
-16
@@ -16,9 +16,12 @@ from typing import TypeVar, List
|
||||
|
||||
COLLECTION = "project"
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
def __init__(self):
|
||||
super().__init__(collection=COLLECTION, model=ProjectModel)
|
||||
|
||||
def create_code(self, coding: ProjectModel):
|
||||
code = str(coding.counter)
|
||||
print("code1", code)
|
||||
@@ -37,6 +40,7 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
}
|
||||
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})
|
||||
@@ -48,9 +52,18 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
}
|
||||
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}, {'$set':{'first_amount': update.monitor.detail.first_amount}})
|
||||
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).update_one({'project_id': update.id}, {
|
||||
'$set': {'first_amount': update.monitor.detail.first_amount}})
|
||||
return True
|
||||
|
||||
def creat_date_delay(self, coding: ProjectModel):
|
||||
start_date = coding.monitor.detail.date_create_project
|
||||
first_time_months = int(coding.monitor.detail.first_time)
|
||||
new_month = start_date.month + first_time_months
|
||||
new_year = start_date.year + (new_month - 1) // 12
|
||||
new_month = (new_month - 1) % 12 + 1
|
||||
return start_date.replace(year=new_year, month=new_month)
|
||||
|
||||
async def create(self, coding: ProjectModel):
|
||||
coding.counter = 1
|
||||
last_project = await use_collection(COLLECTION).find({}).sort("$natural", -1).to_list(None)
|
||||
@@ -64,12 +77,7 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
coding.has_monitor = True
|
||||
await self.create_report_price(coding)
|
||||
if coding.monitor.detail.date_create_project and coding.monitor.detail.first_time:
|
||||
start_date = coding.monitor.detail.date_create_project
|
||||
first_time_months = int(coding.monitor.detail.first_time)
|
||||
new_month = start_date.month + first_time_months
|
||||
new_year = start_date.year + (new_month - 1) // 12
|
||||
new_month = (new_month - 1) % 12 + 1
|
||||
coding.date_delay = start_date.replace(year=new_year, month=new_month)
|
||||
coding.date_delay = self.creat_date_delay(coding)
|
||||
else:
|
||||
coding.has_monitor = False
|
||||
|
||||
@@ -82,7 +90,6 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
await use_collection(TaskEnv.CLN_PROJECT_AGREEMENT).insert_one(_model.mongo_dict())
|
||||
return await self.get(coding.id)
|
||||
|
||||
|
||||
async def update(self, _id: UUID, update: ProjectModel):
|
||||
old_project = await use_collection(COLLECTION).find_one({"_id": _id})
|
||||
old_project = ProjectModel(**old_project)
|
||||
@@ -97,6 +104,8 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
if update.monitor:
|
||||
update.has_monitor = True
|
||||
await self.update_report_price(update)
|
||||
if update.monitor.detail.date_create_project != old_project.monitor.detail.date_create_project or update.monitor.detail.first_amount != old_project.monitor.detail.first_amount:
|
||||
update.date_delay = self.creat_date_delay(update) + datetime.timedelta(days=update.all_delay_day)
|
||||
update.u_at()
|
||||
await use_collection(COLLECTION).update_one({"_id": _id}, {"$set": update.mongo_dict()})
|
||||
if old_project.design.status_agreement != update.design.status_agreement:
|
||||
@@ -157,7 +166,6 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
}})
|
||||
return True
|
||||
|
||||
|
||||
async def list_project_design(self):
|
||||
project = await use_collection(COLLECTION).find({'monitor': {"$exists": 0}}).to_list(None)
|
||||
return project
|
||||
@@ -198,7 +206,6 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
).init_id().cu_at()
|
||||
await use_collection(TaskEnv.CLN_PROJECT_STS).insert_one(sts_class.mongo_dict())
|
||||
|
||||
|
||||
return True
|
||||
|
||||
async def fetch_delete(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
||||
@@ -223,7 +230,8 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
|
||||
async def get_all(self):
|
||||
url = 'http://api.khanesaziceco.ir/api/api/project/table'
|
||||
headers = {'authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkua2hhbmVzYXppY2Vjby5pclwvYXBpXC9hdXRoXC9sb2dpbiIsImlhdCI6MTcyOTg4MTc2OCwiZXhwIjoxNzMyNDczNzY4LCJuYmYiOjE3Mjk4ODE3NjgsImp0aSI6IjRiUGQ0dW1Wc2ZBSnNFUzUiLCJzdWIiOjEzNiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.LsinrL84iKAd4HaTHmsaDCALXJPwMLegNpeFhlJL0aY'}
|
||||
headers = {
|
||||
'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkua2hhbmVzYXppY2Vjby5pclwvYXBpXC9hdXRoXC9sb2dpbiIsImlhdCI6MTcyOTg4MTc2OCwiZXhwIjoxNzMyNDczNzY4LCJuYmYiOjE3Mjk4ODE3NjgsImp0aSI6IjRiUGQ0dW1Wc2ZBSnNFUzUiLCJzdWIiOjEzNiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.LsinrL84iKAd4HaTHmsaDCALXJPwMLegNpeFhlJL0aY'}
|
||||
data = {"page": 1,
|
||||
"limit": 400,
|
||||
"sort": "_id"
|
||||
@@ -247,15 +255,18 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
|
||||
async def create_project_price(self):
|
||||
|
||||
projects = await use_collection(TaskEnv.CLN_PROJECT).find({'monitor.detail.first_amount':{'$exists':1}}).to_list(None)
|
||||
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)
|
||||
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)
|
||||
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']
|
||||
@@ -267,5 +278,3 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
'amount_adjust': sum_adjust
|
||||
}
|
||||
await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user