diff --git a/apps/wpm/filters.py b/apps/wpm/filters.py index 0b636512..f4423459 100644 --- a/apps/wpm/filters.py +++ b/apps/wpm/filters.py @@ -243,10 +243,11 @@ class BatchStFilter(filters.FilterSet): batch__startswith__in = filters.CharFilter(method='filter_batch') data__has_key = filters.CharFilter(method='filter_data') with_source_near = filters.CharFilter(label='来源', method='filter_source_near') + with_zt_big = filters.CharFilter(label='附带直通大批', method='filter_source_near') def filter_source_near(self, queryset, name, value): return queryset - + def filter_data(self, queryset, name, value): return queryset.filter(data__has_key=value) @@ -254,6 +255,7 @@ class BatchStFilter(filters.FilterSet): model = BatchSt fields = { "batch": ["exact", "contains", "startswith"], + "zt_batch": ["exact", "isnull"], "version": ["exact", "gte", "lte"], "first_time": ["exact", "gte", "lte", "isnull"], "last_time": ["exact", "gte", "lte", "isnull"], diff --git a/apps/wpm/scripts/batch_gxerp.md b/apps/wpm/scripts/batch_gxerp.md index 9cfc7181..bf6bd051 100644 --- a/apps/wpm/scripts/batch_gxerp.md +++ b/apps/wpm/scripts/batch_gxerp.md @@ -259,6 +259,11 @@ FtestWork where type2 = TYPE2_SOME | `直通_良率` | 百分比(不可得/异常为 null) | | `直通_口径` | 白料来源口径:`黑化领用` / `入库数量` / `谱系兜底` 及异常标注 | +### 接口(`/wpm/batchst/`) + +- 响应自带 `zt_batch`(所属大批号);`?with_zt_big=yes` 时每行附 `zt_big` = 所属大批的完整 BatchSt(含 `直通_*`),自身即大批时为 null(直通字段就在本行 data 里)。 +- 过滤:`?zt_batch=<大批号>` 查某大批全部子批;`with_source_near=yes` 仍可附 BatchLog 直接来源批。 + ### 部署 1. `python manage.py migrate wpm`(新增 `BatchSt.zt_batch`,迁移 `0133_batchst_zt_batch`)。 diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 14fb4110..d5a5d2a1 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -1103,6 +1103,14 @@ class BatchStViewSet(CustomListModelMixin, ComplexQueryMixin, CustomGenericViewS source_data_dict = {ins["id"]: ins for ins in source_data} for item in data: item["source_near"] = [source_data_dict[ins["source"]] for ins in batchlog_qs if ins["target"] == item["id"]] + if (self.request.query_params.get("with_zt_big", None) == "yes" or + self.request.data.get("with_zt_big", None) == "yes"): + # 附带所属直通统计大批的数据(zt_batch 指向自身的即大批本身, 不重复附带) + zt_batches = {ins["zt_batch"] for ins in data if ins.get("zt_batch") and ins["zt_batch"] != ins["batch"]} + big_data = BatchStSerializer(instance=BatchSt.objects.filter(batch__in=zt_batches, version=1), many=True).data + big_data_dict = {ins["batch"]: ins for ins in big_data} + for item in data: + item["zt_big"] = big_data_dict.get(item.get("zt_batch")) if item.get("zt_batch") != item["batch"] else None return data class MlogbwViewSet(CustomModelViewSet):