feat: enm/task nick_name

This commit is contained in:
zty 2024-10-15 09:54:24 +08:00
parent 5203719023
commit e6e18c6c30
2 changed files with 7 additions and 7 deletions

View File

@ -117,7 +117,7 @@ def cal_mpointstats_duration(start_time: str, end_time: str, m_code_list=[], cal
current_time = start_time current_time = start_time
while current_time <= end_time: while current_time <= end_time:
year, month, day, hour = current_time.year, current_time.month, current_time.day, current_time.hour 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) 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: if mgroup.product_cost:
input_materials_dict[mgroup.product_cost.id] = "P_COST" input_materials_dict[mgroup.product_cost.id] = "P_COST"
has_p_cost = True 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_cost_unit = 0
imaterial_data = [] imaterial_data = []
imaterial_data_dict = {} imaterial_data_dict = {}
for mid, mtype in input_materials_dict: for mid, mtype in input_materials_dict.items():
material = Material.objects.get(id=mid) material = Material.objects.get(id=mid)
if type == "hour_s": 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) 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) price_unit = get_price_unit(material, year_s, month_s)
cost = amount_consume * price_unit cost = amount_consume * price_unit
try: 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: except ZeroDivisionError:
cost_unit = 0 cost_unit = 0
imaterial_cost_unit = imaterial_cost_unit + cost_unit 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: 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.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: try:
enstat.run_rate = (enstat.run_sec / enstat.total_sec_now) * 100 enstat.run_rate = (enstat.run_sec / enstat.total_sec_now) * 100
except ZeroDivisionError: except ZeroDivisionError:

View File

@ -26,7 +26,7 @@ class MpointViewSet(CustomModelViewSet):
queryset = Mpoint.objects.all() queryset = Mpoint.objects.all()
serializer_class = MpointSerializer 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 = { filterset_fields = {
"belong_dept": ["exact"], "belong_dept": ["exact"],
"ep_monitored": ["exact"], "ep_monitored": ["exact"],
@ -43,7 +43,7 @@ class MpointViewSet(CustomModelViewSet):
"code": ["exact", "contains"], "code": ["exact", "contains"],
} }
search_fields = ["name", "code"] search_fields = ["name", "code", "nickname", "material__code", "material__name"]
ordering = ["create_time", "name", "code"] ordering = ["create_time", "name", "code"]
@transaction.atomic @transaction.atomic