feat: 添加wamterial ava_qs方法

This commit is contained in:
caoqianming 2025-08-14 09:48:23 +08:00
parent c69c33e85a
commit 1d778dbdf0
2 changed files with 11 additions and 2 deletions

View File

@ -42,7 +42,7 @@ class WMaterialFilter(filters.FilterSet):
material__process__exclude = filters.CharFilter(field_name="material__process", lookup_expr="exact", exclude=True)
def filter_mgroupx(self, queryset, name, value):
return queryset.filter(mgroup__id=value)|queryset.filter(belong_dept=Mgroup.objects.get(id=value).belong_dept, mgroup=None)|queryset.filter(mgroup=None, belong_dept=None)
return WMaterial.ava_qs(mgroup=Mgroup.objects.get(id=value), qs=queryset)
def filter_tag(self, queryset, name, value):
mgroupId = self.data.get("mgroup", None)

View File

@ -130,6 +130,15 @@ class WMaterial(CommonBDModel):
def count_handovering(self):
return Handoverb.objects.filter(wm=self, handover__submit_time__isnull=True).aggregate(count=Sum('count'))['count'] or 0
@classmethod
def ava_qs(cls, mgroup:Mgroup, qs=None):
"""
可用的queryset
"""
if qs is None:
qs = cls.objects
return qs.filter(Q(mgroup=mgroup)|Q(mgroup=None, belong_dept=mgroup.belong_dept)|Q(mgroup=None, belong_dept=None))
@classmethod
def mat_in_qs(cls, mtask: Mtask, qs=None):
"""
@ -137,7 +146,7 @@ class WMaterial(CommonBDModel):
"""
if qs is None:
qs = cls.objects
return qs.filter(
return WMaterial.ava_qs(mgroup=mtask.mgroup, qs=qs).filter(
mgroup=mtask.mgroup,
material=mtask.material_in,
batch__in=Subquery(