Browse Source

Rename Invoice.is_pdf_exists() → Invoice.pdf_exists()

Seems like a silly name :)
Jocelyn Delande 8 years ago
parent
commit
4e988ad62d

+ 6 - 2
coin/billing/models.py

@@ -116,12 +116,16 @@ class Invoice(models.Model):
         Switch invoice to validate mode. This set to False the draft field
         Switch invoice to validate mode. This set to False the draft field
         and generate the pdf
         and generate the pdf
         """
         """
-        if not self.is_pdf_exists():
+        if not self.pdf_exists():
             self.validated = True
             self.validated = True
             self.save()
             self.save()
             self.generate_pdf()
             self.generate_pdf()
 
 
-    def is_pdf_exists(self):
+    def save(self, *args, **kwargs):
+        self.number = Invoice.objects.get_next_invoice_number(self.date)
+        super(Invoice, self).save(*args, **kwargs)
+
+    def pdf_exists(self):
         return (self.validated
         return (self.validated
                 and bool(self.pdf)
                 and bool(self.pdf)
                 and private_files_storage.exists(self.pdf.name))
                 and private_files_storage.exists(self.pdf.name))

+ 1 - 1
coin/billing/templates/admin/billing/invoice/change_form.html

@@ -3,7 +3,7 @@
 {% block object-tools-items %}
 {% block object-tools-items %}
     {% if not original.validated %}
     {% if not original.validated %}
         <li><a href="{% url 'admin:invoice_validate' id=object_id %}">Valider la facture</a></li>
         <li><a href="{% url 'admin:invoice_validate' id=object_id %}">Valider la facture</a></li>
-    {% elif original.is_pdf_exists %}
+    {% elif original.pdf_exists %}
         <li><a href="{% url 'billing:invoice_pdf' id=object_id %}">Télécharger le PDF</a></li>
         <li><a href="{% url 'billing:invoice_pdf' id=object_id %}">Télécharger le PDF</a></li>
     {% endif %}
     {% endif %}
     {{ block.super }}
     {{ block.super }}

+ 1 - 1
coin/billing/templates/billing/invoice.html

@@ -7,7 +7,7 @@
         <p>Émise le {{ invoice.date }}</p>
         <p>Émise le {{ invoice.date }}</p>
     </div>
     </div>
     <div class="large-4 columns">
     <div class="large-4 columns">
-        {% if invoice.is_pdf_exists %}<a href="{% url 'billing:invoice_pdf' id=invoice.number %}" target="_blank" class="button expand"><i class="fa fa-file-pdf-o"></i> Télécharger en PDF</a>{% endif %}
+        {% if invoice.pdf_exists %}<a href="{% url 'billing:invoice_pdf' id=invoice.number %}" target="_blank" class="button expand"><i class="fa fa-file-pdf-o"></i> Télécharger en PDF</a>{% endif %}
     </div>
     </div>
 </div>
 </div>
 
 

+ 1 - 1
coin/members/templates/members/invoices.html

@@ -20,7 +20,7 @@
             <td>{{ invoice.date }}</td>
             <td>{{ invoice.date }}</td>
             <td>{{ invoice.amount }}</td>
             <td>{{ invoice.amount }}</td>
             <td{% if invoice.amount_remaining_to_pay > 0 %} class="unpaid"{% endif %}>{{ invoice.amount_remaining_to_pay }}</td>
             <td{% if invoice.amount_remaining_to_pay > 0 %} class="unpaid"{% endif %}>{{ invoice.amount_remaining_to_pay }}</td>
-            <td>{% if invoice.is_pdf_exists %}<a href="{% url 'billing:invoice_pdf' id=invoice.number %}"><i class="fa fa-file-pdf-o"></i> PDF</a>{% endif %}</td>
+            <td>{% if invoice.pdf_exists %}<a href="{% url 'billing:invoice_pdf' id=invoice.number %}"><i class="fa fa-file-pdf-o"></i> PDF</a>{% endif %}</td>
         </tr>
         </tr>
         {% empty %}
         {% empty %}
         <tr class="placeholder"><td colspan="6">Aucune facture.</td></tr>
         <tr class="placeholder"><td colspan="6">Aucune facture.</td></tr>