更新子计划进度
This commit is contained in:
parent
3fbede05f7
commit
da1237c421
|
@ -32,12 +32,17 @@ class SubProductionPlan(CommonAModel):
|
|||
"""
|
||||
子生产计划
|
||||
"""
|
||||
SUBPLAN_STATE_PLANING = 0
|
||||
SUBPLAN_STATE_ASSGINED = 1
|
||||
SUBPLAN_STATE_ACCEPTED = 2
|
||||
SUBPLAN_STATE_WORKING = 3
|
||||
SUBPLAN_STATE_DONE = 4
|
||||
state_choices=(
|
||||
(0, '制定中'),
|
||||
(1, '已下达'),
|
||||
(2, '已接收'),
|
||||
(3, '生产中'),
|
||||
(4, '已完成')
|
||||
(SUBPLAN_STATE_PLANING, '制定中'),
|
||||
(SUBPLAN_STATE_ASSGINED, '已下达'),
|
||||
(SUBPLAN_STATE_ACCEPTED, '已接收'),
|
||||
(SUBPLAN_STATE_WORKING, '生产中'),
|
||||
(SUBPLAN_STATE_DONE, '已完成')
|
||||
)
|
||||
production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE)
|
||||
subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='subplan_subprod')
|
||||
|
@ -53,7 +58,7 @@ class SubProductionPlan(CommonAModel):
|
|||
|
||||
steps = models.JSONField('工艺步骤', default=list)
|
||||
|
||||
state = models.IntegerField('状态', default=0)
|
||||
state = models.IntegerField('状态', default=SUBPLAN_STATE_PLANING)
|
||||
start_date_real = models.DateField('实际开工日期', null=True, blank=True)
|
||||
end_date_real = models.DateField('实际完工日期', null=True, blank=True)
|
||||
is_picked = models.BooleanField('是否已领料', default=False)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from apps.pm.models import SubProductionProgress
|
||||
from apps.pm.models import SubProductionPlan, SubProductionProgress
|
||||
|
||||
@receiver(post_save, sender=SubProductionProgress)
|
||||
def update_subplan_main(sender, instance, created, **kwargs):
|
||||
|
@ -13,8 +13,8 @@ def update_subplan_main(sender, instance, created, **kwargs):
|
|||
subplan.main_product = instance.material
|
||||
subplan.main_count = instance.count
|
||||
subplan.main_count_real = instance.count_real
|
||||
if instance.count_real>= instance.count:
|
||||
subplan.state = 4
|
||||
if instance.count_real>= instance.count and instance.count_real != 0:
|
||||
subplan.state = SubProductionPlan.SUBPLAN_STATE_DONE
|
||||
subplan.save()
|
||||
|
||||
|
||||
|
|
|
@ -133,8 +133,8 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo
|
|||
下达任务
|
||||
"""
|
||||
obj = self.get_object()
|
||||
if obj.state == 0:
|
||||
obj.state = 1
|
||||
if obj.state == SubProductionPlan.SUBPLAN_STATE_PLANING:
|
||||
obj.state = SubProductionPlan.SUBPLAN_STATE_ASSGINED
|
||||
obj.save()
|
||||
return Response()
|
||||
raise APIException('计划状态有误')
|
||||
|
@ -145,8 +145,8 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo
|
|||
开始生产
|
||||
"""
|
||||
obj = self.get_object()
|
||||
if obj.state in [1,2]:
|
||||
obj.state = 3
|
||||
if obj.state in [SubProductionPlan.SUBPLAN_STATE_ASSGINED, SubProductionPlan.SUBPLAN_STATE_ACCEPTED]:
|
||||
obj.state = SubProductionPlan.SUBPLAN_STATE_WORKING
|
||||
obj.start_date_real = timezone.now()
|
||||
obj.save()
|
||||
return Response()
|
||||
|
|
|
@ -32,7 +32,8 @@ class PickSerializer(serializers.Serializer):
|
|||
def create(self, validated_data):
|
||||
picks = validated_data.pop('picks')
|
||||
sp = validated_data.pop('subproduction_plan')
|
||||
if sp.state not in [1, 2, 3]:
|
||||
if sp.state not in [SubProductionPlan.SUBPLAN_STATE_ASSGINED, SubProductionPlan.SUBPLAN_STATE_ACCEPTED,
|
||||
SubProductionPlan.SUBPLAN_STATE_WORKING]:
|
||||
raise exceptions.ValidationError('该子计划状态错误')
|
||||
# if sp.is_picked:
|
||||
# raise exceptions.ValidationError('该子计划已领料')
|
||||
|
@ -95,7 +96,7 @@ class PickSerializer(serializers.Serializer):
|
|||
act_state=WProduct.WPR_ACT_STATE_DOING, is_hidden=False, warehouse=None,
|
||||
subproduction_plan=sp, production_plan=sp.production_plan)
|
||||
sp.is_picked=True
|
||||
sp.state = 3 #生产中
|
||||
sp.state = SubProductionPlan.SUBPLAN_STATE_WORKING #生产中
|
||||
sp.state_date_real = timezone.now() #实际开工日期
|
||||
sp.save()
|
||||
# 更新库存
|
||||
|
|
Loading…
Reference in New Issue