feat: 采购入库支持检验
This commit is contained in:
parent
adf3341f4b
commit
8bcd6b4f69
|
@ -37,6 +37,7 @@ class MaterialBatchSerializer(CustomModelSerializer):
|
||||||
supplier_name = serializers.StringRelatedField(
|
supplier_name = serializers.StringRelatedField(
|
||||||
source='supplier', read_only=True)
|
source='supplier', read_only=True)
|
||||||
material_ = MaterialSerializer(source='material', read_only=True)
|
material_ = MaterialSerializer(source='material', read_only=True)
|
||||||
|
defect_name = serializers.CharField(source="defect.name", read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MaterialBatch
|
model = MaterialBatch
|
||||||
|
|
|
@ -9,6 +9,8 @@ from apps.mtm.services import cal_material_count
|
||||||
from apps.wpm.models import WMaterial
|
from apps.wpm.models import WMaterial
|
||||||
from apps.wpm.services_2 import get_alldata_with_batch_and_store
|
from apps.wpm.services_2 import get_alldata_with_batch_and_store
|
||||||
from apps.wpmw.models import Wpr
|
from apps.wpmw.models import Wpr
|
||||||
|
from apps.qm.models import FtestDefect, Defect
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
def do_out(item: MIOItem):
|
def do_out(item: MIOItem):
|
||||||
"""
|
"""
|
||||||
|
@ -225,6 +227,7 @@ class InmService:
|
||||||
in_or_out = -1
|
in_or_out = -1
|
||||||
|
|
||||||
if instance.type == MIO.MIO_TYPE_PUR_IN: # 需要更新订单
|
if instance.type == MIO.MIO_TYPE_PUR_IN: # 需要更新订单
|
||||||
|
# 这里还需要对入厂检验进行处理
|
||||||
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)
|
||||||
|
@ -284,15 +287,39 @@ class InmService:
|
||||||
if i.material.type in [Material.MA_TYPE_MAINSO]:
|
if i.material.type in [Material.MA_TYPE_MAINSO]:
|
||||||
ddict["batch_ofrom"] = i.batch
|
ddict["batch_ofrom"] = i.batch
|
||||||
ddict["material_ofrom"] = i.material
|
ddict["material_ofrom"] = i.material
|
||||||
|
|
||||||
|
m_list = [(material, warehouse, i.batch, getattr(i, field), None, i)] # getattr主要是兼容原有逻辑
|
||||||
|
if tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
m_list = []
|
||||||
|
# 获取所有主要的不合格项
|
||||||
|
mw_qs = MIOItemw.objects.filter(mioitem=i)
|
||||||
|
defectIds= FtestDefect.objects.filter(ftest_mioitemw_ftest__in=mw_qs, is_main=True, has=True).values_list("defect__id", flat=True).distinct()
|
||||||
|
defects_map = {d.id: d for d in Defect.objects.filter(id__in=defectIds)}
|
||||||
|
# 过滤并统计相关数据
|
||||||
|
filtered_mw_qs = mw_qs.filter(
|
||||||
|
ftest__defects_ftest__defect__id__in=defects_map.keys(),
|
||||||
|
ftest__defects_ftest__has=True,
|
||||||
|
ftest__defects_ftest__is_main=True
|
||||||
|
).values('ftest__defects_ftest__defect__id').annotate(xcount=Count('id'))
|
||||||
|
for defect_data in filtered_mw_qs:
|
||||||
|
defect_id = defect_data['ftest__defects_ftest__defect__id']
|
||||||
|
xcount = defect_data['xcount']
|
||||||
|
if xcount > 0:
|
||||||
|
defect = defects_map[defect_id]
|
||||||
|
m_list.append((material, warehouse, i.batch, xcount, defect, i))
|
||||||
|
for material, warehouse, batch, change_count, defect, mioitem in m_list:
|
||||||
|
if change_count <= 0:
|
||||||
|
continue
|
||||||
mb, _ = MaterialBatch.objects.get_or_create(
|
mb, _ = MaterialBatch.objects.get_or_create(
|
||||||
material=material,
|
material=material,
|
||||||
warehouse=warehouse,
|
warehouse=warehouse,
|
||||||
batch=i.batch,
|
batch=batch,
|
||||||
|
defect=defect,
|
||||||
defaults=ddict
|
defaults=ddict
|
||||||
)
|
)
|
||||||
|
|
||||||
if in_or_out == 1:
|
if in_or_out == 1:
|
||||||
mb.count = mb.count + getattr(i, field)
|
mb.count = mb.count + change_count
|
||||||
mb.save()
|
mb.save()
|
||||||
if tracking == Material.MA_TRACKING_SINGLE:
|
if tracking == Material.MA_TRACKING_SINGLE:
|
||||||
mioitemws = MIOItemw.objects.filter(mioitem=i)
|
mioitemws = MIOItemw.objects.filter(mioitem=i)
|
||||||
|
@ -307,7 +334,7 @@ class InmService:
|
||||||
mioitemw.save()
|
mioitemw.save()
|
||||||
|
|
||||||
elif in_or_out == -1:
|
elif in_or_out == -1:
|
||||||
mb.count = mb.count - getattr(i, field)
|
mb.count = mb.count - change_count
|
||||||
if mb.count < 0:
|
if mb.count < 0:
|
||||||
raise ParseError("批次库存不足,操作失败")
|
raise ParseError("批次库存不足,操作失败")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -345,11 +345,10 @@ class MIOItemwViewSet(CustomModelViewSet):
|
||||||
raise ParseError('请指定所属出入库记录明细')
|
raise ParseError('请指定所属出入库记录明细')
|
||||||
return super().filter_queryset(queryset)
|
return super().filter_queryset(queryset)
|
||||||
|
|
||||||
def cal_mioitem_count(self, mioitem):
|
def cal_mioitem_count(self, mioitem:MIOItem):
|
||||||
count = MIOItemw.objects.filter(mioitem=mioitem).count()
|
count = MIOItemw.objects.filter(mioitem=mioitem).count()
|
||||||
mioitem.count = count
|
mioitem.count = count
|
||||||
mioitem.count_notok = MIOItemw.objects.filter(mioitem=mioitem, ftest__is_ok=False).count()
|
mioitem.count_notok = MIOItemw.objects.filter(mioitem=mioitem, ftest__is_ok=False).count()
|
||||||
mioitem.count_ok = count - mioitem.count_notok
|
|
||||||
mioitem.save()
|
mioitem.save()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
|
|
Loading…
Reference in New Issue