主产出只能有1个

This commit is contained in:
caoqianming 2021-10-21 15:56:45 +08:00
parent b5497a6b75
commit b40efc3ca6
4 changed files with 15 additions and 1 deletions

View File

@ -177,6 +177,7 @@ class OutputMaterial(CommonAModel):
输出物料
"""
material = models.ForeignKey(Material, verbose_name='输出物料', on_delete=models.CASCADE, related_name='outputmaterial')
is_main = models.BooleanField('是否主产出', default=True) # 以该产品完成度计算进度
count = models.FloatField('产出量', default=1)
subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE)
sort = models.IntegerField('排序号', default=1)

View File

@ -101,6 +101,8 @@ class OutputMaterialSerializer(serializers.ModelSerializer):
fields = ['count', 'sort', 'material', 'subproduction']
def create(self, validated_data):
if OutputMaterial.objects.filter(subproduction=validated_data['subproduction'], is_deleted=False, is_main=True).exists():
raise ValidationError('主产出只能有1个')
if OutputMaterial.objects.filter(material=validated_data['material'], subproduction=validated_data['subproduction'], is_deleted=False).exists():
raise ValidationError('该物料已存在')
return super().create(validated_data)

View File

@ -7,6 +7,16 @@ from utils.model import SoftModel, BaseModel
from simple_history.models import HistoricalRecords
class Good(CommonAModel):
"""
物品
"""
number = models.CharField('物品编号', primary_key=True, null=True, blank=True, max_length=50)
m_state = models.ForeignKey('所属物料状态', on_delete=models.CASCADE)
p_state = models.ForeignKey('所在步骤', )
class Vendor(CommonAModel):
"""
供应商信息

View File

@ -55,7 +55,8 @@ INSTALLED_APPS = [
'apps.inm',
'apps.sam',
'apps.qm',
'apps.pm'
'apps.pm',
# 'apps.wpm'
]
MIDDLEWARE = [