Project

General

Profile

Download (6.8 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / facturation / views.py @ 76974b6f

1
# -*- coding: utf-8 -*-
2

    
3
from calebasse import cbv
4
from calebasse.facturation import forms
5

    
6
from datetime import date, datetime
7

    
8
from django.http import HttpResponseRedirect
9

    
10
from calebasse.cbv import TemplateView, UpdateView
11

    
12
from models import Invoicing
13
from calebasse.ressources.models import Service
14

    
15

    
16
def display_invoicing(request, *args, **kwargs):
17
    if request.method == 'POST':
18
        try:
19
            seq_id = request.POST.get('id', None)
20
            service_name = kwargs['service']
21
            service = Service.objects.get(slug=service_name)
22
            invoicing = Invoicing.objects.get(seq_id=seq_id, service=service)
23
            return HttpResponseRedirect('%s' % invoicing.id)
24
        except:
25
            pass
26
    return HttpResponseRedirect('.')
27

    
28
class FacturationHomepageView(TemplateView):
29

    
30
    template_name = 'facturation/index.html'
31

    
32
    def get_context_data(self, **kwargs):
33
        context = super(FacturationHomepageView, self).get_context_data(**kwargs)
34
        current = Invoicing.objects.current_for_service(self.service)
35
        last = Invoicing.objects.last_for_service(self.service)
36
        context['current'] = current
37
        context['last'] = last
38
        return context
39

    
40

    
41
class FacturationDetailView(UpdateView):
42

    
43
    context_object_name = "invoicing"
44
    model = Invoicing
45
    template_name = 'facturation/detail.html'
46

    
47
    def post(self, request, *args, **kwargs):
48
        return HttpResponseRedirect('/')
49

    
50
    def get_context_data(self, **kwargs):
51
        context = super(FacturationDetailView, self).get_context_data(**kwargs)
52
        if self.service.name == 'CMPP':
53
            (len_patients, len_invoices, len_invoices_hors_pause,
54
            len_acts_invoiced, len_acts_invoiced_hors_pause,
55
            len_patient_invoiced, len_patient_invoiced_hors_pause,
56
            len_acts_lost, len_patient_with_lost_acts,
57
            patients_stats, days_not_locked, len_patient_acts_paused,
58
                len_acts_paused) = \
59
            context['invoicing'].get_stats_or_validate()
60
            context['len_patients'] = len_patients
61
            context['len_invoices'] = len_invoices
62
            context['len_invoices_hors_pause'] = len_invoices_hors_pause
63
            context['len_invoices_pause'] = len_invoices - len_invoices_hors_pause
64
            context['len_acts_invoiced'] = len_acts_invoiced
65
            context['len_acts_invoiced_hors_pause'] = len_acts_invoiced_hors_pause
66
            context['len_acts_invoiced_pause'] = len_acts_invoiced - len_acts_invoiced_hors_pause
67
            context['len_patient_invoiced'] = len_patient_invoiced
68
            context['len_patient_invoiced_hors_pause'] = len_patient_invoiced_hors_pause
69
            context['len_patient_invoiced_pause'] = len_patient_invoiced - len_patient_invoiced_hors_pause
70
            context['len_acts_lost'] = len_acts_lost
71
            context['len_patient_with_lost_acts'] = len_patient_with_lost_acts
72
            context['patients_stats'] = patients_stats
73
            context['days_not_locked'] = days_not_locked
74
            context['len_patient_acts_paused'] = len_patient_acts_paused
75
            context['len_acts_paused'] = len_acts_paused
76
        elif self.service.name == 'CAMSP':
77
            (len_patient_pause, len_patient_hors_pause,
78
                len_acts_pause, len_acts_hors_pause, patients_stats,
79
                days_not_locked, len_patient_acts_paused,
80
                len_acts_paused) = context['invoicing'].get_stats_or_validate()
81
            if context['invoicing'].status == Invoicing.STATUS.closed and \
82
                    date.today() > context['invoicing'].end_date:
83
                context['show_validation_btn'] = True
84
            context['len_patient_pause'] = len_patient_pause
85
            context['len_patient_hors_pause'] = len_patient_hors_pause
86
            context['len_acts_pause'] = len_acts_pause
87
            context['len_acts_hors_pause'] = len_acts_hors_pause
88
            context['patients_stats'] = patients_stats
89
            context['days_not_locked'] = days_not_locked
90
            context['len_patient_acts_paused'] = len_patient_acts_paused
91
            context['len_acts_paused'] = len_acts_paused
92
        elif 'SESSAD' in self.service.name:
93
            (len_patient_pause, len_patient_hors_pause,
94
                len_acts_pause, len_acts_hors_pause,
95
                len_patient_missing_notif, len_acts_missing_notif,
96
                patients_stats, days_not_locked,
97
                len_patient_acts_paused, len_acts_paused) = \
98
                    context['invoicing'].get_stats_or_validate()
99
            if context['invoicing'].status == Invoicing.STATUS.closed and \
100
                    date.today() > context['invoicing'].end_date:
101
                context['show_validation_btn'] = True
102
            #XXX: Supressimer ligne suivante
103
            context['show_validation_btn'] = True
104
            context['len_patient_pause'] = len_patient_pause
105
            context['len_patient_hors_pause'] = len_patient_hors_pause
106
            context['len_acts_pause'] = len_acts_pause
107
            context['len_acts_hors_pause'] = len_acts_hors_pause
108
            context['len_patient_missing_notif'] = len_patient_missing_notif
109
            context['len_acts_missing_notif'] = len_acts_missing_notif
110
            context['patients_stats'] = patients_stats
111
            context['days_not_locked'] = days_not_locked
112
            context['len_patient_acts_paused'] = len_patient_acts_paused
113
            context['len_acts_paused'] = len_acts_paused
114
        return context
115

    
116

    
117
class CloseInvoicingView(cbv.FormView):
118
    template_name = 'facturation/close.html'
119
    form_class = forms.CloseInvoicingForm
120
    success_url = '..'
121

    
122
    def post(self, request, *args, **kwarg):
123
        return super(CloseInvoicingView, self).post(request, *args, **kwarg)
124

    
125
    def form_valid(self, form):
126
        print form.data
127
        service = Service.objects.get(name=form.data['service_name'])
128
        invoicing = Invoicing.objects.get(id=form.data['invoicing_id'])
129
        date_selected = datetime.strptime(form.data['date'], "%d/%m/%Y")
130
        invoicing.close(end_date=date_selected)
131
        return super(CloseInvoicingView, self).form_valid(form)
132

    
133
close_form = CloseInvoicingView.as_view()
134

    
135

    
136
class ValidationFacturationView(UpdateView):
137

    
138
    context_object_name = "invoicing"
139
    model = Invoicing
140
    template_name = 'facturation/validation.html'
141

    
142
    def post(self, request, *args, **kwargs):
143
        pk = self.kwargs.get('pk', None)
144
        invoicing = None
145
        if pk is not None:
146
            invoicing = Invoicing.objects.get(pk=pk, service=self.service)
147
        if not invoicing or \
148
                invoicing.status != Invoicing.STATUS.closed:
149
            return HttpResponseRedirect('..')
150
        invoicing.get_stats_or_validate(commit=True)
151
        return HttpResponseRedirect('..')
152

    
153
    def get_context_data(self, **kwargs):
154
        context = super(ValidationFacturationView, self).get_context_data(**kwargs)
155
        return context
(8-8/8)