From 149ebe56c2b232f380ef7801bb4969590825c3ac Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Sun, 4 Aug 2024 22:02:16 +0200 Subject: [PATCH] Remove display_specific_boolean --- .../0039_remove_display_specific_boolean.py | 17 ++++++ accounting/models.py | 11 ---- dashboard/api/registration/response.py | 56 +++++++++++++------ util/product.py | 7 +-- util/status.py | 4 ++ 5 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 accounting/migrations/0039_remove_display_specific_boolean.py diff --git a/accounting/migrations/0039_remove_display_specific_boolean.py b/accounting/migrations/0039_remove_display_specific_boolean.py new file mode 100644 index 00000000..1e78bd2d --- /dev/null +++ b/accounting/migrations/0039_remove_display_specific_boolean.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.24 on 2024-08-04 22:00 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0038_add_display_only_when_specific_for_packages'), + ] + + operations = [ + migrations.RemoveField( + model_name='product', + name='display_only_when_specific_for_packages', + ), + ] diff --git a/accounting/models.py b/accounting/models.py index ed978717..3de3feb8 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -200,17 +200,6 @@ class Product(models.Model): ), ) - display_only_when_specific_for_packages = models.BooleanField( - default=False, - help_text=" ".join( - [ - "This product will only be shown to the customer if they select a package that has this product as a specific product.", - "When to use this: e.g. A package is gatekeeping this product, only show the product when the package is selected.", - "When not to use this: e.g. This product's price is only affected by one or more packages, but the product is still available for purchase without the package.", - ] - ), - ) - class Meta: verbose_name_plural = "Products" ordering = ["ordering"] diff --git a/dashboard/api/registration/response.py b/dashboard/api/registration/response.py index 113a1add..a9a5bca4 100644 --- a/dashboard/api/registration/response.py +++ b/dashboard/api/registration/response.py @@ -33,6 +33,8 @@ def handle_response(request, company, fair, contact, exhibitor): serializer = get_serializer(request, registration) + print(order_is_allowed(fair, company)) + if request.method == "GET": return JsonResponse(serializer.data, safe=False) elif request.method == "PUT": @@ -41,6 +43,39 @@ def handle_response(request, company, fair, contact, exhibitor): return status.UNSUPPORTED_METHOD +def order_is_allowed(fair, company): + orders = Order.objects.filter( + purchasing_company=company, + product__revenue__fair=fair, + ) + + package = orders.filter(product__category__name="Package").first() + if package is None: + return False + + return True + + +def handle_submitted_order(fair, company): + orders = Order.objects.filter( + purchasing_company=company, + product__revenue__fair=fair, + ) + + # Add package products + package_products = orders.filter( + product__category__name="Package", + ) + for package in package_products: + for child in package.product.child_products.all(): + Order.objects.create( + purchasing_company=company, + product=child.child_product, + quantity=child.quantity, + unit_price=0, # A package product is free + ) + + @require_POST def submit_cr(request, company, fair, contact, exhibitor): try: @@ -48,8 +83,6 @@ def submit_cr(request, company, fair, contact, exhibitor): except JSONError as error: return error.status - # Currently will not happen, because you can only - # call submit on your own company if registration.contact == None: return status.COMPANY_DOES_NOT_EXIST @@ -59,6 +92,9 @@ def submit_cr(request, company, fair, contact, exhibitor): if registration.ir_signature is None: return status.COMPANY_NOT_SIGNED_IR + if not order_is_allowed(fair, company): + return status.ORDER_NOT_ALLOWED + signature = SignupLog.objects.create( company_contact=contact, contract=registration.cr_contract, @@ -66,21 +102,7 @@ def submit_cr(request, company, fair, contact, exhibitor): ip_address=get_client_ip(request), ) - # Add package products - package_products = Order.objects.filter( - purchasing_company=company, - product__revenue__fair=fair, - product__category__name="Package", - ) - for package in package_products: - for child in package.product.child_products.all(): - Order.objects.create( - purchasing_company=company, - product=child.child_product, - quantity=child.quantity, - unit_price=0, # A package product is free - ) - + handle_submitted_order(fair, company) send_cr_confirmation_email(request, fair, company, exhibitor, signature) try: diff --git a/util/product.py b/util/product.py index 40d46ba5..8d3a3161 100644 --- a/util/product.py +++ b/util/product.py @@ -11,14 +11,9 @@ def get_products(fair, company): q = Q(exclusively_for=[]) - print("timely", signature.contract.is_timely) - if signature.contract.is_timely: q |= Q(exclusively_for__contains=["ir-timely"]) else: q |= Q(exclusively_for__contains=["ir-late"]) - return Product.objects.filter( - revenue__fair=fair, - display_only_when_specific_for_packages=False, - ).filter(q) + return Product.objects.filter(revenue__fair=fair).filter(q) diff --git a/util/status.py b/util/status.py index 846e7bae..69b2c775 100644 --- a/util/status.py +++ b/util/status.py @@ -47,6 +47,10 @@ def serializer_error(errors): {"error": "company_did_not_sign_ir", "message": "Company has not signed IR"}, status=status.HTTP_403_FORBIDDEN, ) +ORDER_NOT_ALLOWED = JsonResponse( + {"error": "order_not_allowed", "message": "Order is not allowed"}, + status=status.HTTP_403_FORBIDDEN, +) COMPANY_NOT_ACCEPTED = JsonResponse( {"error": "company_not_accepted", "message": "Company has not been accepted"}, status=status.HTTP_403_FORBIDDEN,