Skip to content

Commit 6a665a7

Browse files
authored
⬆️ update invoices to v4.4 (#214)
* ⬆️ update invoices to v4.4 * ✨ add support for raw_value in string fields
1 parent 24c5498 commit 6a665a7

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

docs/extras/code_samples/invoices_v4.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
1010
# The endpoint name must be specified since it cannot be determined from the class.
1111
result: PredictResponse = mindee_client.parse(product.InvoiceV4, input_doc)
1212

13-
# Print a brief summary of the parsed data
13+
# Print a summary of the API result
1414
print(result.document)
15+
16+
# Print the document-level summary
17+
# print(result.document.inference.prediction)

docs/extras/guide/invoices_v4.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
2020
# The endpoint name must be specified since it cannot be determined from the class.
2121
result: PredictResponse = mindee_client.parse(product.InvoiceV4, input_doc)
2222

23-
# Print a brief summary of the parsed data
23+
# Print a summary of the API result
2424
print(result.document)
25+
26+
# Print the document-level summary
27+
# print(result.document.inference.prediction)
2528
```
2629

2730
**Output (RST):**
@@ -325,5 +328,12 @@ print(result.document.inference.prediction.total_amount.value)
325328
print(result.document.inference.prediction.total_net.value)
326329
```
327330

331+
## Total Tax
332+
**total_tax** ([AmountField](#amountfield)): The total tax: includes all the taxes paid for this invoice.
333+
334+
```py
335+
print(result.document.inference.prediction.total_tax.value)
336+
```
337+
328338
# Questions?
329339
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)

mindee/parsing/standard/text.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class StringField(FieldPositionMixin, BaseField):
88
"""A field containing a text value."""
99

1010
value: Optional[str]
11+
raw_value: Optional[str]
12+
"""The value as it appears on the document."""
1113

1214
def __init__(
1315
self,
@@ -32,3 +34,4 @@ def __init__(
3234
page_id=page_id,
3335
)
3436
self._set_position(raw_prediction)
37+
self.raw_value = raw_prediction.get("raw_value", None)

mindee/product/invoice/invoice_v4_document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class InvoiceV4Document(Prediction):
5151
"""The total amount paid: includes taxes, tips, fees, and other charges."""
5252
total_net: AmountField
5353
"""The net amount paid: does not include taxes, fees, and discounts."""
54+
total_tax: AmountField
55+
"""The total tax: includes all the taxes paid for this invoice."""
5456

5557
def __init__(
5658
self,
@@ -129,6 +131,10 @@ def __init__(
129131
raw_prediction["total_net"],
130132
page_id=page_id,
131133
)
134+
self.total_tax = AmountField(
135+
raw_prediction["total_tax"],
136+
page_id=page_id,
137+
)
132138

133139
@staticmethod
134140
def _line_items_separator(char: str) -> str:
@@ -183,6 +189,7 @@ def __str__(self) -> str:
183189
out_str += f":Due Date: {self.due_date}\n"
184190
out_str += f":Total Net: {self.total_net}\n"
185191
out_str += f":Total Amount: {self.total_amount}\n"
192+
out_str += f":Total Tax: {self.total_tax}\n"
186193
out_str += f":Taxes: {self.taxes}\n"
187194
out_str += f":Supplier Payment Details: {supplier_payment_details}\n"
188195
out_str += f":Supplier Name: {self.supplier_name}\n"

tests/fields/test_text.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from mindee.parsing.standard.text import StringField
2+
3+
4+
def test_constructor_no_raw_value():
5+
field_dict = {
6+
"value": "hello world",
7+
"confidence": 0.1,
8+
"polygon": [
9+
[0.016, 0.707],
10+
[0.414, 0.707],
11+
[0.414, 0.831],
12+
[0.016, 0.831],
13+
],
14+
}
15+
field = StringField(field_dict)
16+
assert field.value == "hello world"
17+
assert field.raw_value is None
18+
19+
20+
def test_constructor_raw_value():
21+
field_dict = {
22+
"value": "hello world",
23+
"raw_value": "HelLO wOrld",
24+
"confidence": 0.1,
25+
"polygon": [
26+
[0.016, 0.707],
27+
[0.414, 0.707],
28+
[0.414, 0.831],
29+
[0.016, 0.831],
30+
],
31+
}
32+
field = StringField(field_dict)
33+
assert field.value == "hello world"
34+
assert field.raw_value == "HelLO wOrld"

tests/product/invoice/test_invoice_v4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_empty_doc(empty_doc: Document[InvoiceV4Document, Page[InvoiceV4Document
6262
assert prediction.due_date.value is None
6363
assert prediction.total_net.value is None
6464
assert prediction.total_amount.value is None
65+
assert prediction.total_tax.value is None
6566
assert len(prediction.taxes) == 0
6667
assert len(prediction.supplier_payment_details) == 0
6768
assert prediction.supplier_name.value is None

0 commit comments

Comments
 (0)