子工序可复用上表

This commit is contained in:
曹前明 2022-06-27 13:06:09 +08:00
parent 276b8fc9fc
commit 1784a066d0
5 changed files with 51 additions and 28 deletions

View File

@ -106,12 +106,12 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet):
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
now = timezone.now() now = timezone.now()
now_local = timezone.localtime() now_local = timezone.localtime()
if 8<=now_local.hour<=17: if 6<=now_local.hour<=17:
base64_data = base64.urlsafe_b64decode(tran64( base64_data = base64.urlsafe_b64decode(tran64(
request.data.get('base64').replace(' ', '+'))) request.data.get('base64').replace(' ', '+')))
user, msg = HRMService.face_compare_from_base64(base64_data, request.data.get('tolerance', 0.36)) user, msg = HRMService.face_compare_from_base64(base64_data, request.data.get('tolerance', 0.36))
if user: if user:
ins, created = ClockRecord.objects.get_or_create( ClockRecord.objects.get_or_create(
create_by = user, create_time__hour__range = [8,18], create_by = user, create_time__hour__range = [8,18],
create_time__year=now_local.year, create_time__month=now_local.month, create_time__year=now_local.year, create_time__month=now_local.month,
create_time__day=now_local.day, create_time__day=now_local.day,
@ -120,9 +120,9 @@ class ClockRecordViewSet(CreateModelMixin, ListModelMixin, GenericViewSet):
'create_by':user, 'create_by':user,
'create_time':now 'create_time':now
}) })
if not created: # if not created:
ins.update_time = now # ins.update_time = now
ins.save() # ins.save()
# 设为在岗 # 设为在岗
Employee.objects.filter(user=user).update(is_atwork=True, last_check_time=now) Employee.objects.filter(user=user).update(is_atwork=True, last_check_time=now)
return Response(UserSimpleSerializer(instance=user).data) return Response(UserSimpleSerializer(instance=user).data)

View File

@ -266,6 +266,7 @@ class UsedStep(CommonADModel):
""" """
step = models.ForeignKey(Step, verbose_name='子工序', on_delete=models.CASCADE, related_name='usedstep') step = models.ForeignKey(Step, verbose_name='子工序', on_delete=models.CASCADE, related_name='usedstep')
need_test = models.BooleanField('工序内检验', default=False) need_test = models.BooleanField('工序内检验', default=False)
reuse_form = models.BooleanField('复用上表', default=True)
remark = models.TextField('生产备注', null=True, blank=True) remark = models.TextField('生产备注', null=True, blank=True)
subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='usedstep_subproduction') subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='usedstep_subproduction')

View File

@ -163,7 +163,7 @@ class UsedStepCreateSerializer(serializers.ModelSerializer):
""" """
class Meta: class Meta:
model = UsedStep model = UsedStep
fields = ['step', 'subproduction', 'remark', 'need_test'] fields = ['step', 'subproduction', 'remark', 'need_test', 'reuse_form']
class UsedStepUpdateSerializer(serializers.ModelSerializer): class UsedStepUpdateSerializer(serializers.ModelSerializer):
""" """
@ -171,7 +171,7 @@ class UsedStepUpdateSerializer(serializers.ModelSerializer):
""" """
class Meta: class Meta:
model = UsedStep model = UsedStep
fields = ['remark', 'need_test'] fields = ['remark', 'need_test', 'reuse_form']
class UsedStepListSerializer(serializers.ModelSerializer): class UsedStepListSerializer(serializers.ModelSerializer):
""" """

View File

@ -15,16 +15,17 @@ class WpmService(object):
@classmethod @classmethod
def get_next_step(cls, subproduction_plan:SubProductionPlan, nowstep:Step): def get_next_step(cls, subproduction_plan:SubProductionPlan, nowstep:Step):
""" """
获取下一步骤 获取下一步骤的信息
""" """
steps_list = subproduction_plan.steps steps_list = subproduction_plan.steps
stepIds = [i['id'] for i in steps_list] stepIds = [i['id'] for i in steps_list]
pindex = stepIds.index(nowstep.id) pindex = stepIds.index(nowstep.id)
need_test = steps_list[pindex].get('need_test', False) need_test = steps_list[pindex].get('need_test', False)
reuse_form = steps_list[pindex].get('reuse_form', True)
if pindex + 1 < len(stepIds): 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: else:
return nowstep, need_test return nowstep, need_test, reuse_form
@classmethod @classmethod
def get_subplans_queryset_from_wproducts(cls, wproducts:List): def get_subplans_queryset_from_wproducts(cls, wproducts:List):

