diff --git a/apps/inm/models.py b/apps/inm/models.py index 7c0fe546..c14b6afc 100644 --- a/apps/inm/models.py +++ b/apps/inm/models.py @@ -2,7 +2,7 @@ from django.db import models from apps.utils.models import BaseModel, CommonBModel, CommonBDModel, CommonADModel from apps.pum.models import Supplier, PuOrder from apps.sam.models import Customer, Order -from apps.mtm.models import Material +from apps.mtm.models import Material, Mgroup from apps.system.models import User # Create your models here. @@ -75,6 +75,7 @@ class MIO(CommonBDModel): '状态', choices=MIO_STATES, default=10, help_text=str(MIO_CREATE)) type = models.CharField('出入库类型', max_length=10, default=MIO_TYPE_DO_OUT, choices=MIO_TYPES, help_text=str(MIO_TYPES)) + mgroup = models.ForeignKey(Mgroup, verbose_name='出入库工段', on_delete=models.CASCADE, null=True, blank=True) inout_date = models.DateField('出入库日期', null=True, blank=True) supplier = models.ForeignKey( Supplier, verbose_name='供应商', on_delete=models.CASCADE, null=True, blank=True) diff --git a/apps/inm/serializers.py b/apps/inm/serializers.py index 31850e11..caf3623f 100644 --- a/apps/inm/serializers.py +++ b/apps/inm/serializers.py @@ -65,6 +65,7 @@ class MIOListSerializer(CustomModelSerializer): source='mio_user.name', read_only=True) belong_dept_name = serializers.CharField( source='belong_dept.name', read_only=True) + mgroup_name = serializers.CharField(source='mgroup.name', read_only=True) supplier_name = serializers.CharField( source='supplier.name', read_only=True) customer_name = serializers.CharField( @@ -163,8 +164,13 @@ class MIODoSerializer(CustomModelSerializer): class Meta: model = MIO fields = ['id', 'number', 'note', 'do_user', - 'belong_dept', 'type', 'inout_date'] + 'belong_dept', 'type', 'inout_date', 'mgroup'] + def validate(self, attrs): + if 'mgroup' in attrs and attrs['mgroup']: + attrs['belong_dept'] = attrs['mgroup'].belong_dept + return attrs + def create(self, validated_data): if validated_data['type'] not in [MIO.MIO_TYPE_DO_OUT, MIO.MIO_TYPE_DO_IN]: raise ValidationError('出入库类型错误')