def clean_document(self): if get_client(self.cleaned_data['document']): raise forms.ValidationError( self.error_messages['client_exist'], code='client_exist', ) return self.cleaned_data['document']
def search_user_by_document(form): if form.is_valid(): user = get_client(form.cleaned_data['document']) if user: return JsonResponse({'document': user.document, 'id': user.id, 'ok': True, 'name': user.get_full_name()}, status=200) else: return JsonResponse({ 'error': {'document': ['No se encontro un cliente con esa cedula']}, 'ok': False}, status=400) return JsonResponse({'error': form.errors}, status=400)
def clean_guarantor(self): if self.cleaned_data['guarantor'] is None: return None guarantor = get_client(self.cleaned_data['guarantor']) if not guarantor: raise forms.ValidationError('El fiador no está registrado') client = self.cleaned_data['client'] if guarantor == client: raise forms.ValidationError( 'El fiador no puede ser la misma persona que solicita el crédito') return guarantor.id
def form_valid(self, form): form.instance.client = get_client(form.cleaned_data['document']) return super().form_valid(form)
def clean_document(self): client = get_client(self.cleaned_data['document']) if client: return self.cleaned_data['document'] raise forms.ValidationError('Cliente no registrado')