feat: 添加count_json_from字段及相应逻辑

This commit is contained in:
caoqianming 2025-04-16 11:31:23 +08:00
parent 4c7f2b24f8
commit e0217e86c4
5 changed files with 45 additions and 15 deletions

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.12 on 2025-04-16 03:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wpm', '0108_auto_20250414_2244'),
]
operations = [
migrations.AddField(
model_name='mlogb',
name='count_json_from',
field=models.JSONField(blank=True, default=list, verbose_name='层布局数据'),
),
migrations.AddField(
model_name='mlogb',
name='count_json_wx',
field=models.JSONField(blank=True, default=list, verbose_name='外协自定义数据'),
),
]

View File

@ -372,6 +372,9 @@ class Mlogb(BaseModel):
count_n_qt = models.DecimalField('其他', default=0, max_digits=11, decimal_places=1) count_n_qt = models.DecimalField('其他', default=0, max_digits=11, decimal_places=1)
count_notok_json = models.JSONField('不合格情况', default=list, blank=True) count_notok_json = models.JSONField('不合格情况', default=list, blank=True)
count_json = models.JSONField('各物料数量', default=list, blank=True) count_json = models.JSONField('各物料数量', default=list, blank=True)
count_json_from = models.JSONField("层布局数据", default=list, blank=True)
count_json_wx = models.JSONField('外协自定义数据', default=list, blank=True)
def get_tracking(self): def get_tracking(self):
if self.material_in: if self.material_in:
return "in", self.material_in.tracking return "in", self.material_in.tracking

View File

@ -658,21 +658,22 @@ class MlogChangeSerializer(CustomModelSerializer):
class CountJsonSerializer(serializers.Serializer): class CountJsonSerializer(serializers.Serializer):
count_use = serializers.IntegerField(min_value=0, required=True) count_use = serializers.IntegerField(min_value=0, required=True)
floor = serializers.IntegerField(min_value=1, required=True) floor = serializers.IntegerField(min_value=1, required=True)
class CountJson2Serializer(serializers.Serializer):
count_use = serializers.IntegerField(min_value=0, required=True)
floor = serializers.IntegerField(min_value=1, required=True)
count_test = serializers.IntegerField(min_value=0, required=True) count_test = serializers.IntegerField(min_value=0, required=True)
count_notok = serializers.IntegerField(min_value=0, required=True) count_notok = serializers.IntegerField(min_value=0, required=True)
class CountJsonFromSerializer(serializers.Serializer):
start = serializers.IntegerField(min_value=0, required=True)
end = serializers.IntegerField(min_value=0, required=True)
count_t = serializers.IntegerField(min_value=0, required=True, label="总数")
class MlogbInSerializer(CustomModelSerializer): class MlogbInSerializer(CustomModelSerializer):
mlogbdefect = MlogbDefectSerializer(many=True, required=False) mlogbdefect = MlogbDefectSerializer(many=True, required=False)
count_json = CountJsonSerializer(required=False, many=True) count_json_from = CountJsonFromSerializer(required=False, many=True)
class Meta: class Meta:
model = Mlogb model = Mlogb
fields = ['id', 'mlog', 'mtask', 'wm_in', 'count_use', 'count_pn_jgqbl', fields = ['id', 'mlog', 'mtask', 'wm_in', 'count_use', 'count_pn_jgqbl',
'count_break', 'note', "parent", "mlogbdefect", "count_json"] 'count_break', 'note', "parent", "mlogbdefect", "count_json_from"]
extra_kwargs = {'count_use': {'required': True}, 'mtask': {'required': False}, extra_kwargs = {'count_use': {'required': True}, 'mtask': {'required': False},
'wm_in': {'required': True, "allow_empty": False}} 'wm_in': {'required': True, "allow_empty": False}}
@ -721,7 +722,7 @@ class MlogbInSerializer(CustomModelSerializer):
if mlog.material_in is None: if mlog.material_in is None:
mlog.material_in = ins.material_in mlog.material_in = ins.material_in
mlog.material_out = ins.material_in mlog.material_out = ins.material_in
mlog.save(update_fields="material_in") mlog.save(update_fields=["material_in", "material_out"])
elif mlog.material_in != ins.material_in: elif mlog.material_in != ins.material_in:
raise ParseError('该记录必须使用同一物料') raise ParseError('该记录必须使用同一物料')
@ -813,7 +814,7 @@ class MlogbwCreateUpdateSerializer(CustomModelSerializer):
class MlogbOutUpdateSerializer(CustomModelSerializer): class MlogbOutUpdateSerializer(CustomModelSerializer):
mlogbdefect = MlogbDefectSerializer(many=True, required=False) mlogbdefect = MlogbDefectSerializer(many=True, required=False)
count_json = CountJson2Serializer(required=False, many=True) count_json = CountJsonSerializer(required=False, many=True)
class Meta: class Meta:
model = Mlogb model = Mlogb
@ -1061,7 +1062,9 @@ class HandoverSerializer(CustomModelSerializer):
if mtype == Handover.H_DIV: if mtype == Handover.H_DIV:
if not item["batch"]: if not item["batch"]:
raise ParseError(f'{ind+1}行-请提供拆批批次号') raise ParseError(f'{ind+1}行-请提供拆批批次号')
handoverb = Handoverb.objects.create(handover=ins, batch=item["batch"], count=count, wm=wm) if wm is not None:
raise ParseError("拆批错误")
handoverb = Handoverb.objects.create(handover=ins, batch=item["batch"], count=count, wm=ins.wm)
else: else:
handoverb = Handoverb.objects.create(handover=ins, wm=wm, count=count, batch=wm.batch) handoverb = Handoverb.objects.create(handover=ins, wm=wm, count=count, batch=wm.batch)
if wm.material.tracking == Material.MA_TRACKING_SINGLE: if wm.material.tracking == Material.MA_TRACKING_SINGLE:

