feat: 增加is_count_utask字段以确认同步utask
This commit is contained in:
parent
5ba3b4e07a
commit
cbc43fdb65
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2023-10-26 10:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mtm', '0018_material_need_route'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='route',
|
||||
name='is_count_utask',
|
||||
field=models.BooleanField(default=False, verbose_name='是否主任务统计'),
|
||||
),
|
||||
]
|
|
@ -1,7 +1,7 @@
|
|||
from django.db import models
|
||||
from apps.system.models import CommonAModel, Dictionary, CommonBModel, CommonADModel, File, BaseModel
|
||||
from django.db.models import Subquery, OuterRef
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.exceptions import ValidationError, ParseError
|
||||
|
||||
|
||||
class Process(CommonBModel):
|
||||
|
@ -154,6 +154,7 @@ class Route(CommonADModel):
|
|||
Material, verbose_name='主要输入物料', on_delete=models.CASCADE, related_name='route_material_in', null=True, blank=True)
|
||||
material_out = models.ForeignKey(
|
||||
Material, verbose_name='主要输出物料', on_delete=models.CASCADE, related_name='route_material_out', null=True, blank=True)
|
||||
is_count_utask = models.BooleanField('是否主任务统计', default=False)
|
||||
out_rate = models.FloatField('出材率', default=100, null=True, blank=True)
|
||||
|
||||
@staticmethod
|
||||
|
@ -166,7 +167,9 @@ class Route(CommonADModel):
|
|||
rq = Route.objects.filter(
|
||||
**kwargs).order_by('sort', 'process__sort', 'create_time')
|
||||
if rq.first().material_in is None or rq.last().material_out is None or rq.last().material_out != rq.last().material:
|
||||
raise ValidationError('首步缺少输入/最后一步缺少输出')
|
||||
raise ParseError('首步缺少输入/最后一步缺少输出')
|
||||
if not rq.filter(is_count_utask=True).exists():
|
||||
raise ParseError('未指定统计步骤')
|
||||
if autotask:
|
||||
kwargs['is_autotask'] = True
|
||||
return rq
|
||||
|
|
|
@ -4,6 +4,7 @@ from apps.utils.constants import EXCLUDE_FIELDS
|
|||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from apps.system.models import Dept
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
class ShiftSerializer(CustomModelSerializer):
|
||||
|
@ -113,19 +114,24 @@ class RouteSerializer(CustomModelSerializer):
|
|||
instance.save()
|
||||
|
||||
def create(self, validated_data):
|
||||
instance = super().create(validated_data)
|
||||
if 'material_out' in validated_data and validated_data['material_out']:
|
||||
pass
|
||||
else:
|
||||
self.gen_material_out(instance)
|
||||
return instance
|
||||
process = validated_data['process']
|
||||
if Route.objects.filter(material=validated_data['material'], process=process).exists():
|
||||
raise ValidationError('已选择该工序')
|
||||
with transaction.atomic():
|
||||
instance = super().create(validated_data)
|
||||
if 'material_out' in validated_data and validated_data['material_out']:
|
||||
pass
|
||||
else:
|
||||
self.gen_material_out(instance)
|
||||
return instance
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
validated_data.pop('material', None)
|
||||
validated_data.pop('process', None)
|
||||
instance = super().update(instance, validated_data)
|
||||
if 'material_out' in validated_data and validated_data['material_out']:
|
||||
pass
|
||||
else:
|
||||
self.gen_material_out(instance)
|
||||
return instance
|
||||
with transaction.atomic():
|
||||
instance = super().update(instance, validated_data)
|
||||
if 'material_out' in validated_data and validated_data['material_out']:
|
||||
pass
|
||||
else:
|
||||
self.gen_material_out(instance)
|
||||
return instance
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2023-10-26 10:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pm', '0012_auto_20231026_1624'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mtask',
|
||||
name='is_count_utask',
|
||||
field=models.BooleanField(default=False, verbose_name='是否主任务统计'),
|
||||
),
|
||||
]
|
|
@ -63,6 +63,7 @@ class Mtask(CommonADModel):
|
|||
Material, verbose_name='领用物', on_delete=models.CASCADE, related_name='mtask_material_in', null=True, blank=True)
|
||||
material_out = models.ForeignKey(
|
||||
Material, verbose_name='产物', on_delete=models.CASCADE, related_name='mtask_material_out')
|
||||
is_count_utask = models.BooleanField('是否主任务统计', default=False)
|
||||
count = models.PositiveIntegerField('任务数', default=1)
|
||||
count_real = models.PositiveIntegerField('实际生产数', default=0)
|
||||
count_ok = models.PositiveIntegerField('合格数', default=0)
|
||||
|
|
|
@ -126,7 +126,8 @@ class PmService:
|
|||
'end_date': task_date,
|
||||
'utask': utask,
|
||||
'create_by': user,
|
||||
'update_by': user
|
||||
'update_by': user,
|
||||
'is_count_utask': val.is_count_utask
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -157,8 +157,8 @@ def update_mtask(mtask: Mtask):
|
|||
mtask.count_notok = res['sum_count_notok'] if res['sum_count_notok'] else 0
|
||||
mtask.save()
|
||||
utask = mtask.utask
|
||||
if utask and mtask.material_out == utask.material:
|
||||
res2 = Mtask.objects.filter(utask=utask, material_out=utask.material).aggregate(sum_count_real=Sum(
|
||||
if utask and mtask.is_count_utask:
|
||||
res2 = Mtask.objects.filter(utask=utask, mgroup=mtask.mgroup).aggregate(sum_count_real=Sum(
|
||||
'count_real'), sum_count_ok=Sum('count_ok'), sum_count_notok=Sum('count_notok'))
|
||||
utask.count_real = res2['sum_count_real'] if res2['sum_count_real'] else 0
|
||||
utask.count_ok = res2['sum_count_ok'] if res2['sum_count_ok'] else 0
|
||||
|
|
Loading…
Reference in New Issue