diff --git a/hb_server/apps/hrm/views.py b/hb_server/apps/hrm/views.py index c167784..303e25d 100644 --- a/hb_server/apps/hrm/views.py +++ b/hb_server/apps/hrm/views.py @@ -106,12 +106,12 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet): def create(self, request, *args, **kwargs): now = timezone.now() now_local = timezone.localtime() - if 8<=now_local.hour<=17: + if 6<=now_local.hour<=17: base64_data = base64.urlsafe_b64decode(tran64( request.data.get('base64').replace(' ', '+'))) user, msg = HRMService.face_compare_from_base64(base64_data, request.data.get('tolerance', 0.36)) if user: - ins, created = ClockRecord.objects.get_or_create( + ClockRecord.objects.get_or_create( create_by = user, create_time__hour__range = [8,18], create_time__year=now_local.year, create_time__month=now_local.month, create_time__day=now_local.day, @@ -120,9 +120,9 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet): 'create_by':user, 'create_time':now }) - if not created: - ins.update_time = now - ins.save() + # if not created: + # ins.update_time = now + # ins.save() # 设为在岗 Employee.objects.filter(user=user).update(is_atwork=True, last_check_time=now) return Response(UserSimpleSerializer(instance=user).data) diff --git a/hb_server/apps/mtm/models.py b/hb_server/apps/mtm/models.py index 4603bd5..80ab3b3 100644 --- a/hb_server/apps/mtm/models.py +++ b/hb_server/apps/mtm/models.py @@ -266,6 +266,7 @@ class UsedStep(CommonADModel): """ step = models.ForeignKey(Step, verbose_name='子工序', on_delete=models.CASCADE, related_name='usedstep') need_test = models.BooleanField('工序内检验', default=False) + reuse_form = models.BooleanField('复用上表', default=True) remark = models.TextField('生产备注', null=True, blank=True) subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='usedstep_subproduction') diff --git a/hb_server/apps/mtm/serializers.py b/hb_server/apps/mtm/serializers.py index 43681b1..ec43e99 100644 --- a/hb_server/apps/mtm/serializers.py +++ b/hb_server/apps/mtm/serializers.py @@ -163,7 +163,7 @@ class UsedStepCreateSerializer(serializers.ModelSerializer): """ class Meta: model = UsedStep - fields = ['step', 'subproduction', 'remark', 'need_test'] + fields = ['step', 'subproduction', 'remark', 'need_test', 'reuse_form'] class UsedStepUpdateSerializer(serializers.ModelSerializer): """ @@ -171,7 +171,7 @@ class UsedStepUpdateSerializer(serializers.ModelSerializer): """ class Meta: model = UsedStep - fields = ['remark', 'need_test'] + fields = ['remark', 'need_test', 'reuse_form'] class UsedStepListSerializer(serializers.ModelSerializer): """ diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py index 384f036..821d2de 100644 --- a/hb_server/apps/wpm/services.py +++ b/hb_server/apps/wpm/services.py @@ -15,16 +15,17 @@ class WpmService(object): @classmethod def get_next_step(cls, subproduction_plan:SubProductionPlan, nowstep:Step): """ - 获取下一步骤 + 获取下一步骤的信息 """ steps_list = subproduction_plan.steps stepIds = [i['id'] for i in steps_list] pindex = stepIds.index(nowstep.id) need_test = steps_list[pindex].get('need_test', False) + reuse_form = steps_list[pindex].get('reuse_form', True) if pindex + 1 < len(stepIds): - return Step.objects.get(pk=stepIds[pindex+1]), need_test + return Step.objects.get(pk=stepIds[pindex+1]), need_test, reuse_form else: - return nowstep, need_test + return nowstep, need_test, reuse_form @classmethod def get_subplans_queryset_from_wproducts(cls, wproducts:List): diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 1a15fa7..4f7d492 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -185,14 +185,14 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): vdata = serializer.validated_data wproduct = vdata['wproduct'] form = vdata['form'] - if wproduct.test: - raise exceptions.APIException('存在进行中检验') - # 根据情况创建一条检验记录 if wproduct.act_state not in [WProduct.WPR_ACT_STATE_TOTEST, WProduct.WPR_ACT_STATE_TORETEST, WProduct.WPR_ACT_STATE_TOFINALTEST, WProduct.WPR_ACT_STATE_TOCOMBTEST]: raise exceptions.APIException('该产品当前状态不可检验') + if wproduct.test: + raise exceptions.APIException('存在进行中检验') + savedict = dict( create_by=request.user, wproduct=wproduct, @@ -213,8 +213,10 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST: savedict['type'] = TestRecord.TEST_COMB elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST: - if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test: + _, need_test, _ = WpmService.get_next_step(wproduct.subproduction_plan, wproduct.step) + if need_test: savedict['is_midtesting'] = True + # if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test: tr = TestRecord.objects.create(**savedict) # 更新wproduct wproduct.test = tr @@ -698,7 +700,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd wsp = i.subproduction_plan # 获取下一步子工序 - newstep, needTest = WpmService.get_next_step(wsp, step) + newstep, needTest, reuseForm = WpmService.get_next_step(wsp, step) wp.step = newstep wp.pre_step = step wp.material = wsp.product @@ -706,16 +708,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd if step == newstep: wp.act_state = WProduct.WPR_ACT_STATE_TOTEST if wp.test:# 如果有正在进行的工序中检验 - wp.test.is_midtesting = False - wp.test.is_submited = False - wp.test.save() - else: - wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT - if needTest: - wp.act_state = WProduct.WPR_ACT_STATE_TOTEST - if wp.test:# 如果有正在进行的工序中检验 + if reuseForm: + wp.test.is_midtesting = False wp.test.is_submited = False wp.test.save() + else: + wp.test = None + wp.save() + else: + wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT + if needTest: #子工序若需要检验 + wp.act_state = WProduct.WPR_ACT_STATE_TOTEST + if wp.test:# 如果有正在进行的工序中检验 + if reuseForm: + wp.test.is_submited = False + wp.test.save() + else: + wp.test = None + wp.save() wp.operation = None wp.update_by = request.user @@ -732,7 +742,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd raise exceptions.APIException('请选择物料产出') for i in omos: if i.subproduction_progress.is_main: - newstep, _ = WpmService.get_next_step( + newstep, _, _ = WpmService.get_next_step( i.subproduction_plan, step) wpr = dict(material=i.material, step=newstep, act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='', @@ -753,7 +763,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd if oms_w.count!=1: raise exceptions.APIException('产出数量应为1') # 校验单片数量是否正确, 暂时未写 - newstep, needTest = WpmService.get_next_step( + newstep, needTest, reuseForm = WpmService.get_next_step( oms_w.subproduction_plan, step) wproduct = WProduct() wproduct.material = oms_w.material @@ -762,13 +772,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd if step == newstep: wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST if wproduct.test:# 如果有正在进行的工序中检验 - wproduct.test.is_midtesting = False - wproduct.test.is_submited = False - wproduct.test.save() + if reuseForm: + wproduct.test.is_midtesting = False + wproduct.test.is_submited = False + wproduct.test.save() + else: + wproduct.test = None + wproduct.save() else: wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT if needTest: wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST + if wproduct.test:# 如果有正在进行的工序中检验 + if reuseForm: + wproduct.test.is_submited = False + wproduct.test.save() + else: + wproduct.test = None + wproduct.save() # 更新子计划进度 WpmService.update_subproduction_progress_main(