领料bug
This commit is contained in:
parent
f1102656c7
commit
73a475c4ea
|
@ -48,20 +48,20 @@ class PickSerializer(serializers.Serializer):
|
|||
i['is_testok'] = True # 默认检测合格
|
||||
i['subproduction_plan'] = sp
|
||||
FIFOItem.objects.create(**i)
|
||||
# 更新车间物料
|
||||
wm, _ = WMaterial.objects.get_or_create(material=i['material'], batch=i['batch'], \
|
||||
subproduction_plan=sp,defaults={
|
||||
'material':i['material'],
|
||||
'batch':i['batch'],
|
||||
'subproduction_plan':sp,
|
||||
'count':0
|
||||
})
|
||||
wm.count = wm.count + i['count']
|
||||
wm.save()
|
||||
# 更新子计划物料情况
|
||||
spp = SubProductionProgress.objects.get(material=i['material'], subproduction_plan=sp, type=1)
|
||||
spp.count_pick = spp.count_pick + i['count']
|
||||
spp.save()
|
||||
# 更新车间物料
|
||||
wm, _ = WMaterial.objects.get_or_create(material=i['material'], batch=i['batch'], \
|
||||
subproduction_plan=sp,defaults={
|
||||
'material':i['material'],
|
||||
'batch':i['batch'],
|
||||
'subproduction_plan':sp,
|
||||
'count':0
|
||||
})
|
||||
wm.count = wm.count + i['count']
|
||||
wm.save()
|
||||
# 更新子计划物料情况
|
||||
spp = SubProductionProgress.objects.get(material=i['material'], subproduction_plan=sp, type=1)
|
||||
spp.count_pick = spp.count_pick + i['count']
|
||||
spp.save()
|
||||
sp.is_picked=True
|
||||
sp.state = 3 #生产中
|
||||
sp.state_date_real = timezone.now() #实际开工日期
|
||||
|
|
|
@ -34,8 +34,8 @@ class WPlanViewSet(ListModelMixin, GenericViewSet):
|
|||
search_fields = []
|
||||
serializer_class = SubProductionPlanListSerializer
|
||||
filterset_fields = ['production_plan', 'process', 'state', 'main_product', 'workshop']
|
||||
ordering_fields = ['process__number']
|
||||
ordering = ['process__number']
|
||||
ordering_fields = []
|
||||
ordering = ['-id']
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=WplanPutInSerializer)
|
||||
@transaction.atomic
|
||||
|
@ -125,52 +125,52 @@ class WMaterialViewSet(CreateUpdateModelAMixin, ListModelMixin, GenericViewSet):
|
|||
serializer= WproductPutInSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
vdata = serializer.data
|
||||
subplan = self.get_object()
|
||||
material = subplan.main_product
|
||||
batch = subplan.production_plan.number
|
||||
wproducts = WProduct.objects.filter(subproduction_plan=subplan,
|
||||
act_state=WProduct.WPR_ACT_STATE_OK, m_state=material, is_deleted=False)
|
||||
if wproducts.exists():
|
||||
# 创建入库记录
|
||||
remark = vdata.get('remark', '')
|
||||
fifo = FIFO.objects.create(type=FIFO.FIFO_TYPE_DO_IN,
|
||||
is_audited=True, auditor=request.user, inout_date=timezone.now(), create_by=request.user, remark=remark)
|
||||
# 创建入库明细
|
||||
fifoitem = FIFOItem()
|
||||
fifoitem.is_tested = True
|
||||
fifoitem.is_testok = True
|
||||
fifoitem.warehouse = vdata['warehouse']
|
||||
fifoitem.material = material
|
||||
fifoitem.count = wproducts.count()
|
||||
fifoitem.batch = batch
|
||||
fifoitem.fifo = fifo
|
||||
fifoitem.subproduction_plan = subplan
|
||||
fifoitem.save()
|
||||
# 创建入库明细半成品
|
||||
ips = []
|
||||
for i in wproducts:
|
||||
ip = {}
|
||||
ip['fifoitem'] = fifoitem
|
||||
ip['wproduct'] = i
|
||||
ip['number'] = i.number
|
||||
ip['material'] = material
|
||||
ips.append(FIFOItemProduct(**ip))
|
||||
FIFOItemProduct.objects.bulk_create(ips)
|
||||
# 创建IProduct
|
||||
ips2 = []
|
||||
for i in wproducts:
|
||||
ip = {}
|
||||
ip['warehouse'] = vdata['warehouse']
|
||||
ip['batch'] = batch
|
||||
ip['wproduct'] = i
|
||||
ip['number'] = i.number
|
||||
ip['material'] = material
|
||||
ips2.append(IProduct(**ip))
|
||||
IProduct.objects.bulk_create(ips2)
|
||||
# 更新库存并修改半成品进行状态
|
||||
update_inm(fifo)
|
||||
wproducts.update(act_sate=WProduct.WPR_ACT_STATE_INM, warehouse=vdata['warehouse'])
|
||||
|
||||
wproduct = self.get_object()
|
||||
if wproduct.act_state != WProduct.WPR_ACT_STATE_OK:
|
||||
raise exceptions.APIException('半成品不可入库')
|
||||
material = wproduct.m_state
|
||||
batch = wproduct.production_plan.number
|
||||
# 创建入库记录
|
||||
remark = vdata.get('remark', '')
|
||||
fifo = FIFO.objects.create(type=FIFO.FIFO_TYPE_DO_IN,
|
||||
is_audited=True, auditor=request.user, inout_date=timezone.now(), create_by=request.user, remark=remark)
|
||||
# 创建入库明细
|
||||
fifoitem = FIFOItem()
|
||||
fifoitem.is_tested = True
|
||||
fifoitem.is_testok = True
|
||||
fifoitem.warehouse = vdata['warehouse']
|
||||
fifoitem.material = material
|
||||
fifoitem.count = 1 # 单个半成品入库
|
||||
fifoitem.batch = batch
|
||||
fifoitem.fifo = fifo
|
||||
fifoitem.subproduction_plan = wproduct.subproduction_plan
|
||||
fifoitem.save()
|
||||
# 创建入库明细半成品
|
||||
ips = []
|
||||
for i in [wproduct]:
|
||||
ip = {}
|
||||
ip['fifoitem'] = fifoitem
|
||||
ip['wproduct'] = i
|
||||
ip['number'] = i.number
|
||||
ip['material'] = material
|
||||
ips.append(FIFOItemProduct(**ip))
|
||||
FIFOItemProduct.objects.bulk_create(ips)
|
||||
# 创建IProduct
|
||||
ips2 = []
|
||||
for i in [wproduct]:
|
||||
ip = {}
|
||||
ip['warehouse'] = vdata['warehouse']
|
||||
ip['batch'] = batch
|
||||
ip['wproduct'] = i
|
||||
ip['number'] = i.number
|
||||
ip['material'] = material
|
||||
ips2.append(IProduct(**ip))
|
||||
IProduct.objects.bulk_create(ips2)
|
||||
# 更新库存并修改半成品进行状态
|
||||
update_inm(fifo)
|
||||
wproduct.act_state=WProduct.WPR_ACT_STATE_INM
|
||||
wproduct.warehouse=vdata['warehouse']
|
||||
wproduct.save()
|
||||
return Response()
|
||||
|
||||
class WProductViewSet(ListModelMixin, GenericViewSet):
|
||||
|
|
Loading…
Reference in New Issue