feat: mgroup增加自产和外协字段及相关逻辑

This commit is contained in:
caoqianming 2025-03-19 14:27:07 +08:00
parent 1040e55a48
commit 459fc3bbe8
3 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2025-03-19 06:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mtm', '0052_routepack_document'),
]
operations = [
migrations.AddField(
model_name='mgroup',
name='mtype',
field=models.PositiveSmallIntegerField(default=10, help_text='10:自产 20:外协', verbose_name='工段类型'),
),
]

View File

@ -129,11 +129,13 @@ class Team(CommonBModel):
class Mgroup(CommonBModel):
"""测点集
"""
M_SELF = 10
M_OTHER = 20
name = models.CharField('名称', max_length=50)
code = models.CharField('标识', max_length=50, null=True, blank=True)
cate = models.CharField(
'分类', max_length=50, default='section', help_text='section/other') # section是工段
mtype = models.PositiveSmallIntegerField("工段类型", default=10, help_text='10:自产 20:外协')
shift_rule = models.CharField('班次规则', max_length=10, default='默认')
process = models.ForeignKey(
Process, verbose_name='工序', on_delete=models.SET_NULL, null=True, blank=True)

View File

@ -598,7 +598,8 @@ class MlogInitSerializer(CustomModelSerializer):
model = Mlog
fields = ['id',
'work_start_time', 'work_end_time', 'mgroup', 'reminder_interval_list',
'route', 'equipment', 'handle_user', 'note', 'mtype', 'supplier', 'test_file', 'test_user', 'test_time', 'oinfo_json', 'is_fix']
'route', 'equipment', 'handle_user', 'note', 'supplier', 'test_file', 'test_user', 'test_time', 'oinfo_json', 'is_fix']
read_only_fields = ["mtype"]
extra_kwargs = {
'work_start_time': {'required': True},
'route':{'required': False},
@ -607,10 +608,10 @@ class MlogInitSerializer(CustomModelSerializer):
}
def validate(self, attrs):
mtype = attrs['mtype']
route: Route = attrs.get('route', None)
mgroup: Mgroup = attrs['mgroup']
is_fix:bool = attrs.get('is_fix', False)
attrs['mtype'] = mgroup.mtype
if is_fix:
attrs["route"] = None
elif route is None:
@ -626,7 +627,7 @@ class MlogInitSerializer(CustomModelSerializer):
attrs['material_in'] = route.material_in
attrs['material_out'] = route.material_out
attrs['fill_way'] = Mlog.MLOG_23
if mtype == Mlog.MTYPE_OUT:
if attrs['mtype'] == Mlog.MTYPE_OUT:
supplier = attrs.get('supplier', None)
if not supplier:
raise ParseError('外协必须选择外协单位')