Skip to content

Commit

Permalink
Merge branch 'feature/fr/merge' of github.com:armada-ths/ais into fea…
Browse files Browse the repository at this point in the history
…ture/fr/merge
  • Loading branch information
hampfh committed Aug 4, 2024
2 parents 30454c2 + 00c6ae8 commit d790fc3
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 69 deletions.
19 changes: 19 additions & 0 deletions accounting/migrations/0034_change_exclusive_for_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.24 on 2024-08-04 20:10

import accounting.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounting', '0033_add_stock_model'),
]

operations = [
migrations.AlterField(
model_name='product',
name='exclusively_for',
field=accounting.models.ChoiceArrayField(base_field=models.CharField(choices=[('ir-timely', 'Companies who signed IR during the IR period.'), ('ir-late', 'Companies who signed IR after the IR period.')], max_length=31), blank=True, default=list, help_text='Show this product only to the selected company types. An empty selection means showing it to every company.', size=None),
),
]
9 changes: 7 additions & 2 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ class Product(models.Model):
RegistrationSection, blank=True, null=True, on_delete=models.CASCADE
)

# Currently, we can present two different products to the customer.
# One for companies who signed the IR during the IR period, and one for companies who signed it after.
# A better system would be for each product to have list of "ids" of company "types" that can see it.
# A company gets a type depending on time they signed IR, if they are a startup, non-profit, etc.
# Anyway ...
EXCLUSIVELY_FOR_CHOICES = [
("ir-signed", "Companies who have signed IR"),
("ir-unsigned", "Companies who have NOT signed IR"),
("ir-timely", "Companies who signed IR during the IR period."),
("ir-late", "Companies who signed IR after the IR period."),
]

exclusively_for = ChoiceArrayField(
Expand Down
65 changes: 65 additions & 0 deletions dashboard/api/registration/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import datetime

from ais.common import settings
from util.email import send_mail


def send_ir_confirmation_email(
request,
fair,
signature,
company,
# How many days the company has to change their initial registration application after signing the contract
ir_application_change_allowed_time=14,
# How many days after the initial registration end date the company will receive a confirmation email
ir_application_review_time=14,
):
# The deadline for the company to change their initial registration application
# either x days after signature, or the registration end date, whichever comes last.
ir_application_change_deadline = max(
[
signature.timestamp
+ datetime.timedelta(days=ir_application_change_allowed_time),
fair.registration_end_date,
]
)

# The latest date the company will receive a confirmation email
ir_application_review_date = fair.registration_end_date + datetime.timedelta(
days=ir_application_review_time
)

send_mail(
request,
template="register/email/ir_complete.html",
context={
"company": company,
"fair": fair,
"signature": signature,
"ir_application_change_deadline": ir_application_change_deadline,
"ir_application_review_date": ir_application_review_date,
"support_email": "[email protected]",
},
subject="Initial registration received!",
to=[signature.company_contact.email_address],
file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]],
)


def send_cr_confirmation_email(request, fair, company, exhibitor, signature):
# Untested
# Todo: Add packages to email
send_mail(
request,
template="register/email/cr_complete.html",
context={
"company": company,
"fair": fair,
"signature": signature,
"deadline": exhibitor.deadline_complete_registration
or fair.complete_registration_close_date,
},
subject="Final registration received!",
to=[signature.company_contact.email_address],
file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]],
)
66 changes: 5 additions & 61 deletions dashboard/api/registration/response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
from ais.common import settings
from dashboard.api.registration.email import (
send_cr_confirmation_email,
send_ir_confirmation_email,
)
from dashboard.api.registration.types.registration import get_registration
from exhibitors.models import Exhibitor
from util import JSONError, get_contract_signature, get_exhibitor, status
Expand All @@ -12,7 +14,6 @@
from register.models import SignupLog
from accounting.models import Order

from util.email import send_mail
from util.ip import get_client_ip


Expand Down Expand Up @@ -80,22 +81,7 @@ def submit_cr(request, company, fair, contact, exhibitor):
unit_price=0, # A package product is free
)

