From 3ab9682b071ba2a067547c6385615fc95bc8743d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:11:18 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20work=5Fstart=5Ftime=20=E5=8F=AF?= =?UTF-8?q?=E4=B8=8D=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() From 8eee09678a86a5578db87e2847addeaa1c1a1b75 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:16:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20handle=5Fdate=E5=92=8Cshift=E5=8F=AF?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index c0c2f45b..9c4cbd38 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -355,7 +355,7 @@ class MlogSerializer(CustomModelSerializer): model = Mlog fields = '__all__' read_only_fields = EXCLUDE_FIELDS + \ - ['submit_time', 'submit_user', 'material_outs', "handle_date", "shift"] + ['submit_time', 'submit_user', 'material_outs'] extra_kwargs = { "batch": {"required": True}, "shift": {"required": False}, From f5f6c136d9704e5aa80f4c2741424b10769c847f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:21:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20work=5Fstart=5Ftime=20=E5=8F=AF?= =?UTF-8?q?=E4=B8=8D=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 9c4cbd38..cd9f63fe 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -636,18 +636,15 @@ class MlogSerializer(CustomModelSerializer): mgroup:Mgroup = attrs['mgroup'] work_start_time:datetime = attrs.get('work_start_time', None) if work_start_time: - handle_date, attrs["shift"] = mgroup.get_shift(work_start_time) + attrs['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: + if attrs['handle_date'] != mtask.end_date: raise ParseError('任务日期与生产日期不一致') - elif work_start_time: - attrs['handle_date'] = handle_date handle_user = attrs.get('handle_user', None) if handle_user is None and hasattr(self, "request"): From eb2deb02c2222d0f3a93d3490703c3e35f12589c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:22:19 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20work=5Fstart=5Ftime=20=E5=8F=AF?= =?UTF-8?q?=E4=B8=8D=E5=A1=AB2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 05895df0..7bca34cb 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_end_time and mlog.work_start_time > timezone.now(): + if mlog.work_start_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('操作结束时间不能早于操作开始时间') From 20604ef7cbf5d2757589a67dc5ccc35f01d2c798 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sat, 11 Oct 2025 10:28:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20work=5Fstart=5Ftime=20=E5=AF=B9?= =?UTF-8?q?=E5=85=89=E5=AD=90=E7=9A=84=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index cd9f63fe..09458f32 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -644,7 +644,10 @@ class MlogSerializer(CustomModelSerializer): raise ParseError('缺少生产日期') if mtask and mtask.start_date == mtask.end_date: if attrs['handle_date'] != mtask.end_date: - raise ParseError('任务日期与生产日期不一致') + if work_start_time: + raise ParseError('任务日期与生产日期不一致') + else: + attrs['handle_date'] = mtask.end_date handle_user = attrs.get('handle_user', None) if handle_user is None and hasattr(self, "request"):