forked from AtelierSoude/OpenRepairPlatform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_problem_fees_2021.py
executable file
·47 lines (39 loc) · 1.42 KB
/
script_problem_fees_2021.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from copy import deepcopy
from openrepairplatform.user.models import Membership, Fee
rest_memberships_fee = []
rest_memberships = []
Fee.objects.filter(amount=0).delete()
for membership in Membership.objects.all():
for fee in membership.fees.all():
fees = membership.fees.filter(date=fee.date, amount=fee.amount)
if fees.count() > 1:
for f in fees:
if f.pk != fee.pk:
f.delete()
if membership.fees.all():
if membership.fees.count() == 1:
fee = membership.fees.first()
fee.date = membership.first_payment
fee.save()
else:
for fee in membership.fees.all():
if fee.event:
fee.date = fee.event.date
fee.save()
else:
rest_memberships_fee.append(fee)
membership.computed_amount()
membership.save()
for fee in rest_memberships_fee:
if fee.membership not in rest_memberships:
rest_memberships.append(fee.membership)
for membership in rest_memberships:
advised_fee = deepcopy(membership.organization.advised_fee)
for fee in membership.fees.filter(date__year__gte=2021):
advised_fee -= fee.amount
if advised_fee <= 0:
fee.date = membership.first_payment
fee.save()
membership.computed_amount()
membership.save()
break