From a587e570f0a6804911d7f8a28c9dc8c4394d64c7 Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 30 Jul 2024 11:40:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mio=20=E6=B7=BB=E5=8A=A0=20mgroup?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/inm/models.py | 3 ++- apps/inm/serializers.py | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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('出入库类型错误')