Coverage for website/moneybirdsynchronization/tasks.py: 33.33%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1from django.conf import settings 

2 

3from celery import shared_task 

4 

5from moneybirdsynchronization import services 

6from reimbursements.models import Reimbursement 

7 

8 

9@shared_task 

10def synchronize_moneybird(): 

11 if not settings.MONEYBIRD_SYNC_ENABLED: 

12 return 

13 

14 services.synchronize_moneybird() 

15 

16 

17@shared_task 

18def synchronize_moneybird_reimbursement(reimbursement_id): 

19 """Push the receipt for an approved reimbursement to Moneybird immediately. 

20 

21 This happens at night automatically, but can be triggered individually to 

22 allow the treasurer to continue working quickly. 

23 """ 

24 if not settings.MONEYBIRD_SYNC_ENABLED: 

25 return 

26 

27 reimbursement = Reimbursement.objects.get( 

28 id=reimbursement_id, verdict=Reimbursement.Verdict.APPROVED 

29 ) 

30 

31 owner = reimbursement.owner 

32 if ( 

33 not hasattr(owner, "moneybird_contact") 

34 or owner.moneybird_contact.needs_synchronization 

35 ): 

36 services.create_or_update_contact(owner) 

37 

38 services.create_receipt(reimbursement)