Skip to content

Commit

Permalink
Merge branch 'tre-varaamo-qa' into tre-varaamo
Browse files Browse the repository at this point in the history
  • Loading branch information
jopesy committed Jan 23, 2024
2 parents 0a6dde7 + 27e761e commit 3dc8a49
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 173 deletions.
12 changes: 4 additions & 8 deletions resources/api/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
32 changes: 7 additions & 25 deletions resources/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions resources/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
14 changes: 11 additions & 3 deletions resources/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
135 changes: 2 additions & 133 deletions resources/tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 6 additions & 0 deletions respa_admin/static_src/styles/form/page-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down Expand Up @@ -148,3 +152,5 @@
color: red;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% include "respa_admin/resources/form/_nav.html" %}
{% endblock form_nav %}
{% block body %}
<div class="container form-container">
<div class="container form-container form-container-resource">
<form method="post" enctype="multipart/form-data" class="resource-form">
{% csrf_token %}
{{ resource_accessibility_formset.management_form }}
Expand Down

0 comments on commit 3dc8a49

Please sign in to comment.