From 2ef3c0260ac9482b02b521946f905e9ec4d233f1 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sat, 6 May 2017 21:15:44 +0200 Subject: [PATCH] Fix error on accounting when no target_type specified --- accounting/views.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/accounting/views.py b/accounting/views.py index c70de381..76452292 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -304,14 +304,15 @@ class OperationForm(forms.ModelForm): def clean(self): self.cleaned_data = super(OperationForm, self).clean() - if self.cleaned_data['target_type'] == "USER": - self.cleaned_data['target_id'] = self.cleaned_data['user'].id - elif self.cleaned_data['target_type'] == "ACCOUNT": - self.cleaned_data['target_id'] = self.cleaned_data['club_account'].id - elif self.cleaned_data['target_type'] == "CLUB": - self.cleaned_data['target_id'] = self.cleaned_data['club'].id - elif self.cleaned_data['target_type'] == "COMPANY": - self.cleaned_data['target_id'] = self.cleaned_data['company'].id + if 'target_type' in self.cleaned_data.keys(): + if self.cleaned_data['target_type'] == "USER": + self.cleaned_data['target_id'] = self.cleaned_data['user'].id + elif self.cleaned_data['target_type'] == "ACCOUNT": + self.cleaned_data['target_id'] = self.cleaned_data['club_account'].id + elif self.cleaned_data['target_type'] == "CLUB": + self.cleaned_data['target_id'] = self.cleaned_data['club'].id + elif self.cleaned_data['target_type'] == "COMPANY": + self.cleaned_data['target_id'] = self.cleaned_data['company'].id return self.cleaned_data def save(self):