Commit e1033cb5 authored by jocelyn's avatar jocelyn

Corrige le total TTC lorsque la qté d'un produit ≠ 0

Fix #206
parent d13c7621
......@@ -175,7 +175,7 @@ class Invoice(models.Model):
def amount_before_tax(self):
total = Decimal('0.0')
for detail in self.details.all():
total += detail.amount
total += detail.total_before_tax()
return total.quantize(Decimal('0.01'))
amount_before_tax.short_description = 'Montant HT'
......@@ -345,11 +345,16 @@ class InvoiceDetail(models.Model):
return self.label
def total(self):
"""Calcul le total"""
"""Calcul le total TTC"""
return (self.amount * (self.tax / Decimal('100.0') +
Decimal('1.0')) *
self.quantity).quantize(Decimal('0.01'))
def total_before_tax(self):
"""Calcul le total HT"""
return (self.amount * self.quantity).quantize(Decimal('0.01'))
class Meta:
verbose_name = 'détail de facture'
......
......@@ -188,6 +188,19 @@ class BillingInvoiceCreationTests(TestCase):
self.assertEqual(invoice.amount_before_tax(), 110)
def test_invoice_amount_before_tax_with_quantity(self):
invoice = Invoice(member=self.member)
invoice.save()
invoice.details.create(label=self.offer.name,
amount=100,
quantity=0.5,
offersubscription=None,
period_from=datetime.date(2014, 1, 1),
period_to=datetime.date(2014, 3, 31),
tax=0)
self.assertEqual(invoice.amount_before_tax(), 50)
def test_non_billable_offer_isnt_charged(self):
"""
Test qu'une offre non facturable n'est pas prise en compte
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment