Browse Source

Use a draft invoice number before validation

Jocelyn Delande 8 years ago
parent
commit
b8688ea4c6
2 changed files with 9 additions and 1 deletions
  1. 8 0
      coin/billing/models.py
  2. 1 1
      coin/billing/tests.py

+ 8 - 0
coin/billing/models.py

@@ -121,6 +121,14 @@ class Invoice(models.Model):
                            null=True, blank=True,
                            verbose_name='PDF')
 
+    def save(self, *args, **kwargs):
+        # First save to get a PK
+        super(Invoice, self).save(*args, **kwargs)
+        # Then use that pk to build draft invoice number
+        if not self.validated and self.pk and not self.number:
+            self.number = 'DRAFT-{}'.format(self.pk)
+            self.save()
+
     def amount(self):
         """
         Calcul le montant de la facture

+ 1 - 1
coin/billing/tests.py

@@ -232,7 +232,7 @@ class InvoiceQuerySetTests(TestCase):
 
     def test_number_workflow(self):
         iv = Invoice.objects.create()
-        self.assertEqual(iv.number, '')
+        self.assertEqual(iv.number, 'DRAFT-1')
         iv.validate()
         self.assertRegexpMatches(iv.number, r'.*-000001$')