View File

@ -185,14 +185,14 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
vdata = serializer.validated_data vdata = serializer.validated_data
wproduct = vdata['wproduct'] wproduct = vdata['wproduct']
form = vdata['form'] form = vdata['form']
if wproduct.test:
raise exceptions.APIException('存在进行中检验')
# 根据情况创建一条检验记录 # 根据情况创建一条检验记录
if wproduct.act_state not in [WProduct.WPR_ACT_STATE_TOTEST, 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_TORETEST, WProduct.WPR_ACT_STATE_TOFINALTEST,
WProduct.WPR_ACT_STATE_TOCOMBTEST]: WProduct.WPR_ACT_STATE_TOCOMBTEST]:
raise exceptions.APIException('该产品当前状态不可检验') raise exceptions.APIException('该产品当前状态不可检验')
if wproduct.test:
raise exceptions.APIException('存在进行中检验')
savedict = dict( savedict = dict(
create_by=request.user, create_by=request.user,
wproduct=wproduct, wproduct=wproduct,
@ -213,8 +213,10 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST: elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST:
savedict['type'] = TestRecord.TEST_COMB savedict['type'] = TestRecord.TEST_COMB
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST: 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 savedict['is_midtesting'] = True
# if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test:
tr = TestRecord.objects.create(**savedict) tr = TestRecord.objects.create(**savedict)
# 更新wproduct # 更新wproduct
wproduct.test = tr wproduct.test = tr
@ -698,7 +700,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
wsp = i.subproduction_plan 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.step = newstep
wp.pre_step = step wp.pre_step = step
wp.material = wsp.product wp.material = wsp.product
@ -706,16 +708,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
if step == newstep: if step == newstep:
wp.act_state = WProduct.WPR_ACT_STATE_TOTEST wp.act_state = WProduct.WPR_ACT_STATE_TOTEST
if wp.test:# 如果有正在进行的工序中检验 if wp.test:# 如果有正在进行的工序中检验
wp.test.is_midtesting = False if reuseForm:
wp.test.is_submited = False wp.test.is_midtesting = 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:# 如果有正在进行的工序中检验
wp.test.is_submited = False wp.test.is_submited = False
wp.test.save() 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.operation = None
wp.update_by = request.user wp.update_by = request.user
@ -732,7 +742,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
raise exceptions.APIException('请选择物料产出') raise exceptions.APIException('请选择物料产出')
for i in omos: for i in omos:
if i.subproduction_progress.is_main: if i.subproduction_progress.is_main:
newstep, _ = WpmService.get_next_step( newstep, _, _ = WpmService.get_next_step(
i.subproduction_plan, step) i.subproduction_plan, step)
wpr = dict(material=i.material, step=newstep, wpr = dict(material=i.material, step=newstep,
act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='', act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='',
@ -753,7 +763,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
if oms_w.count!=1: if oms_w.count!=1:
raise exceptions.APIException('产出数量应为1') raise exceptions.APIException('产出数量应为1')
# 校验单片数量是否正确, 暂时未写 # 校验单片数量是否正确, 暂时未写
newstep, needTest = WpmService.get_next_step( newstep, needTest, reuseForm = WpmService.get_next_step(
oms_w.subproduction_plan, step) oms_w.subproduction_plan, step)
wproduct = WProduct() wproduct = WProduct()
wproduct.material = oms_w.material wproduct.material = oms_w.material
@ -762,13 +772,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
if step == newstep: if step == newstep:
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
if wproduct.test:# 如果有正在进行的工序中检验 if wproduct.test:# 如果有正在进行的工序中检验
wproduct.test.is_midtesting = False if reuseForm:
wproduct.test.is_submited = False wproduct.test.is_midtesting = False
wproduct.test.save() wproduct.test.is_submited = False
wproduct.test.save()
else:
wproduct.test = None
wproduct.save()
else: else:
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT
if needTest: if needTest:
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST 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( WpmService.update_subproduction_progress_main(