View File

@ -731,6 +731,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material) target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
if handover.wm is None: if handover.wm is None:
raise ParseError('拆批请选择车间库存') raise ParseError('拆批请选择车间库存')
wm_from = handover.wm
source, _ = BatchSt.g_create(batch=handover.wm.batch) source, _ = BatchSt.g_create(batch=handover.wm.batch)
BatchLog.g_create(source=source, target=target, handover=handover, relation_type="split") BatchLog.g_create(source=source, target=target, handover=handover, relation_type="split")
else: else:

View File

@ -605,8 +605,8 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
d_count_ok = mlogbin.count_use d_count_ok = mlogbin.count_use
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults= mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=
update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok})) update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
mlogbout.count_json = mlogbin.count_json mlogbout.count_json_from = mlogbin.count_json_from
mlogbout.save(update_fields=["count_json"]) mlogbout.save(update_fields=["count_json_from"])
if material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_SINGLE: if material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_SINGLE:
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"): for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
wpr_ = mlogbwin.wpr wpr_ = mlogbwin.wpr
@ -630,15 +630,15 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
d_count_real = mlogbin.count_use * div_number d_count_real = mlogbin.count_use * div_number
d_count_ok = d_count_real d_count_ok = d_count_real
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict,{"count_real": d_count_real, "count_ok": d_count_ok})) mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict,{"count_real": d_count_real, "count_ok": d_count_ok}))
mlogbout.count_json = mlogbin.count_json mlogbout.count_json_from = mlogbin.count_json_from
mlogbout.save(update_fields=["count_json"]) mlogbout.save(update_fields=["count_json_from"])
elif mtype == Process.PRO_MERGE: # 支持批到批 elif mtype == Process.PRO_MERGE: # 支持批到批
xcount = math.floor( mlogbin.count_use / route.div_number) xcount = math.floor( mlogbin.count_use / route.div_number)
d_count_real = xcount d_count_real = xcount
d_count_ok = xcount d_count_ok = xcount
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok})) mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
mlogbout.count_json = mlogbin.count_json mlogbout.count_json_from = mlogbin.count_json_from
mlogbout.save(update_fields=["count_json"]) mlogbout.save(update_fields=["count_json_from"])
elif is_fix:# 支持批到批,个到个 elif is_fix:# 支持批到批,个到个
d_count_real = mlogbin.count_use d_count_real = mlogbin.count_use
d_count_ok = mlogbin.count_use d_count_ok = mlogbin.count_use