领料更新,操作表单更新

This commit is contained in:
caoqianming 2021-11-15 09:16:16 +08:00
parent 2d624a1be1
commit a78a10c3fa
5 changed files with 63 additions and 28 deletions

View File

@ -2,7 +2,7 @@ from django.db import models
from django.db.models.base import Model
import django.utils.timezone as timezone
from django.db.models.query import QuerySet
from apps.system.models import CommonAModel, CommonBModel, Organization, User, Dict, File
from apps.system.models import CommonADModel, CommonAModel, CommonBModel, Organization, User, Dict, File
from utils.model import SoftModel, BaseModel
from simple_history.models import HistoricalRecords
from apps.system.models import Organization
@ -178,7 +178,7 @@ class SubProduction(CommonAModel):
verbose_name = '产品生产工序'
verbose_name_plural = verbose_name
class SubprodctionMaterial(CommonAModel):
class SubprodctionMaterial(CommonADModel):
"""
输入/输出物料/工具工装
"""
@ -198,20 +198,20 @@ class SubprodctionMaterial(CommonAModel):
sort = models.IntegerField('排序号', default=1)
class UsedStep(CommonAModel):
class UsedStep(CommonADModel):
"""
涉及的生产子工序
"""
step = models.ForeignKey(Step, verbose_name='子工序', on_delete=models.CASCADE, related_name='usedstep')
remark = models.TextField('生产备注', null=True, blank=True)
subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE)
subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='usedstep_subproduction')
class Meta:
verbose_name = '产品生产子工序'
verbose_name_plural = verbose_name
class TechDoc(CommonAModel):
class TechDoc(CommonADModel):
"""
技术文件
"""

View File

