Blame view

dictionary/management/commands/get_payments.py 1.52 KB
Bartłomiej Nitoń authored
1
2
3
#-*- coding:utf-8 -*-

import codecs
Bartłomiej Nitoń authored
4
import datetime
Bartłomiej Nitoń authored
5
6

from django.contrib.auth.models import User
Bartłomiej Nitoń authored
7
from django.core.management.base import BaseCommand
Bartłomiej Nitoń authored
8
Bartłomiej Nitoń authored
9
from dictionary.ajax_user_stats import get_lexical_stats, get_phraseology_stats, get_semantics_stats
Bartłomiej Nitoń authored
10
11
12
13
14
15
16
17

class Command(BaseCommand):
    args = 'none'

    def handle(self, **options):
        get_payments()

def get_payments():
Bartłomiej Nitoń authored
18
19
    now = datetime.datetime.now().strftime('%Y%m%d')
    payments_path = 'data/payments_%s.csv' % now
Bartłomiej Nitoń authored
20
    payments_file = codecs.open(payments_path, 'wt', 'utf-8')
Bartłomiej Nitoń authored
21
22
23
    users = User.objects.order_by('username')

    payments_file.write(u'Użytkownik\tFunkcja\tKwota zapłacona\tKwota za wykonaną pracę\tNadpłata\n')
Bartłomiej Nitoń authored
24
    for user in users:
Bartłomiej Nitoń authored
25
26
27
28
29
30
31
32
33
34
35
        print user
        function = user.groups.all()[0].name
        lex_work_stats = get_lexical_stats(user)
        phraseology_work_stats = get_phraseology_stats(user)
        semantics_work_stats = get_semantics_stats(user)
        total_earned_cash = round(lex_work_stats['earned_cash']+phraseology_work_stats['earned_cash']+semantics_work_stats['earned_cash'], 2)
        paid_cash = round(user.user_stats.paid_cash, 2)
        surcharge = round(user.user_stats.paid_cash-total_earned_cash, 2)
        if total_earned_cash > 0.0:
            payments_file.write(u'%s\t%s\t%.2f\t%.2f\t%.2f\n' % (user.username, function, 
                                                                 paid_cash, total_earned_cash, surcharge))                                                                
Bartłomiej Nitoń authored
36
    payments_file.close()