Beispiel #1
0
    def _post_clean(self):
        super(ApplicationPayUpdateForm, self)._post_clean()
        if not bool(self.errors):
            try:
                instance = self.instance
                instance.set_final_price() # if donation have changed, then we need to recalculate,
                                           # because instance is not yet saved and it means,
                                           # that this function on model is not yet run.
                active_payment_type = ActivePaymentChannel.objects.get(id=self.cleaned_data.get('payment_type'))

                if active_payment_type.payment_channel.is_bill:
                    instance.external_invoice_code, instance.external_invoice_nr = create_application_invoice(instance, active_payment_type)
                    self.success_url = reverse('application_ok', kwargs={'slug': instance.code})
                    messages.info(self.request, _('Invoice successfully created and sent to %(email)s') % {'email': instance.email})
                else:
                    self.success_url = create_application_bank_transaction(instance, active_payment_type)

            except:
                # TODO We need to catch exception and log it to sentry
                self._errors['payment_type'] = self.error_class([_("Error in connection with bank. Try again later.")])
Beispiel #2
0
    def save(self, commit=True):
        instance = super(InvoiceCreateForm, self).save(commit=False)

        try:
            active_payment_type = ActivePaymentChannel.objects.filter(competition=instance.competition, payment_channel__is_bill=True)[:1]
            if active_payment_type:
                instance.external_invoice_code, instance.external_invoice_nr = create_application_invoice(instance, active_payment_type[0], action="approve")
            else:
                self._errors['company_name'] = self.error_class([_("There is not created invoice link for this competition.")])
        except:
            self._errors['company_name'] = self.error_class([_("Error in connection with bank. Try again later.")])

        if self.request:
            instance.updated_by = self.request.user
        if instance.payment_status < Application.PAY_STATUS_WAITING:
            instance.payment_status = Application.PAY_STATUS_WAITING

        if not bool(self.errors) and commit:
            instance.save()

        return instance