From e6e18c6c30bf680b906cdddaa4dced3f8f51f922 Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 15 Oct 2024 09:54:24 +0800 Subject: [PATCH] feat: enm/task nick_name --- apps/enm/tasks.py | 10 +++++----- apps/enm/views.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index d8cb56e1..2dbf1f97 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -117,7 +117,7 @@ def cal_mpointstats_duration(start_time: str, end_time: str, m_code_list=[], cal current_time = start_time while current_time <= end_time: year, month, day, hour = current_time.year, current_time.month, current_time.day, current_time.hour - cal_mpointstats(0, year, month, day, hour, m_code_list, cal_attrs=[]) + cal_mpointstats(0, year, month, day, hour, m_code_list, cal_attrs) current_time += datetime.timedelta(hours=1) @@ -441,11 +441,11 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, if mgroup.product_cost: input_materials_dict[mgroup.product_cost.id] = "P_COST" has_p_cost = True - input_materials_dict.update({i.id: "M" for i in input_materials if i.id not in input_materials_dict}) + input_materials_dict.update({i : "M" for i in input_materials if i not in input_materials_dict}) imaterial_cost_unit = 0 imaterial_data = [] imaterial_data_dict = {} - for mid, mtype in input_materials_dict: + for mid, mtype in input_materials_dict.items(): material = Material.objects.get(id=mid) if type == "hour_s": mps = MpointStat.objects.filter(type="hour_s", mgroup=mgroup, year_s=year_s, month_s=month_s, day_s=day_s, hour=hour, mpoint__material=material) @@ -475,7 +475,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, price_unit = get_price_unit(material, year_s, month_s) cost = amount_consume * price_unit try: - cost_unit = cost / enstat.total_production if has_p_cost is False else enstat.total_production_cost + cost_unit = cost / enstat.total_production if has_p_cost is False else cost / enstat.total_production_cost except ZeroDivisionError: cost_unit = 0 imaterial_cost_unit = imaterial_cost_unit + cost_unit @@ -625,7 +625,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, # 运转时长相关 if type != "hour_s" and "run_hour" in this_cal_attrs: enstat.total_sec_now, enstat.shut_sec = get_total_sec_now_and_shut_sec(enstat) - enstat.run_sec = enstat.total_sec_now - enstat.shut_sec + enstat.run_sec = enstat.total_sec_now - enstat.shut_sec if enstat.total_sec_now - enstat.shut_sec >0 else 0 try: enstat.run_rate = (enstat.run_sec / enstat.total_sec_now) * 100 except ZeroDivisionError: diff --git a/apps/enm/views.py b/apps/enm/views.py index 62699f47..47a95150 100644 --- a/apps/enm/views.py +++ b/apps/enm/views.py @@ -26,7 +26,7 @@ class MpointViewSet(CustomModelViewSet): queryset = Mpoint.objects.all() serializer_class = MpointSerializer - select_related_fields = ["create_by", "belong_dept", "ep_monitored", "ep_belong", "mgroup", "material__name", "material__code", "nickname"] + select_related_fields = ["create_by", "belong_dept", "ep_monitored", "ep_belong", "mgroup", "material"] filterset_fields = { "belong_dept": ["exact"], "ep_monitored": ["exact"], @@ -43,7 +43,7 @@ class MpointViewSet(CustomModelViewSet): "code": ["exact", "contains"], } - search_fields = ["name", "code"] + search_fields = ["name", "code", "nickname", "material__code", "material__name"] ordering = ["create_time", "name", "code"] @transaction.atomic