From e03faeffc4e06d2dea76214a0b90f6cd30cd4a59 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 13 Aug 2025 10:03:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20WMaterialFilter=20filter=20tag=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/filters.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/wpm/filters.py b/apps/wpm/filters.py index 482f9706..38f16c4b 100644 --- a/apps/wpm/filters.py +++ b/apps/wpm/filters.py @@ -42,21 +42,23 @@ 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) + 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) def filter_tag(self, queryset, name, value): - mgroup = self.data.get("mgroup", None) - if mgroup: - process = Mgroup.objects.get(id=mgroup).process + mgroupId = self.data.get("mgroup", None) + mgroupxId = self.data.get("mgroupx", None) + mgroupId = mgroupId if mgroupId else mgroupxId + if mgroupId: + process = Mgroup.objects.get(id=mgroupId).process matoutIds = process.get_canout_mat_ids() queryset = queryset.filter(material__type__in=[Material.MA_TYPE_MAINSO, Material.MA_TYPE_HALFGOOD, Material.MA_TYPE_GOOD]) if value == "todo": - qs = queryset.exclude(material__id__in=matoutIds).exclude(state=WMaterial.WM_REPAIRED)|queryset.filter(state=WMaterial.WM_REPAIR) + qs = queryset.exclude(material__id__in=matoutIds).exclude(state=WMaterial.WM_REPAIRED)|queryset.filter(state=WMaterial.WM_REPAIR, mgroup__id=mgroupId) return qs elif value == "done": - qs = queryset.filter(material__id__in=matoutIds).exclude(state=WMaterial.WM_REPAIR)|queryset.filter(state=WMaterial.WM_REPAIRED) + qs = queryset.filter(material__id__in=matoutIds).exclude(state=WMaterial.WM_REPAIR)|queryset.filter(state=WMaterial.WM_REPAIRED, mgroup__id=mgroupId) elif value == "canfix": - qs = queryset.filter(state=WMaterial.WM_REPAIR)| queryset.filter(material__id__in=matoutIds, state=WMaterial.WM_NOTOK).exclude( + qs = queryset.filter(state=WMaterial.WM_REPAIR, mgroup__id=mgroupId)| queryset.filter(material__id__in=matoutIds, state=WMaterial.WM_NOTOK).exclude( state=WMaterial.WM_REPAIR).exclude(state=WMaterial.WM_REPAIRED) return qs else: