Coverage for apps/payments/signals.py: 58%
20 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 08:29 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-23 08:29 -0600
1from django.core.files.base import ContentFile
2from django.db.models import Sum, signals
3from django.dispatch import receiver
5from .models import Payment, PaymentAllocation, PaymentExport
6from .reports import create_payment_report
7from .resources import PaymentResource
9# @receiver(signals.pre_save, sender=Payment)
10# def set_pending_to_allocate_amount_on_payment(sender, instance: Payment, *args, **kwargs):
11# instance.pending_to_allocate_amount = instance.amount - instance.allocated_amount
12#
13@receiver(signals.post_save, sender=Payment)
14@receiver(signals.post_delete, sender=Payment)
15def update_appointments_from_payments(sender, instance: Payment, *args, **kwargs):
16 if instance.appointment:
17 instance.appointment.save()
20@receiver(signals.post_save, sender=PaymentAllocation)
21@receiver(signals.post_delete, sender=PaymentAllocation)
22def update_appointments(sender, instance: PaymentAllocation, *args, **kwargs):
23 instance.appointment_charge.save()
24 instance.appointment_charge.appointment.save()
27# @receiver(signals.post_save, sender=PaymentAllocation)
28# @receiver(signals.post_delete, sender=PaymentAllocation)
29# def set_amounts_on_appointment_charge_after_payment_allocation(sender, instance: PaymentAllocation, *args, **kwargs):
30# appointment_charge = instance.appointment_charge
31# appointment_charge.paid_amount = (
32# appointment_charge.payments.aggregate(allocated_amount=Sum("amount")).get("allocated_amount") or 0
33# )
34# appointment_charge.save()
37@receiver(signals.post_save, sender=PaymentExport)
38def save_payment_export_file(sender, instance: PaymentExport, created, *args, **kwargs):
39 if created:
40 create_payment_report(instance)