@ -159,7 +159,7 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo
serializer = SubProductionProgressSerializer(instance=instance, many=True)
return Response(serializer.data)
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=PickNeedSerializer)
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=serializers.Serializer)
def pick_need(self, request, pk=None):
"""
领料需求清单/库存数

View File

@ -177,6 +177,18 @@ class CommonAModel(SoftModel):
class Meta:
abstract = True
class CommonADModel(BaseModel):
"""
业务用基本表A,包含create_by, update_by字段, 硬删除
"""
create_by = models.ForeignKey(
User, null=True, blank=True, on_delete=models.SET_NULL, verbose_name='创建人', related_name= '%(class)s_create_by')
update_by = models.ForeignKey(
User, null=True, blank=True, on_delete=models.SET_NULL, verbose_name='最后编辑人', related_name= '%(class)s_update_by')
class Meta:
abstract = True
class CommonBModel(SoftModel):
"""
业务用基本表B,包含create_by, update_by, belong_dept字段
@ -191,6 +203,19 @@ class CommonBModel(SoftModel):
class Meta:
abstract = True
class CommonBDModel(BaseModel):
"""
业务用基本表B,包含create_by, update_by, belong_dept字段, 硬删除
"""
create_by = models.ForeignKey(
User, null=True, blank=True, on_delete=models.SET_NULL, verbose_name='创建人', related_name = '%(class)s_create_by')
update_by = models.ForeignKey(
User, null=True, blank=True, on_delete=models.SET_NULL, verbose_name='最后编辑人', related_name = '%(class)s_update_by')
belong_dept = models.ForeignKey(
Organization, null=True, blank=True, on_delete=models.SET_NULL, verbose_name='所属部门', related_name= '%(class)s_belong_dept')
class Meta:
abstract = True
class File(CommonAModel):
"""

View File

@ -113,17 +113,17 @@ class OperationListSerializer(serializers.ModelSerializer):
class OperationInitSerializer(serializers.Serializer):
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID")
# subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
wproducts = serializers.ListField(child=
serializers.PrimaryKeyRelatedField(queryset=WProduct.objects.all()), label="半成品ID列表", required=False)
def validate(self, data):
subproduction_plan = data['subproduction_plan']
# subproduction_plan = data['subproduction_plan']
step = data['step']
stepIds=[i['id'] for i in subproduction_plan.steps]
if step.id not in stepIds:
raise exceptions.ValidationError('请选择正确的子工序操作')
# stepIds=[i['id'] for i in subproduction_plan.steps]
# if step.id not in stepIds:
# raise exceptions.ValidationError('请选择正确的子工序操作')
if 'wproducts' in data and data['wproducts']:
if step.type == Step.STEP_TYPE_DIV:
@ -131,8 +131,8 @@ class OperationInitSerializer(serializers.Serializer):
for i in data['wproducts']:
if i.is_executed:
raise exceptions.ValidationError('不可进行操作')
if i.subproduction_plan != subproduction_plan:
raise exceptions.ValidationError('半成品所属子计划不一致')
# if i.subproduction_plan != subproduction_plan:
# raise exceptions.ValidationError('半成品所属子计划不一致')
if i.p_state != step:
raise exceptions.ValidationError('半成品所属子工序不一致')
else:
@ -146,6 +146,7 @@ class DoInputSerializer(serializers.Serializer):
count_input = serializers.IntegerField(min_value=0, label='消耗数量')
class DoOutputSerializer(serializers.Serializer):
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
material = serializers.PrimaryKeyRelatedField(queryset=Material.objects.all(), label='物料ID')
count_output = serializers.IntegerField(min_value=0, label='产出数量')
@ -164,7 +165,7 @@ class OperationRecordSerializer(serializers.ModelSerializer):
class OperationSubmitSerializer(serializers.Serializer):
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID")
# subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
wproducts = serializers.ListField(child=
serializers.PrimaryKeyRelatedField(queryset=WProduct.objects.all()), label="半成品ID列表", required=False)
input = DoInputSerializer(many=True, required=False)

View File

@ -151,26 +151,33 @@ class DoFormInit(CreateAPIView, GenericAPIView):
ret = {}
ret_0 = {}
ret_0['step'] = data['step']
ret_0['subproduction_plan'] = data['subproduction_plan']
splans =[]
ret_0['input'] = []
# ret_0['subproduction_plan'] = data['subproduction_plan']
if 'wproducts' in data and data['wproducts']:
ret_0['wproducts'] = data['wproducts']
splans = WProduct.objects.filter(id__in=data['wproducts']).values('subproduction_plan', flat=True)
# 调出所属子计划现有物料
ret_0['input'] = WMaterialListSerializer(instance=WMaterial.objects.filter(subproduction_plan__in=splans), many=True)
else:
ret_0['wproducts'] = []
# 调出该子计划现有物料
ret_0['input'] = list(WMaterial.objects.filter(subproduction_plan=vdata['subproduction_plan'])\
.values('id', 'material', 'material__name', 'count', 'material__number', 'batch'))
for i in ret_0['input']:
i['count_input'] = 0
# 需要输出的物料
if ret_0['wproducts']:
# 排除主要产物, 因为已经放到半成品里了, 由半成品进行处理, 夹层可能需要特殊处理
o_objs = SubProductionProgress.objects.filter(
subproduction_plan=vdata['subproduction_plan'], type=SubprodctionMaterial.SUB_MA_TYPE_OUT).exclude(is_main=True)
subproduction_plan__in=splans, type=SubprodctionMaterial.SUB_MA_TYPE_OUT).exclude(is_main=True)
else:
# 此时显示所有子计划的情况
splans = SubProductionPlan.objects.filter(is_deleted=False,
subproduction__usedstep_subproduction__step=vdata['step'], state=3)
o_objs = SubProductionProgress.objects.filter(
subproduction_plan=vdata['subproduction_plan'], type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
ret_0['output'] = list(o_objs.values('material', 'material__name', 'material__number'))
subproduction_plan__in=splans, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
ret_0['output'] = list(o_objs.values('subproduction_plan', 'material', 'material__name', 'material__number'))
for i in ret_0['output']:
i['count_output']=0
ret['forms'] = []
@ -227,16 +234,16 @@ class DoFormSubmit(CreateAPIView, GenericAPIView):
if 'output' in data and data['output']:
for i in vdata['output']: # 已经序列化好的数据
ma = i['material']
if vdata['subproduction_plan'].main_product == ma: # 如果是该计划主产物
if i['subproduction_plan'].main_product == ma: # 如果是该计划主产物
# 如果是切割
# 获取下一步子工序
if vdata['step'].type == Step.STEP_TYPE_DIV:
stepIds = [i['id'] for i in vdata['subproduction_plan'].steps]
stepIds = [i['id'] for i in i['subproduction_plan'].steps]
pindex = stepIds.index(vdata['step'].id)
wpr = dict(m_state=ma, p_state=Step.objects.get(pk=stepIds[pindex+1]),
act_state=WProduct.WPR_ACT_STATE_DOING, is_executed=False, remark='',
subproduction_plan=vdata['subproduction_plan'],
production_plan=vdata['subproduction_plan'].production_plan)
subproduction_plan=i['subproduction_plan'],
production_plan=i['subproduction_plan'].production_plan)
for x in range(i['count_output']):
WProduct.objects.create(**wpr)
else:
@ -244,18 +251,20 @@ class DoFormSubmit(CreateAPIView, GenericAPIView):
OperationMaterial.objects.create(type=2, operation=action_obj,
material= ma, count=i['count_output'])
# 更新车间物料表
ins, _ = WMaterial.objects.get_or_create(subproduction_plan=vdata['subproduction_plan'],
ins, _ = WMaterial.objects.get_or_create(subproduction_plan=i['subproduction_plan'],
material=ma)
ins.count = ins.count + i['count_output']
ins.save()
# 更新子计划进度表
sp = SubProductionProgress.objects.get(subproduction_plan=vdata['subproduction_plan'],
sp = SubProductionProgress.objects.get(subproduction_plan=i['subproduction_plan'],
material=ma)
sp.count_real = sp.count_real + i['count_input']
sp.save()
# 更新动态产品表
if 'wproducts' in data and data['wproducts']:
if 'wproducts' in vdata and data['wproducts']:
for i in data['wproducts']:
pass
wproducts = WProduct.objects.filter(pk__in=data['wproducts'])
# 获取下一步子工序
stepIds = [i['id'] for i in vdata['subproduction_plan'].steps]