diff --git a/apps/wpm/migrations/0107_alter_handoverb_handover.py b/apps/wpm/migrations/0107_alter_handoverb_handover.py new file mode 100644 index 00000000..b0c08eed --- /dev/null +++ b/apps/wpm/migrations/0107_alter_handoverb_handover.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.12 on 2025-03-31 08:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0106_alter_handover_type'), + ] + + operations = [ + migrations.AlterField( + model_name='handoverb', + name='handover', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='b_handover', to='wpm.handover', verbose_name='关联交接记录'), + ), + ] diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 1e4d071d..84b46ff1 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -529,7 +529,7 @@ class Handover(CommonADModel): class Handoverb(BaseModel): """TN: 子级交接记录 """ - handover = models.ForeignKey(Handover, verbose_name='关联交接记录', on_delete=models.CASCADE) + handover = models.ForeignKey(Handover, verbose_name='关联交接记录', on_delete=models.CASCADE, related_name="b_handover") batch = models.TextField("批次号", null=True, blank=True) wm = models.ForeignKey(WMaterial, verbose_name='关联车间库存', on_delete=models.SET_NULL, null=True, blank=True, related_name='handoverb_wm') @@ -614,15 +614,16 @@ class BatchSt(BaseModel): @classmethod @transaction.atomic - def init_dag(cls, batch:str, force_update=False): + def init_dag(cls, batch:str): """ - 更新批次数据关系链 + 更新批次数据关系链(初步) """ - ins:BatchSt = cls.g_create(batch) + ins, _ = cls.g_create(batch) if ins.mio is None and ins.handover is None and ins.mlog is None: - force_update = True - if force_update: - pass + from apps.inm.models import MIOItem + mioitem = MIOItem.objects.filter(batch=batch, mio__submit_time__isnull=False).order_by('mio__submit_time').first() + handover = Handover.objects.filter(mtype=20, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 拆分 + handover2 = Handover.objects.filter(mtype=10, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 合并 return ins class BatchLog(BaseModel):