Skip to content

Commit

Permalink
🐛(backend) fix order created_on date filter
Browse files Browse the repository at this point in the history
Order filtering is matching created_on date exactly, which only matches
times at 0:00, as query parameter only contains a date.
  • Loading branch information
kernicPanel committed Dec 20, 2024
1 parent 68152b4 commit c7386e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backend/joanie/core/filters/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Meta:
field_name="product__type",
choices=enums.PRODUCT_TYPE_CHOICES,
)
created_on = filters.DateFilter(field_name="created_on", lookup_expr="exact")
created_on = filters.DateFilter(field_name="created_on", lookup_expr="date")
created_on_date_range = filters.DateFromToRangeFilter(field_name="created_on")

def filter_by_query(self, queryset, _name, value):
Expand Down
20 changes: 14 additions & 6 deletions src/backend/joanie/tests/core/api/admin/orders/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ class OrdersAdminApiListTestCase(TestCase):
@staticmethod
def generate_orders_created_on(number: int, created_on=None):
"""Generate a batch of orders with a specific creation date."""
if created_on:
created_on = datetime.combine(created_on, datetime.min.time(), tzinfo=timezone.utc)
with mock.patch(
"django.utils.timezone.now", return_value=created_on or datetime.now()
):
return factories.OrderGeneratorFactory.create_batch(number)
orders = []
for _ in range(number):
if created_on:
created_on = datetime.combine(
created_on, datetime.now().time(), tzinfo=timezone.utc
)
with mock.patch(
"django.utils.timezone.now",
return_value=created_on or datetime.now(),
):
orders.append(factories.OrderFactory())
# orders default orderings are by creation date
orders.sort(key=lambda x: x.created_on, reverse=True)
return orders

def test_api_admin_orders_request_without_authentication(self):
"""
Expand Down

0 comments on commit c7386e4

Please sign in to comment.