# Untested
# Todo: Add packages to email
send_mail(
request,
template="register/email/cr_complete.html",
context={
"company": company,
"fair": fair,
"signature": signature,
"deadline": exhibitor.deadline_complete_registration
or fair.complete_registration_close_date,
},
subject="Final registration received!",
to=[signature.company_contact.email_address],
file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]],
)
send_cr_confirmation_email(request, fair, company, exhibitor, signature)

try:
registration = get_registration(company, fair, contact, exhibitor)
Expand All @@ -107,48 +93,6 @@ def submit_cr(request, company, fair, contact, exhibitor):
return JsonResponse(serializer.data, safe=False)


def send_ir_confirmation_email(
request,
fair,
signature,
company,
# How many days the company has to change their initial registration application after signing the contract
ir_application_change_allowed_time=14,
# How many days after the initial registration end date the company will receive a confirmation email
ir_application_review_time=14,
):
# The deadline for the company to change their initial registration application
# either x days after signature, or the registration end date, whichever comes last.
ir_application_change_deadline = max(
[
signature.timestamp
+ datetime.timedelta(days=ir_application_change_allowed_time),
fair.registration_end_date,
]
)

# The latest date the company will receive a confirmation email
ir_application_review_date = fair.registration_end_date + datetime.timedelta(
days=ir_application_review_time
)

send_mail(
request,
template="register/email/ir_complete.html",
context={
"company": company,
"fair": fair,
"signature": signature,
"ir_application_change_deadline": ir_application_change_deadline,
"ir_application_review_date": ir_application_review_date,
"support_email": "[email protected]",
},
subject="Initial registration received!",
to=[signature.company_contact.email_address],
file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]],
)


@require_POST
def submit_ir(request, company, fair, contact):
try:
Expand Down
18 changes: 18 additions & 0 deletions register/migrations/0007_add_timely_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.24 on 2024-08-04 20:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('register', '0006_add_signup_log_ip'),
]

operations = [
migrations.AddField(
model_name='signupcontract',
name='is_timely',
field=models.BooleanField(default=True, help_text='(ONLY RELEVANT FOR IR) A contract is timely if it is signed before the IR period ends.'),
),
]
10 changes: 7 additions & 3 deletions register/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.db import models
from django.db.models import DEFERRED
from django.utils import timezone


# A 'Contact' is a person working for a 'Company'
class SignupContract(models.Model):
name = models.CharField(max_length=30)
contract = models.FileField(upload_to="contracts/%Y%m%d/")
Expand All @@ -12,6 +9,13 @@ class SignupContract(models.Model):
type = models.CharField(
max_length=200, choices=types, null=False, blank=False, default=types[0]
)

# 2024, Didrik Munther: Used to determine prices during CR.
# Usually prices for packages are more expensive if the contract is signed after IR.
is_timely = models.BooleanField(
default=True,
help_text="(ONLY RELEVANT FOR IR) A contract is timely if it is signed before the IR period ends.",
)
contract_company_type = models.ForeignKey(
"companies.CompanyType", null=False, blank=False, on_delete=models.CASCADE
)
Expand Down
1 change: 1 addition & 0 deletions templates/register/email/cr_complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
The complete registration is binding and you will be liable for all additional services selected at the last date of the registration
({{ deadline|date:"Y-m-d" }}), provided that THS Armada is able to supply your organization with your choices. To view your order, please visit the dashboard.
</p>
{% include 'email/button.html' with content="Go to dashboard" url="https://ais.armada.nu/register" %}
{% include 'email/divider.html' %}
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
Expand Down
11 changes: 8 additions & 3 deletions util/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

def get_products(fair, company):
contract, signature = get_contract_signature(company, fair, type="INITIAL")
if signature == None:
return Product.objects.none()

q = Q(exclusively_for=[])
if signature == None:
q |= Q(exclusively_for__contains=["ir-unsigned"])

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-signed"])
q |= Q(exclusively_for__contains=["ir-late"])

return Product.objects.filter(revenue__fair=fair).filter(q)

0 comments on commit d790fc3

Please sign in to comment.