增加夹层检验
This commit is contained in:
parent
306f916f00
commit
bf3a7080b2
|
@ -14,4 +14,4 @@ class IProductFilterSet(filters.FilterSet):
|
|||
order = filters.NumberFilter(field_name="wproduct__subproduction_plan__production_plan__order")
|
||||
class Meta:
|
||||
model = IProduct
|
||||
fields = ['material', 'warehouse', 'batch', 'order']
|
||||
fields = ['material', 'warehouse', 'batch', 'order', 'is_mtested', 'is_mtestok']
|
|
@ -93,6 +93,9 @@ class IProduct(BaseModel):
|
|||
warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='所在仓库')
|
||||
batch = models.CharField('所属批次号', max_length=100, default='')
|
||||
wproduct = models.ForeignKey('wpm.wproduct', on_delete=models.CASCADE, verbose_name='关联的动态产品', db_constraint=False, null=True, blank=True)
|
||||
is_mtested = models.BooleanField('是否军检', default=False)
|
||||
is_mtestok = models.BooleanField('是否军检合格', null=True, blank=True)
|
||||
remark_mtest = models.TextField('军检备注', null=True, blank=True)
|
||||
is_saled = models.BooleanField('是否售出', default=False)
|
||||
|
||||
class FIFOItemProduct(BaseModel):
|
||||
|
|
|
@ -147,3 +147,9 @@ class InmTestRecordCreateSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = TestRecord
|
||||
fields = ['form', 'record_data', 'is_testok', 'fifo_item']
|
||||
|
||||
|
||||
class IProductMtestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = IProduct
|
||||
fields = ['remark_mtest', 'is_mtestok']
|
|
@ -1,12 +1,13 @@
|
|||
from django.shortcuts import render
|
||||
from rest_framework import serializers
|
||||
from rest_framework import exceptions
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework.mixins import DestroyModelMixin, ListModelMixin, RetrieveModelMixin
|
||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||
from apps.inm.filters import IProductFilterSet, MbFilterSet
|
||||
|
||||
from apps.inm.models import FIFO, FIFOItem, IProduct, MaterialBatch, WareHouse,Inventory
|
||||
from apps.inm.serializers import FIFOItemSerializer, FIFOInPurSerializer, FIFOListSerializer, IProductListSerializer, InmTestRecordCreateSerializer, MaterialBatchQuerySerializer, MaterialBatchSerializer, WareHouseSerializer, WareHouseCreateUpdateSerializer,InventorySerializer
|
||||
from apps.inm.serializers import FIFOItemSerializer, FIFOInPurSerializer, FIFOListSerializer, IProductListSerializer, IProductMtestSerializer, InmTestRecordCreateSerializer, MaterialBatchQuerySerializer, MaterialBatchSerializer, WareHouseSerializer, WareHouseCreateUpdateSerializer,InventorySerializer
|
||||
from apps.inm.signals import update_inm
|
||||
from apps.qm.models import TestRecordItem
|
||||
from apps.system.mixins import CreateUpdateModelAMixin, OptimizationMixin
|
||||
|
@ -173,3 +174,17 @@ class IProductViewSet(ListModelMixin, GenericViewSet):
|
|||
search_fields = []
|
||||
ordering_fields = ['create_time']
|
||||
ordering = ['-create_time']
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=IProductMtestSerializer)
|
||||
def mtest(self, request, pk=None):
|
||||
"""
|
||||
军检
|
||||
"""
|
||||
obj = self.get_object()
|
||||
if obj.is_mtested:
|
||||
raise exceptions.APIException('已进行军检')
|
||||
obj.remark_mtest = request.data.get('remark_mtest', None)
|
||||
obj.is_mtested = True
|
||||
obj.is_mtestok = request.data.get('is_mtestok')
|
||||
obj.save()
|
||||
return Response()
|
|
@ -50,11 +50,13 @@ class TestRecord(CommonAModel):
|
|||
TEST_STEP = 10
|
||||
TEST_PROCESS = 20
|
||||
TEST_PROCESS_RE = 30
|
||||
TEST_COMB = 36
|
||||
TEST_FINAL = 40
|
||||
type_choice = (
|
||||
(TEST_STEP, '子工序检验'),
|
||||
(TEST_PROCESS, '工序检验'),
|
||||
(TEST_PROCESS_RE, '工序复检'),
|
||||
(TEST_COMB, '夹层检验'),
|
||||
(TEST_FINAL, '成品检验')
|
||||
)
|
||||
form = models.ForeignKey('mtm.recordform', verbose_name='所用表格', on_delete=models.CASCADE)
|
||||
|
|
|
@ -89,8 +89,6 @@ class SaleProduct(BaseModel):
|
|||
sale = models.ForeignKey(Sale, verbose_name='关联销售记录', on_delete=models.CASCADE)
|
||||
number = models.CharField('物品编号', max_length=50)
|
||||
iproduct = models.ForeignKey('inm.iproduct', verbose_name='关联库存产品', on_delete=models.CASCADE, related_name='sale_iproduct')
|
||||
is_mtested = models.BooleanField('是否军检', default=False)
|
||||
is_mtestok = models.BooleanField('是否军检合格', null=True, blank=True)
|
||||
remark = models.TextField('备注', null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -102,8 +102,3 @@ class SaleProductCreateSerializer(serializers.ModelSerializer):
|
|||
instance.sale.count = SaleProduct.objects.filter(sale=instance.sale).count()
|
||||
instance.sale.save()
|
||||
return instance
|
||||
|
||||
class SaleProductMtestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SaleProduct
|
||||
fields = ['remark', 'is_mtestok']
|
|
@ -5,7 +5,7 @@ from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModel
|
|||
from apps.mtm.models import Material
|
||||
from apps.inm.models import FIFO, FIFOItem, FIFOItemProduct, IProduct, WareHouse
|
||||
from apps.inm.signals import update_inm
|
||||
from apps.sam.serializers import ContractCreateUpdateSerializer, ContractSerializer, CustomerCreateUpdateSerializer, CustomerSerializer, OrderCreateUpdateSerializer, OrderSerializer, SaleCreateSerializer, SaleListSerializer, SaleProductCreateSerializer, SaleProductListSerializer, SaleProductMtestSerializer
|
||||
from apps.sam.serializers import ContractCreateUpdateSerializer, ContractSerializer, CustomerCreateUpdateSerializer, CustomerSerializer, OrderCreateUpdateSerializer, OrderSerializer, SaleCreateSerializer, SaleListSerializer, SaleProductCreateSerializer, SaleProductListSerializer
|
||||
from apps.sam.models import Contract, Customer, Order, Sale, SaleProduct
|
||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||
from apps.system.mixins import CreateUpdateCustomMixin
|
||||
|
@ -133,13 +133,13 @@ class SaleViewSet(CreateUpdateCustomMixin, ListModelMixin, RetrieveModelMixin, C
|
|||
fifo.inout_date = timezone.now()
|
||||
fifo.create_by = request.user
|
||||
fifo.save()
|
||||
# 出库条目
|
||||
spds = SaleProduct.objects.filter(sale=obj)
|
||||
for i in spds:
|
||||
if i.is_mtested and i.is_mtestok:
|
||||
pass
|
||||
else:
|
||||
raise exceptions.APIException('存在未军检产品')
|
||||
# 出库条目 暂时不校验是否军检
|
||||
# spds = SaleProduct.objects.filter(sale=obj)
|
||||
# for i in spds:
|
||||
# if i.is_mtested and i.is_mtestok:
|
||||
# pass
|
||||
# else:
|
||||
# raise exceptions.APIException('存在未军检产品')
|
||||
# 创建出库条目
|
||||
ips = IProduct.objects.filter(sale_iproduct__sale=obj)
|
||||
items = ips.values('warehouse', 'material', 'batch').annotate(total=Count('id'))
|
||||
|
@ -199,21 +199,12 @@ class SaleProductViewSet(ListModelMixin, DestroyModelMixin, CreateModelMixin, Ge
|
|||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
obj.sale.count = SaleProduct.objects.filter(sale=obj.sale).count()
|
||||
obj.sale.save()
|
||||
sale = obj.sale
|
||||
if sale.is_audited:
|
||||
raise exceptions.APIException('该销售记录已审核,不可删除产品')
|
||||
sale.count = SaleProduct.objects.filter(sale=obj.sale).count()
|
||||
sale.save()
|
||||
obj.delete()
|
||||
return Response()
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=SaleProductMtestSerializer)
|
||||
def mtest(self, request, pk=None):
|
||||
"""
|
||||
军检
|
||||
"""
|
||||
obj = self.get_object()
|
||||
if obj.is_mtested:
|
||||
raise exceptions.APIException('已进行军检')
|
||||
obj.remark = request.data.get('remark', None)
|
||||
obj.is_mtested = True
|
||||
obj.is_mtestok = request.data.get('is_mtestok')
|
||||
obj.save()
|
||||
return Response()
|
||||
|
|
@ -28,6 +28,7 @@ class WProduct(CommonAModel):
|
|||
WPR_ACT_STATE_DOWAIT = 8
|
||||
WPR_ACT_STATE_DOING = 10
|
||||
WPR_ACT_STATE_TOTEST = 20
|
||||
WPR_ACT_STATE_TOCOMBTEST = 26
|
||||
WPR_ACT_STATE_OK = 30
|
||||
WPR_ACT_STATE_INM = 40
|
||||
WPR_ACT_STATE_NOTOK = 50
|
||||
|
@ -37,6 +38,7 @@ class WProduct(CommonAModel):
|
|||
(WPR_ACT_STATE_DOWAIT, '操作准备中'),
|
||||
(WPR_ACT_STATE_DOING, '操作进行中'),
|
||||
(WPR_ACT_STATE_TOTEST, '待检验'),
|
||||
(WPR_ACT_STATE_TOCOMBTEST, '待夹层检验'),
|
||||
(WPR_ACT_STATE_OK, '已合格'),
|
||||
(WPR_ACT_STATE_INM, '库存中'),
|
||||
(WPR_ACT_STATE_NOTOK, '不合格'),
|
||||
|
|
|
@ -195,7 +195,7 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
|||
record_data = vdata.pop('record_data')
|
||||
wproduct = vdata['wproduct']
|
||||
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]:
|
||||
raise exceptions.APIException('该产品当前状态不可检验')
|
||||
if 'is_testok' not in vdata:
|
||||
raise exceptions.APIException('未填写检测结论')
|
||||
|
@ -206,6 +206,8 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
|||
savedict['type'] = TestRecord.TEST_PROCESS_RE
|
||||
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOFINALTEST:
|
||||
savedict['type'] = TestRecord.TEST_FINAL
|
||||
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST:
|
||||
savedict['type'] = TestRecord.TEST_COMB
|
||||
obj = serializer.save(**savedict)
|
||||
tris = []
|
||||
for m in record_data: # 保存记录详情
|
||||
|
@ -224,10 +226,12 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
|||
# 如果检测合格, 变更动态产品进行状态
|
||||
|
||||
if obj.is_testok:
|
||||
if wproduct.act_state == WProduct.WPR_ACT_STATE_TORETEST:
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT # 复检
|
||||
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST and wproduct.material.type == Material.MA_TYPE_GOOD:
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOFINALTEST # 成品检验
|
||||
if wproduct.act_state == WProduct.WPR_ACT_STATE_TORETEST: # 复检
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
||||
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST and wproduct.material.type == Material.MA_TYPE_GOOD: # 成品检验
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOFINALTEST
|
||||
elif wproduct.step.type == Step.STEP_TYPE_COMB: # 如果是夹层
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOCOMBTEST
|
||||
else:
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_OK
|
||||
if wproduct.number is None: # 产生半成品编号
|
||||
|
@ -498,25 +502,29 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
|||
for x in range(i.count):
|
||||
WProduct.objects.create(**wpr)
|
||||
elif step.type == Step.STEP_TYPE_COMB:
|
||||
if i.subproduction_progress.is_main:
|
||||
oms_w = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT,
|
||||
subproduction_progress__ismain=True)
|
||||
if len(oms_w) == 1:
|
||||
newstep, hasNext = WpmServies.get_next_step(i.subproduction_plan, step)
|
||||
oms_w = oms_w[0]
|
||||
wproduct = WProduct()
|
||||
wproduct.material = i.material
|
||||
wproduct.material = oms_w.material
|
||||
wproduct.step = newstep
|
||||
wproduct.subproduction_plan = i.subproduction_plan
|
||||
wproduct.subproduction_plan = oms_w.subproduction_plan
|
||||
if hasNext:
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
||||
else:
|
||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||
# 更新子计划进度
|
||||
instance = SubProductionProgress.objects.get(subproduction_plan=i.subproduction_plan,
|
||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
||||
instance = oms_w.subproduction_progress
|
||||
instance.count_real = instance.count_real + 1 # 这个地方可能会有问题,不够严谨
|
||||
instance.save()
|
||||
wproduct.save()
|
||||
# 隐藏原半成品
|
||||
wps = WProduct.objects.filter(ow_wproduct__operation = op)
|
||||
wps.update(is_hidden=True, child=wproduct)
|
||||
else:
|
||||
raise exceptions.APIException('产出物料错误')
|
||||
op.is_submited = True
|
||||
op.save()
|
||||
return Response()
|
||||
|
|
Loading…
Reference in New Issue