feat: 支持领用出库和退还入库
This commit is contained in:
parent
b3b77db0c1
commit
382a5a827c
|
@ -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='出入库类型'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -52,11 +52,13 @@ class MaterialBatchA(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
MIO_TYPE_PREFIX = {
|
MIO_TYPE_PREFIX = {
|
||||||
|
'do_in': 'SCRK', # 生产入库
|
||||||
'do_out': 'SCLL', # 生产领料
|
'do_out': 'SCLL', # 生产领料
|
||||||
'sale_out': 'XSFH', # 销售发货
|
'sale_out': 'XSFH', # 销售发货
|
||||||
'pur_in': 'CGRK', # 采购入库
|
'pur_in': 'CGRK', # 采购入库
|
||||||
'pur_out': 'CGTH', # 采购退货
|
'pur_out': 'CGTH', # 采购退货
|
||||||
'do_in': 'SCRK', # 生产入库
|
'borrow_out': 'LYCK', # 领用出库
|
||||||
|
'return_in': 'THRK', # 退还入库
|
||||||
'other_in': 'QTRK', # 其他入库
|
'other_in': 'QTRK', # 其他入库
|
||||||
'other_out': 'QTCK' # 其他出库
|
'other_out': 'QTCK' # 其他出库
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,8 @@ class MIO(CommonBDModel):
|
||||||
MIO_TYPE_DO_IN = 'do_in'
|
MIO_TYPE_DO_IN = 'do_in'
|
||||||
MIO_TYPE_OTHER_IN = 'other_in'
|
MIO_TYPE_OTHER_IN = 'other_in'
|
||||||
MIO_TYPE_OTHER_OUT = 'other_out'
|
MIO_TYPE_OTHER_OUT = 'other_out'
|
||||||
|
MIO_TYPE_BORROW_OUT = 'borrow_out'
|
||||||
|
MIO_TYPE_RETURN_IN = 'return_in'
|
||||||
|
|
||||||
MIO_TYPES = (
|
MIO_TYPES = (
|
||||||
(MIO_TYPE_DO_OUT, '生产领料'),
|
(MIO_TYPE_DO_OUT, '生产领料'),
|
||||||
|
@ -79,6 +83,8 @@ class MIO(CommonBDModel):
|
||||||
(MIO_TYPE_PUR_IN, '采购入库'),
|
(MIO_TYPE_PUR_IN, '采购入库'),
|
||||||
(MIO_TYPE_PUR_OUT, '采购退货'),
|
(MIO_TYPE_PUR_OUT, '采购退货'),
|
||||||
(MIO_TYPE_DO_IN, '生产入库'),
|
(MIO_TYPE_DO_IN, '生产入库'),
|
||||||
|
(MIO_TYPE_BORROW_OUT, '领用出库'),
|
||||||
|
(MIO_TYPE_RETURN_IN, '退还入库'),
|
||||||
(MIO_TYPE_OTHER_IN, '其他入库'),
|
(MIO_TYPE_OTHER_IN, '其他入库'),
|
||||||
(MIO_TYPE_OTHER_OUT, '其他出库')
|
(MIO_TYPE_OTHER_OUT, '其他出库')
|
||||||
)
|
)
|
||||||
|
|
|
@ -139,6 +139,9 @@ class MIOItemCreateSerializer(CustomModelSerializer):
|
||||||
batch = validated_data['batch']
|
batch = validated_data['batch']
|
||||||
if material.is_hidden:
|
if material.is_hidden:
|
||||||
raise ParseError('隐式物料不可出入库')
|
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:
|
if mio.state != MIO.MIO_CREATE:
|
||||||
raise ParseError('出入库记录非创建中不可新增')
|
raise ParseError('出入库记录非创建中不可新增')
|
||||||
|
|
|
@ -306,7 +306,7 @@ class InmService:
|
||||||
cls.update_mb(instance, -1)
|
cls.update_mb(instance, -1)
|
||||||
else:
|
else:
|
||||||
cls.update_mb(instance, 1)
|
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)
|
mioitems = MIOItem.objects.filter(mio=instance)
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
for item in mioitems:
|
for item in mioitems:
|
||||||
|
@ -314,6 +314,14 @@ class InmService:
|
||||||
else:
|
else:
|
||||||
for item in mioitems:
|
for item in mioitems:
|
||||||
do_in(item)
|
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:
|
elif instance.type == MIO.MIO_TYPE_SALE_OUT:
|
||||||
from apps.sam.services import SamService
|
from apps.sam.services import SamService
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
|
@ -326,14 +334,6 @@ class InmService:
|
||||||
cls.update_mb(instance, 1)
|
cls.update_mb(instance, 1)
|
||||||
else:
|
else:
|
||||||
cls.update_mb(instance, -1)
|
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:
|
else:
|
||||||
raise ParseError('不支持该出入库操作')
|
raise ParseError('不支持该出入库操作')
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ class MIOViewSet(CustomModelViewSet):
|
||||||
if self.action in ['create', 'update', 'partial_update']:
|
if self.action in ['create', 'update', 'partial_update']:
|
||||||
type = self.request.data.get('type')
|
type = self.request.data.get('type')
|
||||||
user = self.request.user
|
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']):
|
if not has_perm(user, ['mio.do']):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
return MIODoSerializer
|
return MIODoSerializer
|
||||||
|
|
Loading…
Reference in New Issue