commit feffc42192411db2c692e799642a2fd6d56b453a
Author: Serghei MIHAI <smihai@entrouvert.com>
Date:   Fri Jul 25 11:54:25 2014 +0200

    dossiers: display anap quotations and filter by them
    
    Closes #5011

diff --git a/calebasse/dossiers/templates/dossiers/index.html b/calebasse/dossiers/templates/dossiers/index.html
index 39625847..0ee72a89 100644
--- a/calebasse/dossiers/templates/dossiers/index.html
+++ b/calebasse/dossiers/templates/dossiers/index.html
@@ -51,7 +51,7 @@
   </div>
     <br>
   <div>
-    <a href="quotations">Page des quotations</a><br/>
+    <a href="quotations">Quotations et déficiences</a><br/>
     <a href="waiting-queue">Liste d'attente</a>
   </div>
 </div>
diff --git a/calebasse/dossiers/templates/dossiers/quotations.html b/calebasse/dossiers/templates/dossiers/quotations.html
index b25d3452..731846e9 100644
--- a/calebasse/dossiers/templates/dossiers/quotations.html
+++ b/calebasse/dossiers/templates/dossiers/quotations.html
@@ -2,40 +2,47 @@
 {% load url from future %}
 
 {% block appbar %}
-    <h2>Dossiers</h2>
-    <a href=".">Retourner aux dossiers</a>
-    <button id='print-button'>Imprimer</button>
+<h2>Dossiers</h2>
+<a href=".">Retourner aux dossiers</a>
+<button id='print-button'>Imprimer</button>
 {% endblock %}
 
 {% block content %}
 <div id="sidebar">
   <div>
     <form>
-    <h3>Rechercher dans les dossiers</h3>
-    <label>Sans quotations <input name="without_quotations" type="checkbox"
-    {% if request.GET.without_quotations == 'on' %}checked="checked"{% endif %}/></label>
-
-    <h3>Avec au moins un acte (optionnel)</h3>
-    Après (jj/mm/aaaa)
-    <label><input name="date_actes_start" type="text" value="{{ request.GET.date_actes_start }}"></label>
-    Avant (jj/mm/aaaa)
-    <label><input name="date_actes_end" type="text" value="{{ request.GET.date_actes_end }}"></label>
-    {% if request.GET %}
-    <div class="search-reset">
-    <button id="search">Rechercher</button>
-    <button id="reset" class="icon-remove-sign" title="Réinitialiser"></button>
-    </div>
-    {% else %}
-    <button id="search">Rechercher</button>
-    {% endif %}
-    <p id="search-results" style="display: none; "></p>
+      <h3>Rechercher dans les dossiers</h3>
+      <div>
+        <label>sans quotations
+          <input name="without_quotations" type="checkbox"
+                 {% if request.GET.without_quotations == 'on' %}checked="checked"{% endif %}/></label>
+      </div>
+      <div>
+        <label>sans quotations ANAP
+          <input name="without_anap_quotations" type="checkbox"
+                 {% if request.GET.without_anap_quotations == 'on' %}checked="checked"{% endif %}/></label>
+      </div>
+      <h3>Avec au moins un acte (optionnel)</h3>
+      Après (jj/mm/aaaa)
+      <label><input name="date_actes_start" type="text" value="{{ request.GET.date_actes_start }}"></label>
+      Avant (jj/mm/aaaa)
+      <label><input name="date_actes_end" type="text" value="{{ request.GET.date_actes_end }}"></label>
+      {% if request.GET %}
+      <div class="search-reset">
+        <button id="search">Rechercher</button>
+        <button id="reset" class="icon-remove-sign" title="Réinitialiser"></button>
+      </div>
+      {% else %}
+      <button id="search">Rechercher</button>
+      {% endif %}
+      <p id="search-results" style="display: none; "></p>
   </div>
   <div id="filtre">
     <h3>Filtres sur l'état</h3>
     {{ search_form.states }}
     <button id="btn_all_state">Tous</button>
     <button id="btn_none_state">Aucun</button>
-    </form>
+  </form>
   </div>
 </div>
 <div class="content">
@@ -49,6 +56,7 @@
         <th rowspan="2">Mises 1</th>
         <th rowspan="2">Mises 2</th>
         <th rowspan="2">Mises 3</th>
+        <th rowspan="2">ANAP</th>
       </tr>
       <tr>
         <th>papier</th>
@@ -59,37 +67,38 @@
 
       {% for patient_record in patient_records %}
       <tr style="display: table-row;" class="pr-line {{ patient_record.state_class }}" data-link="{{ patient_record.object.id }}/view">
-          <td>{{ patient_record.object.paper_id|default_if_none:"" }}</td>
-          <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 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>{{ patient_record.object.paper_id|default_if_none:"" }}</td>
+        <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 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.anap %}<span class="icon-ok"></span>{% endif %}</td>
       </tr>
       {% endfor %}
 
     </tbody>
   </table>
 
-{% if request.GET %}
-<div class="pagination">
+  {% if request.GET %}
+  <div class="pagination">
     <span class="step-links">
-        {% if paginate_patient_records.has_previous %}
-            <a href="?{{ query }}&page={{ paginate_patient_records.previous_page_number }}">««</a>
-        {% endif %}
+      {% if paginate_patient_records.has_previous %}
+      <a href="?{{ query }}&page={{ paginate_patient_records.previous_page_number }}">««</a>
+      {% endif %}
 
-        <span class="current">
-            page {{ paginate_patient_records.number }} de {{ paginate_patient_records.paginator.num_pages }}
-        </span>
+      <span class="current">
+        page {{ paginate_patient_records.number }} de {{ paginate_patient_records.paginator.num_pages }}
+      </span>
 
-        {% if paginate_patient_records.has_next %}
-            <a href="?{{ query }}&page={{ paginate_patient_records.next_page_number }}">»»</a>
-        {% endif %}
+      {% if paginate_patient_records.has_next %}
+      <a href="?{{ query }}&page={{ paginate_patient_records.next_page_number }}">»»</a>
+      {% endif %}
     </span>
-</div>
-{% endif %}
+  </div>
+  {% endif %}
 
 
 
diff --git a/calebasse/dossiers/views.py b/calebasse/dossiers/views.py
index 94fda700..d5e3599b 100644
--- a/calebasse/dossiers/views.py
+++ b/calebasse/dossiers/views.py
@@ -840,11 +840,15 @@ class PatientRecordsQuotationsView(cbv.ListView):
             current_state = patient_record.get_current_state() or patient_record.get_state()
             state = current_state.status.name
             state_class = current_state.status.type.lower()
+            deficiencies = [getattr(patient_record, field) \
+                            for field in self.deficience_fields]
+            anap = reduce(lambda f1, f2: f1 or f2, deficiencies)
             patient_records.append(
                     {
                         'object': patient_record,
                         'state': state,
-                        'state_class': state_class
+                        'state_class': state_class,
+                        'anap': anap
                         }
                     )
         return patient_records
@@ -852,9 +856,18 @@ 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_')]
+
         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=None).filter(mises_2=None).filter(mises_3=None)
+            qs = qs.filter(mises_1__isnull=True).filter(mises_2__isnull=True).filter(mises_3__isnull=True)
+
+        if without_anap_quotations:
+            for field in self.deficience_fields:
+                anap_field = {field: 0}
+                qs = qs.filter(**anap_field)
+
         states = self.request.GET.getlist('states')
         qs = qs.filter(last_state__status__id__in=states)
 
