Coverage for apps/core_los/report_builder_schemas.py: 100%

45 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-04 17:24 +0000

1"""Django Ninja schemas for the Report Builder endpoints.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7from ninja import ModelSchema, Schema 

8 

9from apps.core_los.models import CustomReport 

10 

11 

12class ReportFieldOut(Schema): 

13 key: str 

14 label: str 

15 type: str 

16 filterable: bool 

17 groupable: bool 

18 

19 

20class MetricOut(Schema): 

21 key: str 

22 label: str 

23 type: str 

24 

25 

26class ReportFieldCatalogOut(Schema): 

27 fields: list[ReportFieldOut] 

28 metrics: list[MetricOut] 

29 

30 

31class ReportFilterIn(Schema): 

32 field: str 

33 op: str 

34 value: str | int | float 

35 

36 

37class ReportSortIn(Schema): 

38 field: str 

39 dir: str 

40 

41 

42class ReportDefInputSchema(Schema): 

43 name: str 

44 columns: list[str] = [] 

45 filters: list[ReportFilterIn] = [] 

46 group_by: str | None = None 

47 metrics: list[str] = [] 

48 sort: ReportSortIn | None = None 

49 

50 

51class ReportDefOut(ModelSchema): 

52 class Meta: 

53 model = CustomReport 

54 fields = [ 

55 "id", "name", "columns", "filters", "group_by", 

56 "metrics", "sort", "system", "created_at", 

57 ] 

58 

59 

60class ReportColumnOut(Schema): 

61 key: str 

62 label: str 

63 type: str 

64 

65 

66class ReportResultOut(Schema): 

67 mode: str 

68 columns: list[ReportColumnOut] 

69 rows: list[dict[str, Any]] 

70 totals: dict[str, Any] | None = None 

71 row_count: int