diff --git a/iaso/admin.py b/iaso/admin.py index 34c1ae700b..e784022ab1 100644 --- a/iaso/admin.py +++ b/iaso/admin.py @@ -528,7 +528,7 @@ def get_queryset(self, request): @admin_attr_decorator class SourceVersionAdmin(admin.ModelAdmin): readonly_fields = ("created_at",) - list_display = ["__str__", "data_source", "number", "created_at", "updated_at"] + list_display = ["id", "data_source", "number", "created_at", "updated_at"] list_filter = ["data_source", "created_at", "updated_at"] search_fields = ["data_source__name", "number", "description"] autocomplete_fields = ["data_source"] @@ -826,7 +826,7 @@ class EntityDuplicateAnalyzisAdmin(admin.ModelAdmin): class OrgUnitChangeRequestAdmin(admin.ModelAdmin): list_display = ("pk", "org_unit", "created_at", "status") list_display_links = ("pk", "org_unit") - list_filter = ("status", "kind") + list_filter = ("status", "kind", "data_source_synchronization") readonly_fields = ( "uuid", "created_at", @@ -851,6 +851,7 @@ class OrgUnitChangeRequestAdmin(admin.ModelAdmin): "new_reference_instances", "payment", "potential_payment", + "data_source_synchronization", ) fieldsets = ( ( @@ -900,6 +901,7 @@ class OrgUnitChangeRequestAdmin(admin.ModelAdmin): "updated_at", "updated_by", "rejection_comment", + "data_source_synchronization", ) }, ), @@ -921,7 +923,7 @@ class OrgUnitChangeRequestAdmin(admin.ModelAdmin): ) def get_queryset(self, request): - return super().get_queryset(request).select_related("org_unit__org_unit_type") + return super().get_queryset(request).select_related("org_unit__org_unit_type", "data_source_synchronization") @admin.register(Config) @@ -1081,14 +1083,29 @@ class Media: @admin.register(DataSourceVersionsSynchronization) class DataSourceVersionsSynchronizationAdmin(admin.ModelAdmin): + list_display = ( + "pk", + "name", + "account", + "created_by", + "count_create", + "count_update", + ) + list_display_links = ("pk", "name") autocomplete_fields = ("account", "created_by", "source_version_to_update", "source_version_to_compare_with") - readonly_fields = ("created_at", "updated_at", "sync_task") - formfield_overrides = { - ArrayField: { - "form_class": ArrayFieldMultipleChoiceField, - "widget": forms.CheckboxSelectMultiple, - } - } + readonly_fields = ("json_diff", "count_create", "count_update", "created_at", "updated_at", "sync_task") + + def get_queryset(self, request): + return ( + super() + .get_queryset(request) + .select_related( + "source_version_to_update__data_source", + "source_version_to_compare_with__data_source", + "account", + "created_by", + ) + ) admin.site.register(AccountFeatureFlag) diff --git a/iaso/models/data_source.py b/iaso/models/data_source.py index 1dc56f31bf..0ebdab7d96 100644 --- a/iaso/models/data_source.py +++ b/iaso/models/data_source.py @@ -115,7 +115,7 @@ class Meta: ] def __str__(self): - return "%s %d" % (self.data_source, self.number) + return f"#{self.pk} n°{self.number} - Data source: {self.data_source}" def as_dict(self): return { @@ -294,21 +294,22 @@ def create_json_diff( "show_deleted_org_units": show_deleted_org_units, "field_names": field_names, } - diffs, fields = Differ(logger_to_use or logger).diff(**differ_params) + diffs, _ = Differ(logger_to_use or logger).diff(**differ_params) + diffs = [diff for diff in diffs if diff.status != "same"] - coun_status = { + count_status = { "new": 0, "modified": 0, } for diff in diffs: - if diff.status in coun_status: - coun_status[diff.status] += 1 + if diff.status in count_status: + count_status[diff.status] += 1 - self.count_create = coun_status["new"] - self.count_update = coun_status["modified"] + self.count_create = count_status["new"] + self.count_update = count_status["modified"] self.json_diff = diffs_to_json(diffs) self.diff_config = str(differ_params) - self.save(update_fields=["json_diff", "diff_config"]) + self.save() def synchronize_source_versions(self): # Prevent a circular import. diff --git a/iaso/tests/models/test_data_source_versions_synchronization.py b/iaso/tests/models/test_data_source_versions_synchronization.py index 4467610ad1..8ec2140211 100644 --- a/iaso/tests/models/test_data_source_versions_synchronization.py +++ b/iaso/tests/models/test_data_source_versions_synchronization.py @@ -227,6 +227,8 @@ def test_create_json_diff(self): ignore_groups=True, field_names=["name"], ) + data_source_sync.refresh_from_db() + json_diff = json.loads(data_source_sync.json_diff) comparisons = json_diff[0]["comparisons"]