From 9ccac338452774b1e1961758de4563ac066523e0 Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Thu, 22 Feb 2024 09:49:25 +0100 Subject: [PATCH] clean from review --- lemarche/tenders/admin.py | 10 +++++----- lemarche/tenders/models.py | 8 ++++---- lemarche/tenders/tests.py | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 754354e1c..979f96e14 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -56,8 +56,6 @@ def queryset(self, request, queryset): class AmountCustomFilter(admin.SimpleListFilter): title = "Montant du besoin" - # FILTER_LABEL = Tender._meta.get_field("amount").verbose_name - BUTTON_LABEL = "Appliquer" parameter_name = "amount" def lookups(self, request, model_admin): @@ -71,11 +69,13 @@ def queryset(self, request, queryset): value = self.value() amount_10k = 10 * 10**3 # 10k if value == "<10k": - return queryset.filter_by_amount(amount_10k, operation="lt") + return queryset.filter_by_amount_exact(amount_10k, operation="lt") elif value == "5k-10k": - return queryset.filter_by_amount(amount_10k, operation="lte").filter_by_amount(amount_10k, operation="gte") + return queryset.filter_by_amount_exact(amount_10k, operation="lte").filter_by_amount_exact( + amount_10k, operation="gte" + ) elif value == ">=10k": - return queryset.filter_by_amount(amount_10k, operation="gte") + return queryset.filter_by_amount_exact(amount_10k, operation="gte") class ResponseKindFilter(admin.SimpleListFilter): diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 0d9acedcf..521f15d5d 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -113,7 +113,7 @@ def has_amount(self): ) ) - def filter_by_amount(self, amount: int, operation: str = "gte"): + def filter_by_amount_exact(self, amount: int, operation: str = "gte"): """ Filters records based on a monetary amount with a specified comparison operation. It dynamically selects between filtering on an exact amount (`amount_exact`) @@ -131,7 +131,7 @@ def filter_by_amount(self, amount: int, operation: str = "gte"): QuerySet: Filtered queryset based on the amount and operation. Example: - >>> filtered_queryset = MyModel.objects.all().filter_by_amount(5000, 'gte') + >>> filtered_queryset = MyModel.objects.all().filter_by_amount_exact(5000, 'gte') Filters for records with `amount_exact` >= 5000 or in the matching amount range. """ amounts_keys = find_amount_ranges(amount=amount, operation=operation) @@ -1012,7 +1012,7 @@ class PartnerShareTenderQuerySet(models.QuerySet): def is_active(self): return self.filter(is_active=True) - def filter_by_amount(self, tender: Tender): + def filter_by_amount_exact(self, tender: Tender): """ Return partners with: - an empty 'amount_in' @@ -1051,7 +1051,7 @@ def filter_by_perimeter(self, tender: Tender): return self.filter(conditions) def filter_by_tender(self, tender: Tender): - return self.is_active().filter_by_amount(tender).filter_by_perimeter(tender).distinct() + return self.is_active().filter_by_amount_exact(tender).filter_by_perimeter(tender).distinct() class PartnerShareTender(models.Model): diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 394866102..83ea31c11 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -1005,4 +1005,5 @@ def test_edge_case(self): def test_no_matching_ranges(self): """Test when no ranges match the criteria.""" - self.assertListEqual(find_amount_ranges(100, "lte"), [tender_constants.AMOUNT_RANGE_0_1]) + expected_keys = [tender_constants.AMOUNT_RANGE_0_1] + self.assertListEqual(find_amount_ranges(100, "lte"), expected_keys)