From 511b56ab60a6abab9f2bd0134b53cffe98b5962c Mon Sep 17 00:00:00 2001 From: jonathanMindee Date: Fri, 19 Feb 2021 16:03:59 +0100 Subject: [PATCH 1/5] fix: :bug: fixed bug on financial_document tax rate and version --- mindee/documents/financial_document.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mindee/documents/financial_document.py b/mindee/documents/financial_document.py index 56d1d3fd..855cbd0a 100644 --- a/mindee/documents/financial_document.py +++ b/mindee/documents/financial_document.py @@ -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") @@ -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: From c00f895293f000b05786cf1649fa8ec208ff966d Mon Sep 17 00:00:00 2001 From: jonathanMindee Date: Fri, 19 Feb 2021 16:04:41 +0100 Subject: [PATCH 2/5] chg: :white_check_mark: Added tests for financial document last bug on tax rate --- tests/documents/test_financial_doc.py | 8 ++++++++ tests/documents/test_invoice.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/documents/test_financial_doc.py b/tests/documents/test_financial_doc.py index 2025b7f1..fa6798d7 100644 --- a/tests/documents/test_financial_doc.py +++ b/tests/documents/test_financial_doc.py @@ -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) diff --git a/tests/documents/test_invoice.py b/tests/documents/test_invoice.py index cbb5dd21..74de56a9 100644 --- a/tests/documents/test_invoice.py +++ b/tests/documents/test_invoice.py @@ -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) From 43e9a8300b94c43b5de0fafddb1fcdb296e16ab2 Mon Sep 17 00:00:00 2001 From: jonathanMindee Date: Fri, 19 Feb 2021 16:05:11 +0100 Subject: [PATCH 3/5] chg: :heavy_plus_sign: added pytest-cov dev dependency --- requirements.dev.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.dev.txt b/requirements.dev.txt index 21ca8a28..067e675a 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -5,4 +5,5 @@ pytz~=2020.1 setuptools~=49.2.0 matplotlib~=3.1.2 numpy~=1.18.5 -PyMuPDF~=1.18.1 \ No newline at end of file +PyMuPDF~=1.18.1 +pytest-cov~=2.11.1 \ No newline at end of file From 36d347705d1e0db8286d8f70e138311688ea1360 Mon Sep 17 00:00:00 2001 From: jonathanMindee Date: Fri, 19 Feb 2021 16:06:03 +0100 Subject: [PATCH 4/5] chg: :bookmark: prepare v1.1.2 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8420e52..5deb8f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 1ec03b66b950efe70223a569fe811627f654990f Mon Sep 17 00:00:00 2001 From: jonathanMindee Date: Fri, 19 Feb 2021 16:07:27 +0100 Subject: [PATCH 5/5] chg: :mag: :memo: changed README title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1adfd69..8a96d06d 100644 --- a/README.md +++ b/README.md @@ -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)