diff --git a/apps/wpm/migrations/0131_mlog_clear_defect.py b/apps/wpm/migrations/0131_mlog_clear_defect.py new file mode 100644 index 00000000..c7988230 --- /dev/null +++ b/apps/wpm/migrations/0131_mlog_clear_defect.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0130_handover_clear_defect'), + ] + + operations = [ + migrations.AddField( + model_name='mlog', + name='clear_defect', + field=models.BooleanField(default=False, verbose_name='合格B类缺陷不拆批'), + ), + ] diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 1dcf1955..e5c4e513 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -242,6 +242,7 @@ class Mlog(CommonADModel): reminder_interval_list = models.JSONField('提醒间隔', default=list, blank=True) stored_mgroup = models.BooleanField('入库到工段', default=False) stored_notok = models.BooleanField('不合格品是否已入库', default=False) + clear_defect = models.BooleanField('合格B类缺陷不拆批', default=False) route = models.ForeignKey(Route, verbose_name='生产路线', on_delete=models.SET_NULL, null=True, blank=True) mtask = models.ForeignKey( Mtask, verbose_name='关联任务', on_delete=models.CASCADE, null=True, blank=True, related_name='mlog_mtask') diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 0ff39357..42e61aae 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -731,7 +731,7 @@ class MlogInitSerializer(CustomModelSerializer): class MlogChangeSerializer(CustomModelSerializer): class Meta: model = Mlog - fields = ['id', 'work_start_time', 'work_end_time', 'handle_user', 'note', 'oinfo_json', 'test_file', 'test_user', 'test_time', 'equipment', "team"] + fields = ['id', 'work_start_time', 'work_end_time', 'handle_user', 'note', 'oinfo_json', 'test_file', 'test_user', 'test_time', 'equipment', "team", "clear_defect"] def update(self, instance, validated_data): work_start_time = validated_data.get('work_start_time', None) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 52901842..23956746 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -282,9 +282,13 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): mlogb_out_qs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False) + clear_defect = bool(mlog.clear_defect) if mlogb_out_qs.exists(): mlogb_out_qs = mlogb_out_qs.filter(need_inout=True) - m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok_full if mo.count_ok_full is not None else mo.count_ok, mlog.count_real_eweight, None, mo) for mo in mlogb_out_qs.all()] + if clear_defect: + m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight, None, mo) for mo in mlogb_out_qs.all()] + else: + m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok_full if mo.count_ok_full is not None else mo.count_ok, mlog.count_real_eweight, None, mo) for mo in mlogb_out_qs.all()] if stored_notok: for item in mlogb_out_qs: mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item) @@ -293,6 +297,8 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): # Mlogbw.cal_count_notok(item) for itemx in mbd_qs: if itemx.count > 0: + if clear_defect and itemx.defect and itemx.defect.okcate == Defect.DEFECT_OK_B: + continue m_outs_list.append((item.material_out, item.batch, itemx.count, 0, itemx.defect, item)) # # 获取所有主要的不合格项/先暂时保留 # bw_qs = Mlogbw.objects.filter(mlogb=item) @@ -435,11 +441,17 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): # 有多个产物的情况 # 需要考虑不合格品退回的情况 mlogb_out_qs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False) + clear_defect = bool(mlog.clear_defect) if mlogb_out_qs.exists(): mlogb_out_qs = mlogb_out_qs.filter(need_inout=True) - m_outs_list = [ - (mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok_full if mo.count_ok_full is not None else mo.count_ok, mlog.count_real_eweight, None, mo) - for mo in mlogb_out_qs.all()] + if clear_defect: + m_outs_list = [ + (mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight, None, mo) + for mo in mlogb_out_qs.all()] + else: + m_outs_list = [ + (mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok_full if mo.count_ok_full is not None else mo.count_ok, mlog.count_real_eweight, None, mo) + for mo in mlogb_out_qs.all()] if stored_notok: for item in mlogb_out_qs: mbd_qs = MlogbDefect.get_defect_qs_from_mlogb(item) @@ -448,6 +460,8 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): # Mlogbw.cal_count_notok(item) for itemx in mbd_qs: if itemx.count > 0: + if clear_defect and itemx.defect and itemx.defect.okcate == Defect.DEFECT_OK_B: + continue m_outs_list.append((item.material_out, item.batch, itemx.count, 0, itemx.defect, item)) # if item.material_out.tracking == Material.MA_TRACKING_SINGLE: # # 获取所有主要的不合格项