Skip to content

Commit

Permalink
Merge pull request #3 from publicMindee/fix_issue_#2
Browse files Browse the repository at this point in the history
Fix issue #2
  • Loading branch information
jonathanMindee authored Dec 1, 2020
2 parents 2696e43 + b3a1b57 commit bfaa4c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mindee/documents/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def __taxes_match_total_incl(self):
total_vat = 0
reconstructed_total = 0
for tax in self.taxes:
if tax.value is None or tax.rate is None or tax.rate == 0:
return False
total_vat += tax.value
reconstructed_total += tax.value + 100 * tax.value / tax.rate

Expand Down Expand Up @@ -241,6 +243,8 @@ def __taxes_match_total_excl(self):
total_vat = 0
reconstructed_total = 0
for tax in self.taxes:
if tax.value is None or tax.rate is None or tax.rate == 0:
return False
total_vat += tax.value
reconstructed_total += 100 * tax.value / tax.rate

Expand Down
2 changes: 1 addition & 1 deletion mindee/documents/receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __taxes_match_total(self):
total_vat = 0
reconstructed_total = 0
for tax in self.taxes:
if tax.value is None or tax.rate is None:
if tax.value is None or tax.rate is None or tax.rate == 0:
return False
total_vat += tax.value
reconstructed_total += tax.value + 100 * tax.value / tax.rate
Expand Down
19 changes: 19 additions & 0 deletions tests/documents/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,22 @@ def test_empty_object_works():
invoice = Invoice()
assert invoice.total_tax.value is None


def test_null_tax_rates_dont_raise():
invoice = Invoice(
locale="fr",
total_incl=12,
total_excl=15,
invoice_date="2018-12-21",
invoice_number="001",
due_date="2019-01-01",
taxes={(1, 0), (2, 20)},
supplier="Amazon",
payment_details="1231456498799765",
company_number="asdqsdae",
vat_number="1231231232",
orientation=0,
total_tax=3
)
assert invoice.checklist["taxes_match_total_incl"] is False
assert invoice.checklist["taxes_match_total_excl"] is False
12 changes: 12 additions & 0 deletions tests/documents/test_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ def test_compare_4(receipt_object_from_scratch):
def test_empty_object_works():
receipt = Receipt()
assert receipt.total_tax.value is None


def test_null_tax_rates_dont_raise():
invoice = Receipt(
locale="fr",
total_incl=12,
total_excl=15,
taxes={(1, 0), (2, 20)},
orientation=0,
total_tax=3
)
assert invoice.checklist["taxes_match_total_incl"] is False

0 comments on commit bfaa4c6

Please sign in to comment.