wbintegrator_office365 1.43.1__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. wbintegrator_office365/__init__.py +1 -0
  2. wbintegrator_office365/admin.py +209 -0
  3. wbintegrator_office365/apps.py +5 -0
  4. wbintegrator_office365/configurations/__init__.py +0 -0
  5. wbintegrator_office365/configurations/configurations/__init__.py +23 -0
  6. wbintegrator_office365/dynamic_preferences_registry.py +15 -0
  7. wbintegrator_office365/factories.py +102 -0
  8. wbintegrator_office365/filters.py +237 -0
  9. wbintegrator_office365/importer/__init__.py +3 -0
  10. wbintegrator_office365/importer/api.py +403 -0
  11. wbintegrator_office365/importer/disable_signals.py +43 -0
  12. wbintegrator_office365/importer/parser.py +135 -0
  13. wbintegrator_office365/kpi_handlers/__init__.py +1 -0
  14. wbintegrator_office365/kpi_handlers/calls.py +114 -0
  15. wbintegrator_office365/migrations/0001_initial_squashed_squashed_0003_alter_calendar_owner_alter_calendarevent_organizer_and_more.py +677 -0
  16. wbintegrator_office365/migrations/0002_remove_calendar_owner_remove_calendarevent_activity_and_more.py +85 -0
  17. wbintegrator_office365/migrations/0003_alter_event_options.py +20 -0
  18. wbintegrator_office365/migrations/__init__.py +0 -0
  19. wbintegrator_office365/models/__init__.py +3 -0
  20. wbintegrator_office365/models/event.py +623 -0
  21. wbintegrator_office365/models/subscription.py +144 -0
  22. wbintegrator_office365/models/tenant.py +62 -0
  23. wbintegrator_office365/serializers.py +266 -0
  24. wbintegrator_office365/tasks.py +108 -0
  25. wbintegrator_office365/templates/admin/tenant_change_list.html +12 -0
  26. wbintegrator_office365/tests/__init__.py +0 -0
  27. wbintegrator_office365/tests/conftest.py +28 -0
  28. wbintegrator_office365/tests/test_admin.py +86 -0
  29. wbintegrator_office365/tests/test_models.py +65 -0
  30. wbintegrator_office365/tests/test_tasks.py +318 -0
  31. wbintegrator_office365/tests/test_views.py +128 -0
  32. wbintegrator_office365/tests/tests.py +12 -0
  33. wbintegrator_office365/urls.py +46 -0
  34. wbintegrator_office365/viewsets/__init__.py +31 -0
  35. wbintegrator_office365/viewsets/display.py +306 -0
  36. wbintegrator_office365/viewsets/endpoints.py +52 -0
  37. wbintegrator_office365/viewsets/menu.py +65 -0
  38. wbintegrator_office365/viewsets/titles.py +49 -0
  39. wbintegrator_office365/viewsets/viewsets.py +745 -0
  40. wbintegrator_office365-1.43.1.dist-info/METADATA +10 -0
  41. wbintegrator_office365-1.43.1.dist-info/RECORD +42 -0
  42. wbintegrator_office365-1.43.1.dist-info/WHEEL +5 -0
