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: