Coverage for website/payments/forms.py: 100.00%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1from django import forms 

2from django.utils.translation import gettext as _ 

3 

4from payments.models import BankAccount, Payment 

5from payments.widgets import SignatureWidget 

6 

7 

8class BankAccountForm(forms.ModelForm): 

9 """Custom admin form for BankAccount model to add the widget for the signature.""" 

10 

11 direct_debit = forms.BooleanField( 

12 required=False, label=_("I want to use this account for direct debits") 

13 ) 

14 

15 class Meta: 

16 fields = ( 

17 "initials", 

18 "last_name", 

19 "iban", 

20 "bic", 

21 "signature", 

22 "valid_from", 

23 "mandate_no", 

24 "owner", 

25 ) 

26 model = BankAccount 

27 

28 

29class BankAccountUserRevokeForm(forms.ModelForm): 

30 """Custom form for members to revoke their bank account.""" 

31 

32 def is_valid(self): 

33 return super().is_valid() and self.instance.can_be_revoked 

34 

35 class Meta: 

36 fields = ("valid_until",) 

37 model = BankAccount 

38 

39 

40class BankAccountAdminForm(forms.ModelForm): 

41 """Custom admin form for BankAccount model to add the widget for the signature.""" 

42 

43 class Meta: 

44 fields = "__all__" 

45 model = BankAccount 

46 widgets = { 

47 "signature": SignatureWidget(), 

48 } 

49 

50 

51class PaymentCreateForm(forms.Form): 

52 """Custom form to create a payment by a user.""" 

53 

54 app_label = forms.CharField(max_length=255, widget=forms.HiddenInput()) 

55 model_name = forms.CharField(max_length=255, widget=forms.HiddenInput()) 

56 payable = forms.CharField(max_length=255, widget=forms.HiddenInput()) 

57 next = forms.CharField(max_length=255, widget=forms.HiddenInput()) 

58 payable_hash = forms.CharField(max_length=255, widget=forms.HiddenInput()) 

59 

60 class Meta: 

61 fields = "__all__" 

62 

63 

64class BatchPaymentInlineAdminForm(forms.ModelForm): 

65 """Custom admin form for Payments model for the Batch inlines to add remove from batch option.""" 

66 

67 remove_batch = forms.BooleanField( 

68 required=False, label=_("Remove payment from batch") 

69 ) 

70 

71 class Meta: 

72 fields = ( 

73 "topic", 

74 "paid_by", 

75 "amount", 

76 "created_at", 

77 "notes", 

78 ) 

79 model = Payment