diff --git a/resources/api/reservation.py b/resources/api/reservation.py index f44509d25..c13a33f9f 100644 --- a/resources/api/reservation.py +++ b/resources/api/reservation.py @@ -431,14 +431,12 @@ def add_report_data(self, request, instance, data): "state": instance.get_state_display(), } - if request.data.get("includeAccountingFields") == "1": + if request.query_params.get("includeAccountingFields") == "1": order = instance.get_order() if order: price = order.get_price() if price: order_line = order.order_lines.first() - user_group = order_line.user_group if order_line else None - event_type = order_line.event_type if order_line else None data = { **data, @@ -447,11 +445,9 @@ def add_report_data(self, request, instance, data): "sap_cost_center_code": instance.resource.unit.sap_cost_center_code, "sap_sales_organization": instance.resource.unit.sap_sales_organization, "invoice_generated_at": instance.invoice_generated_at, - "tax_percentage": order.tax_percentage, - "quantity": order.quantity, - "unit_price": order.unit_price, - "user_group": user_group, - "event_type": event_type, + "tax_percentage": order_line.tax_percentage if order_line else None, + "quantity": order_line.quantity if order_line else None, + "unit_price": order_line.unit_price if order_line else None, } return data diff --git a/resources/models/resource.py b/resources/models/resource.py index 906efc2fa..7d15a83e2 100644 --- a/resources/models/resource.py +++ b/resources/models/resource.py @@ -215,32 +215,10 @@ def with_pricing(self): ) def free_of_charge(self, is_free): - """if `is_free` is True, returns any resources that either have - `free_to_use=True` or have no associated price lists with amounts > zero. - - Otherwise returns any resources that have prices attached - and `free_to_use` is False. + """if `is_free` is True, returns resource with `free_to_use` is True, + else returns all those with `free_to_use` is False. """ - queryset = self.annotate( - has_pricing=models.Exists( - self.filter( - Q(default_min_price__gt=0) - | Q(default_max_price__gt=0) - | Q( - products__pricedproduct__price_list__usergroup_prices__price__gt=0, - ) - | Q( - products__pricedproduct__price_list__event_prices__price__gt=0, - ), - pk=models.OuterRef("pk"), - ) - ) - ) - - if is_free: - return queryset.filter(Q(free_to_use=True) | Q(has_pricing=False)) - else: - return queryset.filter(free_to_use=False, has_pricing=True) + return self.filter(free_to_use=is_free) class ResourceAccess(models.Model): @@ -254,6 +232,10 @@ class ResourceAccess(models.Model): access_method = models.CharField(max_length=15, choices=ACCESS_METHODS, unique=True) + class Meta: + verbose_name = _("Resource access method") + verbose_name_plural = _("Resource access methods") + def __str__(self): return self.get_access_method_display() diff --git a/resources/models/utils.py b/resources/models/utils.py index f6787db5a..6583bdd41 100644 --- a/resources/models/utils.py +++ b/resources/models/utils.py @@ -32,16 +32,14 @@ ] RESERVATION_ACCOUNTING_FIELDS = [ - ("user_group", "User group", 15), - ("event_type", "Event type", 15), ("quantity", "Quantity", 15), ("unit_price", "Unit price", 15), ("total_price", "Total price", 15), + ("tax_percentage", "Tax percentage", 15), ("cost_center_code", "CeePos Cost center code", 30), ("sap_cost_center_code", "SAP Cost center code", 30), ("sap_sales_organization", "SAP Sales Organization code", 30), ("invoice_generated_at", "Invoice created", 15), - ("tax_percentage", "Tax percentage", 15), ] RESERVATION_DATETIME_FIELDS = [ diff --git a/resources/pagination.py b/resources/pagination.py index 2db498593..3c3406931 100644 --- a/resources/pagination.py +++ b/resources/pagination.py @@ -3,7 +3,9 @@ class DefaultPagination(PageNumberPagination): page_size = 20 - page_size_query_param = 'page_size' # Allow client to override, using `?page_size=xxx + page_size_query_param = ( + "page_size" # Allow client to override, using `?page_size=xxx + ) max_page_size = 500 @@ -15,12 +17,18 @@ class ReservationPagination(DefaultPagination): def get_page_size(self, request): if self.page_size_query_param: cutoff = self.max_page_size - if request.query_params.get('format', '').lower() == 'xlsx': + if request.query_params.get("format", "").lower() == "xlsx": + cutoff = 50000 + if request.accepted_media_type in [ + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "text/csv", + ]: cutoff = 50000 try: return _positive_int( request.query_params[self.page_size_query_param], - strict=True, cutoff=cutoff + strict=True, + cutoff=cutoff, ) except (KeyError, ValueError): pass diff --git a/resources/tests/test_resource.py b/resources/tests/test_resource.py index 4d7c4d508..985059706 100644 --- a/resources/tests/test_resource.py +++ b/resources/tests/test_resource.py @@ -61,7 +61,7 @@ def test_get_reservable_before_not_none(): @pytest.mark.django_db -def test_free_of_charge_free_to_use_true_no_pricing_info(space_resource): +def test_free_of_charge_free_to_use_true(space_resource): space_resource.free_to_use = True space_resource.save() @@ -70,87 +70,12 @@ def test_free_of_charge_free_to_use_true_no_pricing_info(space_resource): @pytest.mark.django_db -def test_free_of_charge_free_to_use_false_has_default_min_price(space_resource): +def test_free_of_charge_free_to_use_false(space_resource): space_resource.free_to_use = False - space_resource.default_min_price = Decimal("10.00") space_resource.save() - assert Resource.objects.free_of_charge(True).count() == 0 assert Resource.objects.free_of_charge(False).count() == 1 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_has_default_max_price(space_resource): - space_resource.free_to_use = False - space_resource.default_min_price = Decimal("0") - space_resource.default_max_price = Decimal("10.00") - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 0 - assert Resource.objects.free_of_charge(False).count() == 1 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_has_default_min_max_price(space_resource): - space_resource.free_to_use = False - space_resource.default_min_price = Decimal("10.00") - space_resource.default_max_price = Decimal("20.00") - space_resource.save() - assert Resource.objects.free_of_charge(True).count() == 0 - assert Resource.objects.free_of_charge(False).count() == 1 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_has_default_min_price_zero(space_resource): - space_resource.free_to_use = False - space_resource.default_min_price = Decimal("0") - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_has_default_min_price_null(space_resource): - space_resource.free_to_use = False - space_resource.default_min_price = None - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_true_has_default_min_price_gt_zero(space_resource): - space_resource.free_to_use = True - space_resource.default_min_price = Decimal("10.00") - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_true_has_default_max_price_gt_zero(space_resource): - space_resource.free_to_use = True - space_resource.default_max_price = Decimal("10.00") - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_no_pricing_info(space_resource): - """Even if free_to_use is False, is still free of charge as there is - no pricing info attached.""" - - space_resource.free_to_use = False - space_resource.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 @pytest.mark.django_db @@ -213,62 +138,6 @@ def test_free_of_charge_free_to_use_true_with_pricing_info( assert Resource.objects.free_of_charge(False).count() == 0 -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_with_pricing_info_zero( - space_resource_with_product, priced_product -): - """If pricing is available but is zero, then should still be free of charge.""" - UserGroupPriceListItemFactory(price_list=priced_product.price_list, price="00.00") - - space_resource_with_product.free_to_use = False - space_resource_with_product.save() - - assert Resource.objects.free_of_charge(True).count() == 1 - assert Resource.objects.free_of_charge(False).count() == 0 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_with_user_group_pricing_info( - space_resource_with_product, priced_product -): - UserGroupPriceListItemFactory(price_list=priced_product.price_list, price="100.00") - - space_resource_with_product.free_to_use = False - space_resource_with_product.save() - - assert Resource.objects.free_of_charge(True).count() == 0 - assert Resource.objects.free_of_charge(False).count() == 1 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_with_event_type_pricing_info( - space_resource_with_product, priced_product -): - EventTypePriceListItemFactory(price_list=priced_product.price_list, price="100.00") - - space_resource_with_product.free_to_use = False - space_resource_with_product.save() - - assert Resource.objects.free_of_charge(True).count() == 0 - assert Resource.objects.free_of_charge(False).count() == 1 - - -@pytest.mark.django_db -def test_free_of_charge_free_to_use_false_with_mixed_pricing_info( - space_resource_with_product, priced_product -): - """Check combination of different prices""" - UserGroupPriceListItemFactory(price_list=priced_product.price_list, price="0.00") - UserGroupPriceListItemFactory(price_list=priced_product.price_list, price="5.00") - EventTypePriceListItemFactory(price_list=priced_product.price_list, price="100.00") - - space_resource_with_product.free_to_use = False - space_resource_with_product.save() - - assert Resource.objects.free_of_charge(True).count() == 0 - assert Resource.objects.free_of_charge(False).count() == 1 - - @pytest.mark.django_db def test_with_pricing_no_pricing_info(space_resource): """If no user group or event type pricing, max/min price should be None.""" diff --git a/respa_admin/static_src/styles/form/page-form.scss b/respa_admin/static_src/styles/form/page-form.scss index 22daa2ad7..4194e83da 100644 --- a/respa_admin/static_src/styles/form/page-form.scss +++ b/respa_admin/static_src/styles/form/page-form.scss @@ -14,6 +14,10 @@ .form-container { padding-bottom: $input-height-default + $padding-large-vertical * 2; + &-resource { + padding-bottom: $input-height-default + $padding-large-vertical * 1.5; + } + .error, .success { width: 100%; } @@ -148,3 +152,5 @@ color: red; } } + + diff --git a/respa_admin/templates/respa_admin/resources/create_resource.html b/respa_admin/templates/respa_admin/resources/create_resource.html index 6fb2dda72..4e90a1543 100644 --- a/respa_admin/templates/respa_admin/resources/create_resource.html +++ b/respa_admin/templates/respa_admin/resources/create_resource.html @@ -4,7 +4,7 @@ {% include "respa_admin/resources/form/_nav.html" %} {% endblock form_nav %} {% block body %} -
+
{% csrf_token %} {{ resource_accessibility_formset.management_form }}