From 3ab9682b071ba2a067547c6385615fc95bc8743d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:11:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20work=5Fstart=5Ftime=20=E5=8F=AF=E4=B8=8D?= =?UTF-8?q?=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 14 ++++++++++---- apps/wpm/services.py | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 0d2e1951..c0c2f45b 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -360,7 +360,7 @@ class MlogSerializer(CustomModelSerializer): "batch": {"required": True}, "shift": {"required": False}, "material_out": {"required": True}, - "work_start_time": {"required": True} + "work_start_time": {"required": False} } def create(self, validated_data): @@ -634,13 +634,19 @@ class MlogSerializer(CustomModelSerializer): # 时间 mgroup:Mgroup = attrs['mgroup'] - work_start_time:datetime = attrs['work_start_time'] - handle_date, attrs["shift"] = mgroup.get_shift(work_start_time) + work_start_time:datetime = attrs.get('work_start_time', None) + if work_start_time: + handle_date, attrs["shift"] = mgroup.get_shift(work_start_time) + else: + if "handle_date" in attrs and attrs["handle_date"]: + pass + else: + raise ParseError('缺少生产日期') if mtask and mtask.start_date == mtask.end_date: attrs['handle_date'] = mtask.end_date if attrs['handle_date'] != handle_date: raise ParseError('任务日期与生产日期不一致') - else: + elif work_start_time: attrs['handle_date'] = handle_date handle_user = attrs.get('handle_user', None) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 69aafb13..05895df0 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -152,7 +152,7 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): """ 生产日志提交后需要执行的操作 """ - if mlog.work_start_time > timezone.now(): + if mlog.work_end_time and mlog.work_start_time > timezone.now(): raise ParseError('操作开始时间不能晚于当前时间') if mlog.work_start_time and mlog.work_end_time and mlog.work_end_time < mlog.work_start_time: raise ParseError('操作结束时间不能早于操作开始时间') @@ -385,7 +385,7 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): mlog.submit_user = user mlog.stored_notok = stored_notok mlog.stored_mgroup = stored_mgroup - if mlog.work_end_time is None: + if mlog.work_end_time is None and mlog.work_start_time is not None: mlog.work_end_time = now mlog.save()