Skip to content

Commit bfaa4c6

Browse files
Merge pull request #3 from publicMindee/fix_issue_#2
Fix issue #2
2 parents 2696e43 + b3a1b57 commit bfaa4c6

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

mindee/documents/invoice.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def __taxes_match_total_incl(self):
208208
total_vat = 0
209209
reconstructed_total = 0
210210
for tax in self.taxes:
211+
if tax.value is None or tax.rate is None or tax.rate == 0:
212+
return False
211213
total_vat += tax.value
212214
reconstructed_total += tax.value + 100 * tax.value / tax.rate
213215

@@ -241,6 +243,8 @@ def __taxes_match_total_excl(self):
241243
total_vat = 0
242244
reconstructed_total = 0
243245
for tax in self.taxes:
246+
if tax.value is None or tax.rate is None or tax.rate == 0:
247+
return False
244248
total_vat += tax.value
245249
reconstructed_total += 100 * tax.value / tax.rate
246250

mindee/documents/receipt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __taxes_match_total(self):
189189
total_vat = 0
190190
reconstructed_total = 0
191191
for tax in self.taxes:
192-
if tax.value is None or tax.rate is None:
192+
if tax.value is None or tax.rate is None or tax.rate == 0:
193193
return False
194194
total_vat += tax.value
195195
reconstructed_total += tax.value + 100 * tax.value / tax.rate

tests/documents/test_invoice.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,22 @@ def test_empty_object_works():
290290
invoice = Invoice()
291291
assert invoice.total_tax.value is None
292292

293+
294+
def test_null_tax_rates_dont_raise():
295+
invoice = Invoice(
296+
locale="fr",
297+
total_incl=12,
298+
total_excl=15,
299+
invoice_date="2018-12-21",
300+
invoice_number="001",
301+
due_date="2019-01-01",
302+
taxes={(1, 0), (2, 20)},
303+
supplier="Amazon",
304+
payment_details="1231456498799765",
305+
company_number="asdqsdae",
306+
vat_number="1231231232",
307+
orientation=0,
308+
total_tax=3
309+
)
310+
assert invoice.checklist["taxes_match_total_incl"] is False
311+
assert invoice.checklist["taxes_match_total_excl"] is False

tests/documents/test_receipt.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,15 @@ def test_compare_4(receipt_object_from_scratch):
179179
def test_empty_object_works():
180180
receipt = Receipt()
181181
assert receipt.total_tax.value is None
182+
183+
184+
def test_null_tax_rates_dont_raise():
185+
invoice = Receipt(
186+
locale="fr",
187+
total_incl=12,
188+
total_excl=15,
189+
taxes={(1, 0), (2, 20)},
190+
orientation=0,
191+
total_tax=3
192+
)
193+
assert invoice.checklist["taxes_match_total_incl"] is False

0 commit comments

Comments
 (0)