Project

General

Profile

Download (6.8 KB) Statistics
| Branch: | Tag: | Revision:
cfb62e2b Mikaël Ates
# -*- coding: utf-8 -*-

6c0f005e Mikaël Ates
from calebasse import cbv
from calebasse.facturation import forms

from datetime import date, datetime
cfb62e2b Mikaël Ates
from django.http import HttpResponseRedirect

from calebasse.cbv import TemplateView, UpdateView

from models import Invoicing
6c0f005e Mikaël Ates
from calebasse.ressources.models import Service
cfb62e2b Mikaël Ates
30f0ea5d Mikaël Ates
def display_invoicing(request, *args, **kwargs):
if request.method == 'POST':
try:
seq_id = request.POST.get('id', None)
service_name = kwargs['service']
service = Service.objects.get(slug=service_name)
invoicing = Invoicing.objects.get(seq_id=seq_id, service=service)
return HttpResponseRedirect('%s' % invoicing.id)
except:
pass
return HttpResponseRedirect('.')

cfb62e2b Mikaël Ates
class FacturationHomepageView(TemplateView):

template_name = 'facturation/index.html'

def get_context_data(self, **kwargs):
context = super(FacturationHomepageView, self).get_context_data(**kwargs)
current = Invoicing.objects.current_for_service(self.service)
last = Invoicing.objects.last_for_service(self.service)
context['current'] = current
context['last'] = last
return context

3538ec20 Mikaël Ates
cfb62e2b Mikaël Ates
class FacturationDetailView(UpdateView):

context_object_name = "invoicing"
model = Invoicing
template_name = 'facturation/detail.html'

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

def get_context_data(self, **kwargs):
context = super(FacturationDetailView, self).get_context_data(**kwargs)
3538ec20 Mikaël Ates
if self.service.name == 'CMPP':
(len_patients, len_invoices, len_invoices_hors_pause,
len_acts_invoiced, len_acts_invoiced_hors_pause,
len_patient_invoiced, len_patient_invoiced_hors_pause,
len_acts_lost, len_patient_with_lost_acts,
bc7e290e Mikaël Ates
patients_stats, days_not_locked, len_patient_acts_paused,
len_acts_paused) = \
3538ec20 Mikaël Ates
context['invoicing'].get_stats_or_validate()
context['len_patients'] = len_patients
context['len_invoices'] = len_invoices
context['len_invoices_hors_pause'] = len_invoices_hors_pause
context['len_invoices_pause'] = len_invoices - len_invoices_hors_pause
context['len_acts_invoiced'] = len_acts_invoiced
context['len_acts_invoiced_hors_pause'] = len_acts_invoiced_hors_pause
context['len_acts_invoiced_pause'] = len_acts_invoiced - len_acts_invoiced_hors_pause
context['len_patient_invoiced'] = len_patient_invoiced
context['len_patient_invoiced_hors_pause'] = len_patient_invoiced_hors_pause
context['len_patient_invoiced_pause'] = len_patient_invoiced - len_patient_invoiced_hors_pause
context['len_acts_lost'] = len_acts_lost
context['len_patient_with_lost_acts'] = len_patient_with_lost_acts
context['patients_stats'] = patients_stats
context['days_not_locked'] = days_not_locked
bc7e290e Mikaël Ates
context['len_patient_acts_paused'] = len_patient_acts_paused
context['len_acts_paused'] = len_acts_paused
3538ec20 Mikaël Ates
elif self.service.name == 'CAMSP':
09de66b4 Mikaël Ates
(len_patient_pause, len_patient_hors_pause,
bc7e290e Mikaël Ates
len_acts_pause, len_acts_hors_pause, patients_stats,
days_not_locked, len_patient_acts_paused,
len_acts_paused) = context['invoicing'].get_stats_or_validate()
885b4cb9 Mikaël Ates
if context['invoicing'].status == Invoicing.STATUS.closed and \
date.today() > context['invoicing'].end_date:
context['show_validation_btn'] = True
09de66b4 Mikaël Ates
context['len_patient_pause'] = len_patient_pause
context['len_patient_hors_pause'] = len_patient_hors_pause
context['len_acts_pause'] = len_acts_pause
context['len_acts_hors_pause'] = len_acts_hors_pause
bc7e290e Mikaël Ates
context['patients_stats'] = patients_stats
09de66b4 Mikaël Ates
context['days_not_locked'] = days_not_locked
bc7e290e Mikaël Ates
context['len_patient_acts_paused'] = len_patient_acts_paused
context['len_acts_paused'] = len_acts_paused
cfb62e2b Mikaël Ates
elif 'SESSAD' in self.service.name:
1368bb27 Mikaël Ates
(len_patient_pause, len_patient_hors_pause,
len_acts_pause, len_acts_hors_pause,
len_patient_missing_notif, len_acts_missing_notif,
bc7e290e Mikaël Ates
patients_stats, days_not_locked,
len_patient_acts_paused, len_acts_paused) = \
context['invoicing'].get_stats_or_validate()
885b4cb9 Mikaël Ates
if context['invoicing'].status == Invoicing.STATUS.closed and \
date.today() > context['invoicing'].end_date:
context['show_validation_btn'] = True
bc7e290e Mikaël Ates
#XXX: Supressimer ligne suivante
context['show_validation_btn'] = True
1368bb27 Mikaël Ates
context['len_patient_pause'] = len_patient_pause
context['len_patient_hors_pause'] = len_patient_hors_pause
context['len_acts_pause'] = len_acts_pause
context['len_acts_hors_pause'] = len_acts_hors_pause
context['len_patient_missing_notif'] = len_patient_missing_notif
context['len_acts_missing_notif'] = len_acts_missing_notif
bc7e290e Mikaël Ates
context['patients_stats'] = patients_stats
1368bb27 Mikaël Ates
context['days_not_locked'] = days_not_locked
bc7e290e Mikaël Ates
context['len_patient_acts_paused'] = len_patient_acts_paused
context['len_acts_paused'] = len_acts_paused
cfb62e2b Mikaël Ates
return context


6c0f005e Mikaël Ates
class CloseInvoicingView(cbv.FormView):
cfb62e2b Mikaël Ates
template_name = 'facturation/close.html'
6c0f005e Mikaël Ates
form_class = forms.CloseInvoicingForm
success_url = '..'
cfb62e2b Mikaël Ates
6c0f005e Mikaël Ates
def post(self, request, *args, **kwarg):
return super(CloseInvoicingView, self).post(request, *args, **kwarg)

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

close_form = CloseInvoicingView.as_view()
cfb62e2b Mikaël Ates
ad503195 Mikaël Ates
class ValidationFacturationView(UpdateView):

context_object_name = "invoicing"
model = Invoicing
template_name = 'facturation/validation.html'

def post(self, request, *args, **kwargs):
pk = self.kwargs.get('pk', None)
invoicing = None
if pk is not None:
invoicing = Invoicing.objects.get(pk=pk, service=self.service)
885b4cb9 Mikaël Ates
if not invoicing or \
ad503195 Mikaël Ates
invoicing.status != Invoicing.STATUS.closed:
return HttpResponseRedirect('..')
invoicing.get_stats_or_validate(commit=True)
return HttpResponseRedirect('..')

def get_context_data(self, **kwargs):
885b4cb9 Mikaël Ates
context = super(ValidationFacturationView, self).get_context_data(**kwargs)
ad503195 Mikaël Ates
return context