feat: material的count改为对所有库存进行统计

This commit is contained in:
caoqianming 2024-04-09 08:40:28 +08:00
parent 9b2dbb8a01
commit 19f6e18154
3 changed files with 11 additions and 10 deletions

View File

@ -44,10 +44,3 @@ def correct_mb_count_notok():
InmService.update_mb_after_test(mi)
except ParseError as e:
MIOItem.objects.filter(id=mi.id).update(test_date=None)
def correct_material_count():
"""
矫正现有物料总数量
"""
res = MaterialBatch.objects.values('material').aggregate(total=Sum('count'))

View File

@ -45,10 +45,14 @@ class InmService:
def cal_mat_count(cls, material: Material):
material_count = MaterialBatch.objects.filter(
material=material).aggregate(total=Sum('count'))['total']
from apps.wpm.models import WMaterial
wm_count = WMaterial.objects.filter(material=material).aggregate(total=Sum('count'))['total']
if material_count is None:
material_count = 0
if wm_count is None:
wm_count = 0
Material.objects.filter(id=material.id).update(
count=material_count)
count=material_count+wm_count)
@classmethod
def update_mb(cls, instance: MIO, in_or_out: int = 1):

View File

@ -4,10 +4,14 @@ from celery import shared_task
from apps.mtm.models import Material
@shared_task(base=CustomTask)
def correct_material_count():
def correct_material_count(materialId: str = ''):
"""
矫正现有物料总数量
"""
from apps.inm.services import InmService
for m in Material.objects.all():
if materialId:
objs = Material.objects.filter(id=materialId)
else:
objs = Material.objects.all()
for m in objs:
InmService.cal_mat_count(m)