diff --git a/smash/web/forms/voucher_forms.py b/smash/web/forms/voucher_forms.py index 99bb89736762a3c49a1e859d95feb0389f033fa9..946486db177dd364d547e97afba6b33fafbc9bc2 100644 --- a/smash/web/forms/voucher_forms.py +++ b/smash/web/forms/voucher_forms.py @@ -7,8 +7,9 @@ from django.utils import timezone from web.algorithm import VerhoeffAlgorithm from web.forms.forms import DATEPICKER_DATE_ATTRS -from web.models import VoucherType, VoucherTypePrice, Voucher +from web.models import VoucherType, VoucherTypePrice, Voucher, Worker from web.models.constants import VOUCHER_STATUS_NEW, VOUCHER_STATUS_USED +from web.models.worker_study_role import WORKER_VOUCHER_PARTNER logger = logging.getLogger(__name__) @@ -42,6 +43,7 @@ class VoucherForm(ModelForm): super(VoucherForm, self).__init__(*args, **kwargs) self.fields['voucher_type'].queryset = voucher_types + self.fields['usage_partner'].queryset = Worker.get_workers_by_worker_type(WORKER_VOUCHER_PARTNER) self.fields['number'].widget.attrs['readonly'] = True self.fields['number'].required = False diff --git a/smash/web/tests/forms/test_voucher_forms.py b/smash/web/tests/forms/test_voucher_forms.py index 64a78eef15b2365f515aecfa030b4da88aaeb166..ef712cfd73ce50411dced4da76f553eced508b16 100644 --- a/smash/web/tests/forms/test_voucher_forms.py +++ b/smash/web/tests/forms/test_voucher_forms.py @@ -3,10 +3,12 @@ import logging from django.urls import reverse from web.forms import VoucherForm -from web.models import Voucher +from web.models import WorkerStudyRole, Voucher from web.models.constants import VOUCHER_STATUS_USED +from web.models.worker_study_role import ROLE_CHOICES_VOUCHER_PARTNER from web.tests import LoggedInWithWorkerTestCase -from web.tests.functions import create_study_subject, create_voucher_type, format_form_field, create_voucher +from web.tests.functions import create_study_subject, create_voucher_type, format_form_field, create_voucher, \ + create_worker logger = logging.getLogger(__name__) @@ -14,6 +16,8 @@ logger = logging.getLogger(__name__) class VoucherFormTests(LoggedInWithWorkerTestCase): def setUp(self): super(VoucherFormTests, self).setUp() + self.voucher_partner = create_worker() + WorkerStudyRole.objects.filter(worker=self.voucher_partner).update(role=ROLE_CHOICES_VOUCHER_PARTNER) def test_auto_generated_use_date(self): voucher_type = create_voucher_type() @@ -24,7 +28,7 @@ class VoucherFormTests(LoggedInWithWorkerTestCase): voucher_form = VoucherForm() form_data = { "status": VOUCHER_STATUS_USED, - "usage_partner": str(self.worker.id), + "usage_partner": str(self.voucher_partner.id), "voucher_type": voucher_type.id } for key, value in voucher_form.initial.items(): @@ -58,7 +62,7 @@ class VoucherFormTests(LoggedInWithWorkerTestCase): def test_valid_status(self): study_subject = create_study_subject() voucher = create_voucher(study_subject) - voucher.usage_partner = self.worker + voucher.usage_partner = self.voucher_partner voucher.save() voucher_form = VoucherForm(instance=voucher)