@@ -0,0 +1,114 @@
1
+ from typing import Type
2
+
3
+ from django.db.models import Q
4
+ from django.db.models.expressions import F
5
+ from django.db.models.query import QuerySet
6
+ from wbcore import serializers
7
+ from wbcore.serializers.serializers import Serializer
8
+ from wbhuman_resources.models.kpi import KPI, KPIHandler
9
+ from wbhuman_resources.serializers import KPIModelSerializer
10
+ from wbintegrator_office365.models import CallEvent
11
+
12
+
13
+ class NumberOfCallKPIKPISerializer(KPIModelSerializer):
14
+ call_area = serializers.ChoiceField(
15
+ default="all",
16
+ choices=[("only_internal", "Only Internal"), ("only_external", "Only External"), ("all", "All")],
17
+ )
18
+ person_participates = serializers.BooleanField(
19
+ default=True,
20
+ label="Participants of call/Meeting ",
21
+ help_text="Calls/Meeting considered are related to the participants",
22
+ )
23
+ person_created = serializers.BooleanField(
24
+ default=True,
25
+ label="Organizer of call/Meeting ",
26
+ help_text="Calls/Meeting considered are related to the organizer",
27
+ )
28
+
29
+ def update(self, instance, validated_data):
30
+ call_area = validated_data.get(
31
+ "call_area",
32
+ instance.additional_data["serializer_data"].get("call_area", "all"),
33
+ )
34
+
35
+ person_participates = validated_data.get(
36
+ "person_participates",
37
+ instance.additional_data["serializer_data"].get("person_participates", True),
38
+ )
39
+ person_created = validated_data.get(
40
+ "person_created",
41
+ instance.additional_data["serializer_data"].get("person_created", True),
42
+ )
43
+
44
+ additional_data = instance.additional_data
45
+ additional_data["serializer_data"]["call_area"] = call_area
46
+ additional_data["serializer_data"]["person_participates"] = person_participates
47
+ additional_data["serializer_data"]["person_created"] = person_created
48
+
49
+ additional_data["list_data"] = instance.get_handler().get_list_data(additional_data["serializer_data"])
50
+ validated_data["additional_data"] = additional_data
51
+
52
+ return super().update(instance, validated_data)
53
+
54
+ class Meta(KPIModelSerializer.Meta):
55
+ fields = (
56
+ *KPIModelSerializer.Meta.fields,
57
+ "call_area",
58
+ "person_participates",
59
+ "person_created",
60
+ )
61
+
62
+
63
+ class NumberOfCallKPI(KPIHandler):
64
+ def get_name(self) -> str:
65
+ return "Number of Calls/Meeting"
66
+
67
+ def get_serializer(self) -> Type[Serializer]:
68
+ return NumberOfCallKPIKPISerializer
69
+
70
+ def annotate_parameters(self, queryset: QuerySet[KPI]) -> QuerySet[KPI]:
71
+ return queryset.annotate(
72
+ call_area=F("additional_data__serializer_data__call_area"),
73
+ person_participates=F("additional_data__serializer_data__person_participates"),
74
+ person_created=F("additional_data__serializer_data__person_created"),
75
+ person_assigned=F("additional_data__serializer_data__person_assigned"),
76
+ )
77
+
78
+ def get_list_data(self, serializer_data: dict) -> list[str]:
79
+ return [
80
+ f"Call Area: {serializer_data['call_area']}",
81
+ f"Person Participates: {serializer_data['person_participates']}",
82
+ f"Person Created: {serializer_data['person_created']}",
83
+ ]
84
+
85
+ def get_display_grid(self) -> list[list[str]]:
86
+ return [["call_area"] * 2, ["person_created", "person_participates"]]
87
+
88
+ def evaluate(self, kpi: "KPI", evaluated_person=None, evaluation_date=None) -> int:
89
+ persons = (
90
+ [evaluated_person.id] if evaluated_person else kpi.evaluated_persons.all().values_list("id", flat=True)
91
+ )
92
+ serializer_data = kpi.additional_data.get("serializer_data")
93
+ qs = CallEvent.objects.filter(
94
+ start__gte=kpi.period.lower,
95
+ end__lte=evaluation_date if evaluation_date else kpi.period.upper,
96
+ )
97
+ if (call_area := serializer_data.get("call_area")) and (call_area != "all"):
98
+ if call_area == "only_internal":
99
+ qs = qs.filter(is_internal_call=True)
100
+ elif call_area == "only_external":
101
+ qs = qs.filter(is_internal_call=False)
102
+
103
+ condition = None
104
+ if serializer_data.get("person_created") or serializer_data.get("person_created") is None:
105
+ condition = Q(organizer__tenant_user__profile__in=persons)
106
+ if serializer_data.get("person_participates") or serializer_data.get("person_participates") is None:
107
+ condition = (
108
+ (condition | Q(participants__tenant_user__profile__in=persons))
109
+ if condition
110
+ else Q(participants__tenant_user__profile__in=persons)
111
+ )
112
+ if condition:
113
+ qs = qs.filter(condition)
114
+ return qs.distinct().count()