Skip to content

Commit

Permalink
Remove display_specific_boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
didrikmunther committed Aug 4, 2024
1 parent 9108dec commit 149ebe5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 34 deletions.
17 changes: 17 additions & 0 deletions accounting/migrations/0039_remove_display_specific_boolean.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
11 changes: 0 additions & 11 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
56 changes: 39 additions & 17 deletions dashboard/api/registration/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -41,15 +43,46 @@ 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:
registration = get_registration(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

Expand All @@ -59,28 +92,17 @@ 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,
company=company,
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:
Expand Down
7 changes: 1 addition & 6 deletions util/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions util/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 149ebe5

Please sign in to comment.