Coverage for apps/accounting/signals.py: 57%
19 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
1from django.db.models import signals
2from django.dispatch import receiver
4from apps.accounting.models import Movement, PatientAccount, PositiveMovement
5from apps.patients.models import Patient
8@receiver(signals.post_save, sender=Movement)
9def trigger_account_save_after_saving_movement(sender, instance, created, **kwargs):
10 account = instance.account
11 account.save()
14@receiver(signals.post_save, sender=Patient)
15def create_patient_account_upon_creation(sender, instance, created, **kwargs):
16 pat_account, new = PatientAccount.objects.get_or_create(patient=instance)
17 pat_account.save()
20@receiver(signals.pre_save, sender=PatientAccount)
21def set_name_pre_save(sender, instance, **kwargs):
22 instance.name = "Cuenta del Paciente {}".format(instance.patient)
25@receiver(signals.pre_save, sender=PositiveMovement)
26def set_side_positive_movement(sender, instance, **kwargs):
27 if not instance.side:
28 instance.side = instance.account.get_positive_side