Почему часть elif в моем операторе if-else не дает желаемого результата, даже если условие True в Django?

Я использую сигнал, который раньше работал совершенно нормально, когда у него была только одна часть if:

@receiver(post_save, sender=Realization)
def new_receivable_save(sender, instance, created, **kwargs):
    print('Sender: ', sender)
    print('Instance: ', instance)
    print('Instance expansion: ', instance.patient)
    print('Created?: ', created)
    print('---------------------------')
    pkg=Package.objects.filter(patient=instance.patient).order_by('-id').first()
    print('patient type: ', pkg.patient_type)
    print()
    rec=Receivables.objects.filter(patient=instance.patient).order_by('-id').first()
    print('expected value: ', rec.expected_value)
    print()
    print('deficit?', instance.deficit_or_surplus_amount<0)
    print()
    if created:
        if pkg.patient_type!='CASH' and instance.cash==False:
            if instance.deficit_or_surplus_amount<0:
                Receivables(patient=rec.patient, rt_number=rec.rt_number, discount=rec.discount, approved_package=rec.approved_package, proposed_fractions=rec.proposed_fractions, done_fractions=rec.done_fractions, base_value=rec.base_value, expected_value=instance.deficit_or_surplus_amount).save()
                print('The End')

Но у меня был другой сценарий, и мне нужно было применить elif и else части, но это почему-то не сработало. Сейчас это выглядит следующим образом:

@receiver(post_save, sender=Realization)
    def new_receivable_save(sender, instance, created, **kwargs):
        print('Sender: ', sender)
        print('Instance: ', instance)
        print('Instance expansion: ', instance.patient)
        print('Created?: ', created)
        print('---------------------------')
        pkg=Package.objects.filter(patient=instance.patient).order_by('-id').first()
        print('patient type: ', pkg.patient_type)
        print()
        rec=Receivables.objects.filter(patient=instance.patient).order_by('-id').first()
        print('expected value: ', rec.expected_value)
        print()
        print('deficit?', instance.deficit_or_surplus_amount<0)
        print()
        if created:
            if pkg.patient_type!='CASH' and instance.cash==False:
                if instance.deficit_or_surplus_amount<0:
                    Receivables(patient=rec.patient, rt_number=rec.rt_number, discount=rec.discount, approved_package=rec.approved_package, proposed_fractions=rec.proposed_fractions, done_fractions=rec.done_fractions, base_value=rec.base_value, expected_value=instance.deficit_or_surplus_amount).save()
                    print('The End')
            elif pkg.patient_type == 'CASH':
                print('patient type: ', pkg.patient_type)
                print()
                if instance.deficit_or_surplus_amount<0:
                    print('deficit?', instance.deficit_or_surplus_amount<0)
                    Receivables(patient=rec.patient, rt_number=rec.rt_number, discount=rec.discount, approved_package=rec.approved_package, proposed_fractions=rec.proposed_fractions, done_fractions=rec.done_fractions, base_value=rec.base_value, expected_value=instance.deficit_or_surplus_amount).save()
                    print('The End')
            else:
                pass

В части if говорится, что если пациент использует какую-либо государственную схему вместо оплаты наличными, выполните приведенный ниже код. Часть elif предназначена для пациента, который платит наличными. Я ввожу данные, и моя функция pkg.patient_type print возвращает CASH, но часть elif не запускается. Что здесь происходит?

EDIT:

Мои модели:

Вернуться на верх