commit 748e8d64e8318079252787877cb0ba3f33bafa24
Author: Serghei MIHAI <smihai@entrouvert.com>
Date:   Fri Jul 25 14:43:49 2014 +0200

    dossiers: quotations table refactored
    
    Closes #5013

diff --git a/calebasse/dossiers/templates/dossiers/quotations.html b/calebasse/dossiers/templates/dossiers/quotations.html
index 731846e9..893bfdb8 100644
--- a/calebasse/dossiers/templates/dossiers/quotations.html
+++ b/calebasse/dossiers/templates/dossiers/quotations.html
@@ -52,10 +52,11 @@
         <th colspan="2">N° dossier
         </th><th rowspan="2">Nom</th>
         <th rowspan="2">Prénom</th>
+        <th rowspan="2">Date de naissance</th>
         <th rowspan="2">État du dossier</th>
-        <th rowspan="2">Mises 1</th>
-        <th rowspan="2">Mises 2</th>
-        <th rowspan="2">Mises 3</th>
+        <th rowspan="2">Date du prochain rendez-vou</th>
+        <th rowspan="2">Date du dernier rendez-vous</th>
+        <th rowspan="2">Mises</th>
         <th rowspan="2">ANAP</th>
       </tr>
       <tr>
@@ -71,10 +72,16 @@
         <td>{{ patient_record.object.id }}</td>
         <td><span class="lastname">{{ patient_record.object.last_name }}</span></td>
         <td>{{ patient_record.object.first_name }}</td>
+        <td>{{ patient_record.object.birthdate|date:"SHORT_DATE_FORMAT" }}</td>
         <td class="{{ patient_record.state_class }}">{{ patient_record.state }}</td>
-        <td>{% for mise in patient_record.object.mises_1.all %}{{ mise }}<br/>{% endfor %}</td>
-        <td>{% for mise in patient_record.object.mises_2.all %}{{ mise }}<br/>{% endfor %}</td>
-        <td>{% for mise in patient_record.object.mises_3.all %}{{ mise }}<br/>{% endfor %}</td>
+        <td>{% if patient_record.next_rdv_date %}
+          {{ patient_record.next_rdv_date|date:"DATETIME_FORMAT" }}
+          {% endif %}
+        </td>
+        <td>{% if patient_record.last_rdv_date %}
+          {{ patient_record.last_rdv_date|date:"DATETIME_FORMAT" }}
+          {% endif %}</td>
+        <td>{% if patient_record.mises %}<span class="icon-ok"></span>{% endif %}</td>
         <td>{% if patient_record.anap %}<span class="icon-ok"></span>{% endif %}</td>
       </tr>
       {% endfor %}
diff --git a/calebasse/dossiers/views.py b/calebasse/dossiers/views.py
index d5e3599b..c1153add 100644
--- a/calebasse/dossiers/views.py
+++ b/calebasse/dossiers/views.py
@@ -843,12 +843,27 @@ class PatientRecordsQuotationsView(cbv.ListView):
             deficiencies = [getattr(patient_record, field) \
                             for field in self.deficience_fields]
             anap = reduce(lambda f1, f2: f1 or f2, deficiencies)
+            mises = reduce(lambda m1, m2: m1+m2, [list(getattr(patient_record, field).all()) for field in self.mises_fields])
+            next_rdv = get_next_rdv(patient_record)
+            last_rdv = get_last_rdv(patient_record)
+
+            if next_rdv:
+                next_rdv_datetime = next_rdv.start_datetime
+            else:
+                next_rdv_datetime = None
+            if last_rdv:
+                last_rdv_datetime = last_rdv['start_datetime']
+            else:
+                last_rdv_datetime = None
             patient_records.append(
                     {
                         'object': patient_record,
                         'state': state,
                         'state_class': state_class,
-                        'anap': anap
+                        'anap': anap,
+                        'mises': mises,
+                        'next_rdv_date': next_rdv_datetime,
+                        'last_rdv_date': last_rdv_datetime
                         }
                     )
         return patient_records
@@ -856,12 +871,16 @@ class PatientRecordsQuotationsView(cbv.ListView):
     def get_queryset(self):
         form = forms.QuotationsForm(data=self.request.GET or None)
         qs = super(PatientRecordsQuotationsView, self).get_queryset()
-        self.deficience_fields = [field for field in self.model._meta.get_all_field_names() if field.startswith('deficiency_')]
+        all_field_names = self.model._meta.get_all_field_names()
+        self.deficience_fields = [field for field in all_field_names if field.startswith('deficiency_')]
+        self.mises_fields = [field for field in all_field_names if field.startswith('mises_')]
 
         without_quotations = self.request.GET.get('without_quotations')
         without_anap_quotations = self.request.GET.get('without_anap_quotations')
         if without_quotations:
-            qs = qs.filter(mises_1__isnull=True).filter(mises_2__isnull=True).filter(mises_3__isnull=True)
+            for field in self.mises_fields:
+                mise_field = {'%s__isnull' % field: True}
+                qs = qs.filter(**mise_field)
 
         if without_anap_quotations:
             for field in self.deficience_fields:
