diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 0d2e1951..09458f32 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -355,12 +355,12 @@ 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}, "material_out": {"required": True}, - "work_start_time": {"required": True} + "work_start_time": {"required": False} } def create(self, validated_data): @@ -634,14 +634,20 @@ 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) - if mtask and mtask.start_date == mtask.end_date: - attrs['handle_date'] = mtask.end_date - if attrs['handle_date'] != handle_date: - raise ParseError('任务日期与生产日期不一致') + work_start_time:datetime = attrs.get('work_start_time', None) + if work_start_time: + attrs['handle_date'], attrs["shift"] = mgroup.get_shift(work_start_time) else: - attrs['handle_date'] = handle_date + if "handle_date" in attrs and attrs["handle_date"]: + pass + else: + raise ParseError('缺少生产日期') + if mtask and mtask.start_date == mtask.end_date: + if attrs['handle_date'] != mtask.end_date: + 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"): diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 69aafb13..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_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('操作结束时间不能早于操作开始时间') @@ -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()