diff --git a/apps/inm/services.py b/apps/inm/services.py index 5e2c52b6..78a98238 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -239,9 +239,8 @@ class InmService: if is_reverse: BatchLog.clear(mio=instance) else: - batches = [item.batch for item in MIOItem.objects.filter(mio=instance)] - for item in batches: - BatchSt.create(batch=item, mio=instance) + for item in MIOItem.objects.filter(mio=instance): + BatchSt.create(batch=item.batch, mio=instance, material_start=item.material) from apps.pum.services import PumService cls.update_mb(instance, in_or_out) PumService.mio_purin(instance, is_reverse) @@ -249,9 +248,8 @@ class InmService: if is_reverse: BatchLog.clear(mio=instance) else: - batches = [item.batch for item in MIOItem.objects.filter(mio=instance)] - for item in batches: - BatchSt.create(batch=item, mio=instance) + for item in MIOItem.objects.filter(mio=instance): + BatchSt.create(batch=item, mio=instance, material_start=item.material) cls.update_mb(instance, in_or_out) elif instance.type == MIO.MIO_TYPE_DO_IN: mioitems = MIOItem.objects.filter(mio=instance) diff --git a/apps/wpm/filters.py b/apps/wpm/filters.py index 2a6b458d..0e32bc8b 100644 --- a/apps/wpm/filters.py +++ b/apps/wpm/filters.py @@ -176,7 +176,9 @@ class BatchStFilter(filters.FilterSet): fields = { "batch": ["exact", "contains", "startswith"], "last_time": ["exact", "gte", "lte"], - "update_time": ["exact", "gte", "lte"] + "update_time": ["exact", "gte", "lte"], + "material_start": ["exact"], + "material_start__type": ["exact"] } def filter_batch(self, queryset, name, value): diff --git a/apps/wpm/migrations/0103_batchst_material_start.py b/apps/wpm/migrations/0103_batchst_material_start.py new file mode 100644 index 00000000..412824cc --- /dev/null +++ b/apps/wpm/migrations/0103_batchst_material_start.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.12 on 2025-03-24 07:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('mtm', '0054_process_parent'), + ('wpm', '0102_mloguser'), + ] + + operations = [ + migrations.AddField( + model_name='batchst', + name='material_start', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='mtm.material', verbose_name='起始物料'), + ), + ] diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 0feebc9f..54390bb0 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -587,12 +587,13 @@ class BatchSt(BaseModel): batch = models.TextField("批次号", unique=True, db_index=True) last_time = models.DateTimeField("最后操作时间", null=True, blank=True) data = models.JSONField("数据", default=list, blank=True) + material_start = models.ForeignKey(Material, verbose_name="起始物料", on_delete=models.SET_NULL, null=True, blank=True) mio = models.ForeignKey("inm.mio", verbose_name="由何出入库记录创建", on_delete=models.CASCADE, null=True, blank=True) handover = models.ForeignKey(Handover, verbose_name='由何交接记录创建', on_delete=models.CASCADE, null=True, blank=True) mlog = models.ForeignKey(Mlog, verbose_name='由何日志创建', on_delete=models.CASCADE, null=True, blank=True) @classmethod - def create(cls, batch:str, mio=None, handover=None, mlog=None): + def create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None): """ 创建新的批次 """ diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 0d71ee0e..bf3664c2 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -171,10 +171,10 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False) for item in m_outs: if item.mlogb_from and item.batch != item.mlogb_from.batch: - BatchSt.create(batch=item.batch, mlog=mlog) + BatchSt.create(batch=item.batch, mlog=mlog, material_start=item.material_out) BatchLog.g_create(source_b=item.mlogb_from.batch, target_b=item.batch, mlog=mlog) if item.mlogbw_from and item.batch != item.mlogbw_from.mlogb.batch: - BatchSt.create(batch=item.batch, mlog=mlog) + BatchSt.create(batch=item.batch, mlog=mlog, material_start=item.material_out) BatchLog.g_create(source_b=item.mlogbw_from.mlogb.batch, target_b=item.batch, mlog=mlog) if material_in or is_fix: # 需要进行车间库存管理 @@ -718,12 +718,12 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, if mtype == Handover.H_MERGE: batch = new_batch if create_new_batch is False: - BatchSt.create(batch=batch, handover=handover) + BatchSt.create(batch=batch, handover=handover, material_start=material) create_new_batch = True BatchLog.g_create(source_b=wm_from.batch, target_b=batch, handover=handover, relation_type="merge") elif mtype == Handover.H_DIV: batch = handover_or_b.batch - BatchSt.create(batch=batch, handover=handover) + BatchSt.create(batch=batch, handover=handover, material_start=material) BatchLog.g_create(source_b=handover.wm.batch, target_b=batch, handover=handover, relation_type="split") else: batch = wm_from.batch