Skip to content

Commit c5316f8

Browse files
committed
🎨 harmonize invoice and financial docs line item classes
1 parent c1d2402 commit c5316f8

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

mindee/documents/financial_document/financial_document_v1_line_item.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class FinancialDocumentV1LineItem(FieldPositionMixin, FieldConfidenceMixin):
2626
"""The item total amount."""
2727
unit_price: Optional[float]
2828
"""The item unit price."""
29-
confidence: float = 0.0
30-
"""Confidence score"""
3129
page_n: int
3230
"""The document page on which the information was found."""
3331

mindee/documents/invoice/invoice_v4.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
44
from mindee.documents.invoice import checks, reconstruct
5-
from mindee.documents.invoice.line_item_v4 import InvoiceLineItemV4
5+
from mindee.documents.invoice.invoice_v4_line_item import InvoiceV4LineItem
66
from mindee.fields.amount import AmountField
77
from mindee.fields.classification import ClassificationField
88
from mindee.fields.company_registration import CompanyRegistrationField
@@ -48,7 +48,7 @@ class InvoiceV4(Document):
4848
"""Customer company registration numbers"""
4949
supplier_payment_details: List[PaymentDetails]
5050
"""Payment details"""
51-
line_items: List[InvoiceLineItemV4]
51+
line_items: List[InvoiceV4LineItem]
5252
"""Details of line items"""
5353

5454
def __init__(
@@ -119,7 +119,7 @@ def _build_from_api_prediction(
119119
for payment_detail in api_prediction["supplier_payment_details"]
120120
]
121121
self.line_items = [
122-
InvoiceLineItemV4(prediction=line_item, page_id=page_n)
122+
InvoiceV4LineItem(prediction=line_item, page_id=page_n)
123123
for line_item in api_prediction["line_items"]
124124
]
125125
self.total_amount = AmountField(api_prediction["total_amount"], page_id=page_n)

mindee/documents/invoice/line_item_v4.py renamed to mindee/documents/invoice/invoice_v4_line_item.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import Optional
22

33
from mindee.fields.base import (
4+
FieldConfidenceMixin,
45
FieldPositionMixin,
56
TypePrediction,
67
float_to_string,
78
to_opt_float,
89
)
910

1011

11-
class InvoiceLineItemV4(FieldPositionMixin):
12+
class InvoiceV4LineItem(FieldPositionMixin, FieldConfidenceMixin):
1213
product_code: Optional[str]
1314
"""The product code referring to the item."""
1415
description: Optional[str]
@@ -33,18 +34,14 @@ def __init__(
3334
prediction: TypePrediction,
3435
page_id: Optional[int] = None,
3536
):
37+
self._set_confidence(prediction)
3638
self._set_position(prediction)
3739

3840
if page_id is None:
3941
self.page_n = prediction["page_id"]
4042
else:
4143
self.page_n = page_id
4244

43-
try:
44-
self.confidence = float(prediction["confidence"])
45-
except (KeyError, TypeError):
46-
pass
47-
4845
self.product_code = prediction["product_code"]
4946
self.description = prediction["description"]
5047
self.quantity = to_opt_float(prediction, "quantity")

0 commit comments

Comments
 (0)