diff --git a/apps/cm/migrations/0002_lablemat_defect.py b/apps/cm/migrations/0002_lablemat_defect.py new file mode 100644 index 00000000..2f802ea6 --- /dev/null +++ b/apps/cm/migrations/0002_lablemat_defect.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.12 on 2025-01-13 06:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('qm', '0036_auto_20250113_1130'), + ('cm', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='lablemat', + name='defect', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='qm.defect', verbose_name='缺陷'), + ), + ] diff --git a/apps/cm/models.py b/apps/cm/models.py index 4f77be02..9c77ee05 100644 --- a/apps/cm/models.py +++ b/apps/cm/models.py @@ -10,4 +10,5 @@ class LableMat(BaseModel): batch = models.CharField('批次号', max_length=100) supplier = models.ForeignKey(Supplier, verbose_name='外协供应商', on_delete=models.SET_NULL, null=True, blank=True) notok_sign = models.CharField('不合格标记', max_length=10, null=True, blank=True) + defect = models.ForeignKey("qm.defect", verbose_name='缺陷', on_delete=models.SET_NULL, null=True, blank=True) material_origin = models.ForeignKey(Material, verbose_name='原始物料', on_delete=models.SET_NULL, null=True, blank=True, related_name='lm_mo') \ No newline at end of file diff --git a/apps/cm/views.py b/apps/cm/views.py index 30b3e0ed..ccc4f90f 100644 --- a/apps/cm/views.py +++ b/apps/cm/views.py @@ -28,7 +28,7 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie mb = MaterialBatch.objects.get(id=tid) except MaterialBatch.DoesNotExist: raise NotFound("仓库明细不存在") - obj, _ = LableMat.objects.get_or_create(state=10, material=mb.material, batch=mb.batch, defaults={"supplier": mb.supplier}) + obj, _ = LableMat.objects.get_or_create(state=mb.state, material=mb.material, batch=mb.batch, defect=mb.defect, defaults={"supplier": mb.supplier}) rdata = LabelMatSerializer(obj).data rdata["code_label"] = f"mat{SPLIT_FIELD}{obj.id}" return Response(rdata) @@ -45,7 +45,9 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie wm = WMaterial.objects.get(id=tid) except WMaterial.DoesNotExist: raise NotFound("车间库存不存在") - obj, _ = LableMat.objects.get_or_create(state=wm.state, material=wm.material, batch=wm.batch, notok_sign=wm.notok_sign, material_origin=wm.material_origin) + obj, _ = LableMat.objects.get_or_create(state=wm.state, material=wm.material, batch=wm.batch, + notok_sign=wm.notok_sign, defect=wm.defect, + material_origin=wm.material_origin) rdata = LabelMatSerializer(obj).data rdata["code_label"] = f"mat{SPLIT_FIELD}{obj.id}" return Response(rdata)