diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index dd55ceb..1bac267 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -197,6 +197,10 @@ class OperationWproduct(BaseModel): material = models.ForeignKey(Material, verbose_name='操作时的物料状态', on_delete=models.CASCADE) subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='当前子生产计划', on_delete=models.CASCADE, related_name='ow_subplan') + class Meta: + unique_together = ( + ('operation','wproduct') + ) class OperationMaterial(BaseModel): """ @@ -214,6 +218,19 @@ class OperationMaterial(BaseModel): subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='关联的子计划', on_delete=models.CASCADE, null=True, blank=True) batch = models.CharField('批次号', max_length=100, null=True, blank=True) + #以下为冷加工下料清单所用字段 + count_cut = models.PositiveIntegerField('切裁片数', default=0) + count_real = models.PositiveIntegerField('生产片数', default=0) + count_ok = models.PositiveIntegerField('成品数量', default=0) + count_qipao = models.PositiveIntegerField('气泡甩片', default=0) + count_podian = models.PositiveIntegerField('破点甩片', default=0) + count_hua = models.PositiveIntegerField('划伤甩片', default=0) + count_other = models.PositiveIntegerField('其他甩片', default=0) + class Meta: + unique_together = ( + ('operation','material', 'batch') + ) + class OperationRecord(BaseModel): """ 记录表格 diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py index bd68bb7..eb1a226 100644 --- a/hb_server/apps/wpm/services.py +++ b/hb_server/apps/wpm/services.py @@ -7,7 +7,7 @@ from apps.mtm.models import Material, Step, SubprodctionMaterial from apps.qm.models import TestRecord from apps.system.models import User from apps.wf.models import State, TicketFlow, Transition -from apps.wpm.models import WProduct, WproductFlow, WprouctTicket +from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow, WprouctTicket from utils.tools import ranstr class WpmServies(object): @@ -146,3 +146,11 @@ class WpmServies(object): setattr(ins, f.name, getattr(instance, f.name, None)) ins.change_str = change_str ins.save() + + @classmethod + def update_cutting_list(cls, op:Operation): + """ + 更新下料清单 + """ + inputs = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_IN) + outputs = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index c446a47..817ed9f 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -579,9 +579,11 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd spp.save() # 更新动态产品表 if step.type == Step.STEP_TYPE_NOM: - for i in OperationWproduct.objects.filter(operation=op): + ows = OperationWproduct.objects.filter(operation=op) + for i in ows: wp = i.wproduct wsp = i.subproduction_plan + # 获取下一步子工序 newstep, hasNext = WpmServies.get_next_step(wsp, step) wp.step = newstep @@ -591,17 +593,21 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd else: wp.act_state = WProduct.WPR_ACT_STATE_TOTEST wp.material = wsp.product - # 更新子计划生产进度 - # 如果产品有返工标记不做计算 - if wp.ng_sign not in [WProduct.NG_BACK_FIX, WProduct.NG_BACK_WORK]: - WpmServies.update_subproduction_progress_main(sp=wsp) wp.operation = None wp.update_by = request.user wp.save() WpmServies.add_wproduct_flow_log(wp, 'operation_submit') + + for i in ows.values('subproduction_plan').distinct(): + # 更新进度 + WpmServies.update_subproduction_progress_main(sp=wsp) + elif step.type == Step.STEP_TYPE_DIV: # 更新物料产出情况 - for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT): + outputs = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) + if not outputs.exists(): + raise exceptions.APIException('请选择物料产出') + for i in outputs: if i.subproduction_progress.is_main: newstep, _ = WpmServies.get_next_step(i.subproduction_plan, step) wpr = dict(material=i.material, step=newstep, @@ -640,6 +646,10 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd raise exceptions.APIException('产出物料未填写或填写错误') op.is_submited = True op.save() + + # 如果是冷加工 + if step.type == Step.STEP_TYPE_DIV: + WpmServies.update_cutting_list(op=op) return Response()