Skip to content

Commit ea68d46

Browse files
🐛 Fix financial doc (#7)
* fix: 🐛 fixed bug on financial_document tax rate and version * chg: ✅ Added tests for financial document last bug on tax rate * chg: ➕ added pytest-cov dev dependency * chg: 🔖 prepare v1.1.2 * chg: 🔍 📝 changed README title
1 parent ab0e65e commit ea68d46

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Mindee python SDK
22

3+
## v1.1.2 (2020-02-19)
4+
5+
### Fix
6+
7+
* :bug: Fixed FinancialDoc invoice version and reconstruction
8+
39
## v1.1.1 (2020-01-31)
410

511
### Chg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Mindee API helper library for python
1+
# Receipt, passport and invoice OCR python helper for Mindee API
22

33
The full documentation is available [here](https://mindee.com/documentation/get-started/setup-your-account)
44

mindee/documents/financial_document.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def request(
192192
:param invoice_token: Invoices API token
193193
"""
194194
if "pdf" in input_file.file_extension:
195-
url = os.path.join(base_url, "invoices", "v1", "predict")
195+
url = os.path.join(base_url, "invoices", "v2", "predict")
196196
return request(url, input_file, invoice_token, include_words)
197197
else:
198198
url = os.path.join(base_url, "expense_receipts", "v3", "predict")
@@ -218,8 +218,9 @@ def __taxes_match_total_incl(self):
218218
total_vat = 0
219219
reconstructed_total = 0
220220
for tax in self.taxes:
221-
total_vat += tax.value
222-
reconstructed_total += tax.value + 100 * tax.value / tax.rate
221+
if tax.rate is not None and tax.rate != 0:
222+
total_vat += tax.value
223+
reconstructed_total += tax.value + 100 * tax.value / tax.rate
223224

224225
# Sanity check
225226
if total_vat <= 0:

requirements.dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pytz~=2020.1
55
setuptools~=49.2.0
66
matplotlib~=3.1.2
77
numpy~=1.18.5
8-
PyMuPDF~=1.18.1
8+
PyMuPDF~=1.18.1
9+
pytest-cov~=2.11.1

tests/documents/test_financial_doc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ def test__invoice_taxes_match_total_incl_3(invoice_pred):
236236
assert financial_doc.checklist["taxes_match_total_incl"] is False
237237

238238

239+
def test__shouldnt_raise_when_tax_rate_none(invoice_pred):
240+
# sanity check with null tax
241+
invoice_pred["total_incl"] = {"value": 507.25, "probability": 0.6}
242+
invoice_pred["taxes"] = [{"rate": "N/A", "value": 0., "probability": 0.5}]
243+
financial_doc = FinancialDocument(invoice_pred)
244+
assert financial_doc.checklist["taxes_match_total_incl"] is False
245+
246+
239247
def test_compare_1(financial_doc_from_invoice_object):
240248
# Compare same object must return all True
241249
benchmark = FinancialDocument.compare(financial_doc_from_invoice_object, financial_doc_from_invoice_object)

tests/documents/test_invoice.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ def test__taxes_plus_total_excl_match_total_incl_3(invoice_pred):
252252
assert invoice.checklist["taxes_match_total_incl"] is False
253253

254254

255+
def test__shouldnt_raise_when_tax_rate_none(invoice_pred):
256+
# sanity check with null tax
257+
invoice_pred["total_excl"] = {"value": 456.15, "probability": 0.6}
258+
invoice_pred["total_incl"] = {"value": 507.25, "probability": 0.6}
259+
invoice_pred["taxes"] = [{"rate": "N/A", "value": 0., "probability": 0.5}]
260+
invoice = Invoice(invoice_pred)
261+
assert invoice.checklist["taxes_match_total_incl"] is False
262+
263+
255264
def test_compare_1(invoice_object):
256265
# Compare same object must return all True
257266
benchmark = Invoice.compare(invoice_object, invoice_object)

0 commit comments

Comments
 (0)