diff --git a/apps/inm/migrations/0033_alter_mio_type.py b/apps/inm/migrations/0033_alter_mio_type.py new file mode 100644 index 00000000..28a3eb24 --- /dev/null +++ b/apps/inm/migrations/0033_alter_mio_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2025-07-28 05:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('inm', '0032_auto_20250723_1639'), + ] + + operations = [ + migrations.AlterField( + model_name='mio', + name='type', + field=models.CharField(choices=[('do_out', '生产领料'), ('sale_out', '销售发货'), ('pur_in', '采购入库'), ('pur_out', '采购退货'), ('do_in', '生产入库'), ('borrow_out', '领用出库'), ('return_in', '退还入库'), ('other_in', '其他入库'), ('other_out', '其他出库')], default='do_out', help_text="(('do_out', '生产领料'), ('sale_out', '销售发货'), ('pur_in', '采购入库'), ('pur_out', '采购退货'), ('do_in', '生产入库'), ('borrow_out', '领用出库'), ('return_in', '退还入库'), ('other_in', '其他入库'), ('other_out', '其他出库'))", max_length=10, verbose_name='出入库类型'), + ), + ] diff --git a/apps/inm/models.py b/apps/inm/models.py index 70bc36a7..44a8737d 100644 --- a/apps/inm/models.py +++ b/apps/inm/models.py @@ -52,11 +52,13 @@ class MaterialBatchA(BaseModel): MIO_TYPE_PREFIX = { + 'do_in': 'SCRK', # 生产入库 'do_out': 'SCLL', # 生产领料 'sale_out': 'XSFH', # 销售发货 'pur_in': 'CGRK', # 采购入库 'pur_out': 'CGTH', # 采购退货 - 'do_in': 'SCRK', # 生产入库 + 'borrow_out': 'LYCK', # 领用出库 + 'return_in': 'THRK', # 退还入库 'other_in': 'QTRK', # 其他入库 'other_out': 'QTCK' # 其他出库 } @@ -72,6 +74,8 @@ class MIO(CommonBDModel): MIO_TYPE_DO_IN = 'do_in' MIO_TYPE_OTHER_IN = 'other_in' MIO_TYPE_OTHER_OUT = 'other_out' + MIO_TYPE_BORROW_OUT = 'borrow_out' + MIO_TYPE_RETURN_IN = 'return_in' MIO_TYPES = ( (MIO_TYPE_DO_OUT, '生产领料'), @@ -79,6 +83,8 @@ class MIO(CommonBDModel): (MIO_TYPE_PUR_IN, '采购入库'), (MIO_TYPE_PUR_OUT, '采购退货'), (MIO_TYPE_DO_IN, '生产入库'), + (MIO_TYPE_BORROW_OUT, '领用出库'), + (MIO_TYPE_RETURN_IN, '退还入库'), (MIO_TYPE_OTHER_IN, '其他入库'), (MIO_TYPE_OTHER_OUT, '其他出库') ) diff --git a/apps/inm/serializers.py b/apps/inm/serializers.py index 76a6586c..9c7910eb 100644 --- a/apps/inm/serializers.py +++ b/apps/inm/serializers.py @@ -139,6 +139,9 @@ class MIOItemCreateSerializer(CustomModelSerializer): batch = validated_data['batch'] if material.is_hidden: raise ParseError('隐式物料不可出入库') + if mio.type in [MIO.MIO_TYPE_RETURN_IN, MIO.MIO_TYPE_BORROW_OUT]: + if not material.into_wm: + raise ParseError('该物料不可领用或归还') if mio.state != MIO.MIO_CREATE: raise ParseError('出入库记录非创建中不可新增') diff --git a/apps/inm/services.py b/apps/inm/services.py index 70e057a0..f511bfb3 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -306,7 +306,7 @@ class InmService: cls.update_mb(instance, -1) else: cls.update_mb(instance, 1) - elif instance.type == MIO.MIO_TYPE_DO_IN: + elif instance.type in [MIO.MIO_TYPE_DO_IN, MIO.MIO_TYPE_RETURN_IN]: mioitems = MIOItem.objects.filter(mio=instance) if is_reverse: for item in mioitems: @@ -314,6 +314,14 @@ class InmService: else: for item in mioitems: do_in(item) + elif instance.type in [MIO.MIO_TYPE_DO_OUT, MIO.MIO_TYPE_BORROW_OUT]: + mioitems = MIOItem.objects.filter(mio=instance) + if is_reverse: + for item in mioitems: + do_in(item) + else: + for item in mioitems: + do_out(item) elif instance.type == MIO.MIO_TYPE_SALE_OUT: from apps.sam.services import SamService if is_reverse: @@ -326,14 +334,6 @@ class InmService: cls.update_mb(instance, 1) else: cls.update_mb(instance, -1) - elif instance.type == MIO.MIO_TYPE_DO_OUT: - mioitems = MIOItem.objects.filter(mio=instance) - if is_reverse: - for item in mioitems: - do_in(item) - else: - for item in mioitems: - do_out(item) else: raise ParseError('不支持该出入库操作') diff --git a/apps/inm/views.py b/apps/inm/views.py index a8e37112..451a9c9e 100644 --- a/apps/inm/views.py +++ b/apps/inm/views.py @@ -170,7 +170,7 @@ class MIOViewSet(CustomModelViewSet): if self.action in ['create', 'update', 'partial_update']: type = self.request.data.get('type') user = self.request.user - if type in [MIO.MIO_TYPE_DO_IN, MIO.MIO_TYPE_DO_OUT]: + if type in [MIO.MIO_TYPE_DO_IN, MIO.MIO_TYPE_DO_OUT, MIO.MIO_TYPE_BORROW_OUT, MIO.MIO_TYPE_RETURN_IN]: if not has_perm(user, ['mio.do']): raise PermissionDenied return MIODoSerializer