Skip to content

Commit

Permalink
🐛 Fix financial doc (#7)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jonathanMindee authored Feb 19, 2021
1 parent ab0e65e commit ea68d46
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Mindee python SDK

## v1.1.2 (2020-02-19)

### Fix

* :bug: Fixed FinancialDoc invoice version and reconstruction

## v1.1.1 (2020-01-31)

### Chg
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mindee API helper library for python
# Receipt, passport and invoice OCR python helper for Mindee API

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

Expand Down
7 changes: 4 additions & 3 deletions mindee/documents/financial_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def request(
:param invoice_token: Invoices API token
"""
if "pdf" in input_file.file_extension:
url = os.path.join(base_url, "invoices", "v1", "predict")
url = os.path.join(base_url, "invoices", "v2", "predict")
return request(url, input_file, invoice_token, include_words)
else:
url = os.path.join(base_url, "expense_receipts", "v3", "predict")
Expand All @@ -218,8 +218,9 @@ def __taxes_match_total_incl(self):
total_vat = 0
reconstructed_total = 0
for tax in self.taxes:
total_vat += tax.value
reconstructed_total += tax.value + 100 * tax.value / tax.rate
if tax.rate is not None and tax.rate != 0:
total_vat += tax.value
reconstructed_total += tax.value + 100 * tax.value / tax.rate

# Sanity check
if total_vat <= 0:
Expand Down
3 changes: 2 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pytz~=2020.1
setuptools~=49.2.0
matplotlib~=3.1.2
numpy~=1.18.5
PyMuPDF~=1.18.1
PyMuPDF~=1.18.1
pytest-cov~=2.11.1
8 changes: 8 additions & 0 deletions tests/documents/test_financial_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def test__invoice_taxes_match_total_incl_3(invoice_pred):
assert financial_doc.checklist["taxes_match_total_incl"] is False


def test__shouldnt_raise_when_tax_rate_none(invoice_pred):
# sanity check with null tax
invoice_pred["total_incl"] = {"value": 507.25, "probability": 0.6}
invoice_pred["taxes"] = [{"rate": "N/A", "value": 0., "probability": 0.5}]
financial_doc = FinancialDocument(invoice_pred)
assert financial_doc.checklist["taxes_match_total_incl"] is False


def test_compare_1(financial_doc_from_invoice_object):
# Compare same object must return all True
benchmark = FinancialDocument.compare(financial_doc_from_invoice_object, financial_doc_from_invoice_object)
Expand Down
9 changes: 9 additions & 0 deletions tests/documents/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ def test__taxes_plus_total_excl_match_total_incl_3(invoice_pred):
assert invoice.checklist["taxes_match_total_incl"] is False


def test__shouldnt_raise_when_tax_rate_none(invoice_pred):
# sanity check with null tax
invoice_pred["total_excl"] = {"value": 456.15, "probability": 0.6}
invoice_pred["total_incl"] = {"value": 507.25, "probability": 0.6}
invoice_pred["taxes"] = [{"rate": "N/A", "value": 0., "probability": 0.5}]
invoice = Invoice(invoice_pred)
assert invoice.checklist["taxes_match_total_incl"] is False


def test_compare_1(invoice_object):
# Compare same object must return all True
benchmark = Invoice.compare(invoice_object, invoice_object)
Expand Down

0 comments on commit ea68d46

Please sign in to comment.