Open kgilpin opened 5 hours ago
Fix export to include all orders for an offer in OfferDetailView
The export functionality in OfferDetailView
only includes the first page of orders when generating the export. This is not the expected behavior. When a user exports data, they expect all relevant orders to be included in the export.
The root cause of this issue is that the render_to_response
method in OfferDetailView
uses context['order_discounts']
, which contains only the orders from the current page. When the export format is CSV, only this subset of orders is being exported.
To resolve this, we need to modify the export functionality to fetch and include all orders associated with the offer, rather than just the orders from the current page.
src/oscar/apps/dashboard/offers/views.py:
render_to_response
method to fetch all related orders before creating the export, bypassing the pagination.src/oscar/apps/dashboard/offers/views.py:
OfferDetailView
to get all orders linked to the specific offer.src/oscar/apps/dashboard/offers/views.py:
render_to_response
method:
<!-- file: /home/runner/work/django-oscar/django-oscar/src/oscar/apps/dashboard/offers/views.py -->
```python
def render_to_response(self, context):
if self.request.GET.get('format') == 'csv':
formatter = OrderDiscountCSVFormatter()
all_order_discounts = self.get_all_order_discounts()
return formatter.generate_response(all_order_discounts,
offer=self.offer)
return super().render_to_response(context)
src/oscar/apps/dashboard/offers/views.py:
<!-- file: /home/runner/work/django-oscar/django-oscar/src/oscar/apps/dashboard/offers/views.py -->
```python
def get_all_order_discounts(self):
return OrderDiscount.objects.filter(offer=self.offer)
This change ensures that when the export is triggered, it will include all orders related to the offer, thus solving the issue.
Original report: https://github.com/django-oscar/django-oscar/issues/4104
If you go to the offer detail view in the dashboard, and this offer has been used in orders, you can generate an export.
See: django-oscar/src/oscar/apps/dashboard/offers/views.py
Lines 407 to 412 in 1d1590f
However, if you got multiple pages of orders, only the first page will be in the export. It makes more sense when you generate an export, it will include all the orders.
Found in version
1d1590f2