mirror of
https://github.com/nikdoof/pacmanager.git
synced 2025-12-13 07:32:15 +00:00
Added chargecorps command
This commit is contained in:
25
pacmanager/core/management/commands/chargecorps.py
Normal file
25
pacmanager/core/management/commands/chargecorps.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import logging
|
||||
import datetime
|
||||
import calendar
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils.timezone import utc, now
|
||||
|
||||
from core.models import Transaction, MonthTotal
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Charge all outstand months for corporations'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
for total in MonthTotal.objects.filter(charged=False):
|
||||
if datetime.datetime(total.year, total.month, calendar.monthrange(total.year, total.month)[1], 23, 59, 59) < now():
|
||||
print "Charging %s - %s/%s" % (total.corporation, total.year, total.month)
|
||||
total.corporation.balance -= Decimal(str(self.object.fees_due))
|
||||
total.charged = True
|
||||
|
||||
total.save()
|
||||
total.corporation.save()
|
||||
|
||||
Transaction.objects.create(corporation=total.corporation, type=Transaction.TRANSACTION_TYPE_CHARGE, value=Decimal(str(-total.fees_due)), comment="Charges for period %s-%s" % (total.year, total.month))
|
||||
Reference in New Issue
Block a user