feat: batchst添加字段以追踪
This commit is contained in:
parent
e07f9c877c
commit
b070b312a8
|
@ -239,9 +239,8 @@ class InmService:
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
batches = [item.batch for item in MIOItem.objects.filter(mio=instance)]
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
for item in batches:
|
BatchSt.create(batch=item.batch, mio=instance, material_start=item.material)
|
||||||
BatchSt.create(batch=item, mio=instance)
|
|
||||||
from apps.pum.services import PumService
|
from apps.pum.services import PumService
|
||||||
cls.update_mb(instance, in_or_out)
|
cls.update_mb(instance, in_or_out)
|
||||||
PumService.mio_purin(instance, is_reverse)
|
PumService.mio_purin(instance, is_reverse)
|
||||||
|
@ -249,9 +248,8 @@ class InmService:
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
batches = [item.batch for item in MIOItem.objects.filter(mio=instance)]
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
for item in batches:
|
BatchSt.create(batch=item, mio=instance, material_start=item.material)
|
||||||
BatchSt.create(batch=item, mio=instance)
|
|
||||||
cls.update_mb(instance, in_or_out)
|
cls.update_mb(instance, in_or_out)
|
||||||
elif instance.type == MIO.MIO_TYPE_DO_IN:
|
elif instance.type == MIO.MIO_TYPE_DO_IN:
|
||||||
mioitems = MIOItem.objects.filter(mio=instance)
|
mioitems = MIOItem.objects.filter(mio=instance)
|
||||||
|
|
|
@ -176,7 +176,9 @@ class BatchStFilter(filters.FilterSet):
|
||||||
fields = {
|
fields = {
|
||||||
"batch": ["exact", "contains", "startswith"],
|
"batch": ["exact", "contains", "startswith"],
|
||||||
"last_time": ["exact", "gte", "lte"],
|
"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):
|
def filter_batch(self, queryset, name, value):
|
||||||
|
|
|
@ -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='起始物料'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -587,12 +587,13 @@ class BatchSt(BaseModel):
|
||||||
batch = models.TextField("批次号", unique=True, db_index=True)
|
batch = models.TextField("批次号", unique=True, db_index=True)
|
||||||
last_time = models.DateTimeField("最后操作时间", null=True, blank=True)
|
last_time = models.DateTimeField("最后操作时间", null=True, blank=True)
|
||||||
data = models.JSONField("数据", default=list, 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)
|
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)
|
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)
|
mlog = models.ForeignKey(Mlog, verbose_name='由何日志创建', on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
|
||||||
@classmethod
|
@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):
|
||||||
"""
|
"""
|
||||||
创建新的批次
|
创建新的批次
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -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)
|
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
for item in m_outs:
|
for item in m_outs:
|
||||||
if item.mlogb_from and item.batch != item.mlogb_from.batch:
|
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)
|
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:
|
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)
|
BatchLog.g_create(source_b=item.mlogbw_from.mlogb.batch, target_b=item.batch, mlog=mlog)
|
||||||
|
|
||||||
if material_in or is_fix: # 需要进行车间库存管理
|
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:
|
if mtype == Handover.H_MERGE:
|
||||||
batch = new_batch
|
batch = new_batch
|
||||||
if create_new_batch is False:
|
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
|
create_new_batch = True
|
||||||
BatchLog.g_create(source_b=wm_from.batch, target_b=batch, handover=handover, relation_type="merge")
|
BatchLog.g_create(source_b=wm_from.batch, target_b=batch, handover=handover, relation_type="merge")
|
||||||
elif mtype == Handover.H_DIV:
|
elif mtype == Handover.H_DIV:
|
||||||
batch = handover_or_b.batch
|
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")
|
BatchLog.g_create(source_b=handover.wm.batch, target_b=batch, handover=handover, relation_type="split")
|
||||||
else:
|
else:
|
||||||
batch = wm_from.batch
|
batch = wm_from.batch
|
||||||
|
|
Loading…
Reference in New Issue