fix: mlog 数值计算bug

This commit is contained in:
caoqianming 2025-06-13 09:03:43 +08:00
parent dbad152218
commit c02bb6d3db
2 changed files with 13 additions and 12 deletions

View File

@ -316,7 +316,7 @@ class Mlog(CommonADModel):
通过mlogb计算mlog count 合计
"""
mlog = self
if mlog.fill_way == Mlog.MLOG_23:
if mlog.fill_way in [Mlog.MLOG_23, Mlog.MLOG_12]:
a_dict = {
"total_count_use": Sum('count_use'),
"total_count_break": Sum('count_break'),

View File

@ -579,20 +579,21 @@ class MlogSerializer(CustomModelSerializer):
supplier = attrs.get('supplier', None)
if not supplier:
raise ParseError('外协必须选择外协单位')
mtask = attrs.get('mtask', None)
count_notok = 0
for i in attrs:
if 'count_n_' in i:
if attrs[i] < 0:
raise ParseError(f'{attrs[i]}不能小于0')
count_notok = count_notok + attrs[i]
attrs['count_notok'] = count_notok
mlogdefect = attrs.get('mlogdefect', None)
if mlogdefect is None:
count_notok = 0
for i in attrs:
if 'count_n_' in i:
if attrs[i] < 0:
raise ParseError(f'{attrs[i]}不能小于0')
count_notok = count_notok + attrs[i]
attrs['count_notok'] = count_notok
if attrs['count_ok'] < 0:
raise ParseError('合格数量不能小于0')
if attrs['count_real'] >= attrs['count_ok'] + attrs['count_notok']:
pass
else:
raise ParseError('生产数量不能小于合格数量')
if attrs['count_real'] != attrs['count_ok'] + attrs['count_notok']:
raise ParseError('生产数量需等于合格数量+不合格数量')
if mtask:
if mtask.start_date == mtask.end_date:
attrs['handle_date'] = mtask.start_date