From 9c2e9409945fa0ffba2b393685eeab937482267f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 29 Dec 2024 00:01:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20get=5Fmgroup=5Fgoals=20=E5=8F=AF?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E5=8E=BB=E5=B9=B4=E6=95=B0=E6=8D=AE3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mtm/services.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/mtm/services.py b/apps/mtm/services.py index 47f7ab60..dd9a6b74 100644 --- a/apps/mtm/services.py +++ b/apps/mtm/services.py @@ -9,6 +9,7 @@ from apps.wf.models import Ticket from django.db.models import Sum from typing import List from apps.utils.snowflake import idWorker +from django.utils import timezone def cal_material_count(materialId_list: List[str]=None): """ @@ -47,14 +48,16 @@ def get_mgroup_goals(mgroupId, year, reload=False): mgroup_goals = {} if not goals.exists(): # 尝试寻找去年的 - goals_last_year = Goal.objects.filter(mgroup__id=mgroupId, year=year) + goals_last_year = Goal.objects.filter(mgroup__id=mgroupId, year=year-1) if goals_last_year.exists(): for goal in goals_last_year: # 复用去年的数据创建 goal.id = idWorker.get_id() - goal.year = year + 1 + goal.create_time = timezone.now() + goal.update_time = goal.create_time + goal.year = year goal.save() - goals = Goal.objects.get(mgroup__id=mgroupId, year=year) + goals = Goal.objects.filter(mgroup__id=mgroupId, year=year) for goal in goals: mgroup_goals[f'{goal.goal_cate.code}_year'] = goal.goal_val for i in range(12):