fix: qm task 计算bug
This commit is contained in:
parent
b672581c11
commit
e399e8fa4b
|
@ -8,10 +8,14 @@ def cal_quastat_type(qs, params_o: dict, type: str):
|
|||
params = params_o.copy()
|
||||
v_list = ['belong_dept', 'material', 'testitem', 'year_s', 'month_s', 'day_s']
|
||||
if type == 'month_s':
|
||||
params.pop('day_s')
|
||||
v_list = ['belong_dept', 'material', 'testitem', 'year_s', 'month_s']
|
||||
elif type == 'year_s':
|
||||
params.pop('month_s')
|
||||
params.pop('day_s')
|
||||
v_list = ['belong_dept', 'material', 'testitem', 'year_s']
|
||||
results = qs.filter(**params).values(*v_list).annotate(
|
||||
qs_ = qs.filter(**params).values(*v_list)
|
||||
results = qs_.annotate(
|
||||
avg_val_total=Sum(F('val_avg')*F('num_test')),
|
||||
num_test_1=Sum('num_test'),
|
||||
num_ok_1=Sum('num_ok')).annotate(
|
||||
|
@ -25,11 +29,6 @@ def cal_quastat_type(qs, params_o: dict, type: str):
|
|||
GROUP BY belong_dept_id, material_id, testitem_id
|
||||
"""
|
||||
params['type'] = type
|
||||
if type == 'month_s':
|
||||
params.pop('day_s')
|
||||
elif type == 'year_s':
|
||||
params.pop('month_s')
|
||||
params.pop('day_s')
|
||||
for r1 in results:
|
||||
stat_params = {
|
||||
'val_avg': r1['avg_val_1'],
|
||||
|
@ -47,12 +46,11 @@ def cal_quastat_type(qs, params_o: dict, type: str):
|
|||
@shared_task(base=CustomTask)
|
||||
def cal_quastat(quastatId: str):
|
||||
ins = QuaStat.objects.get(id=quastatId)
|
||||
qs = QuaStat.objects.exclude(Q(val_avg__isnull=True)|Q(num_test__isnull=True)|Q(num_ok__isnull=True))
|
||||
qs = QuaStat.objects.filter(type='sflog').exclude(Q(val_avg__isnull=True)|Q(num_test__isnull=True)|Q(num_ok__isnull=True))
|
||||
params = {
|
||||
'testitem': ins.testitem,
|
||||
'material': ins.material,
|
||||
'belong_dept': ins.belong_dept,
|
||||
'type': 'sflog',
|
||||
'year_s': ins.year_s,
|
||||
'month_s': ins.month_s,
|
||||
'day_s': ins.day_s
|
||||
|
|
Loading…
Reference in New Issue