Blame view

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

import codecs

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

class Command(BaseCommand):
    args = 'none'

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

def get_payments():
Bartłomiej Nitoń authored
17
    payments_path = 'data/payments_20150907.csv'
Bartłomiej Nitoń authored
18
    payments_file = codecs.open(payments_path, 'wt', 'utf-8')
Bartłomiej Nitoń authored
19
20
21
    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
22
    for user in users:
Bartłomiej Nitoń authored
23
24
25
26
27
28
29
30
31
32
33
        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
34
    payments_file.close()