Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions mindee/documents/financial/financial_document_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mindee.fields.date import DateField
from mindee.fields.locale import LocaleField
from mindee.fields.payment_details import PaymentDetails
from mindee.fields.tax import TaxField
from mindee.fields.tax import Taxes
from mindee.fields.text import TextField


Expand All @@ -27,7 +27,7 @@ class FinancialDocumentV1(Document):
"""List of Reference numbers including PO number."""
due_date: DateField
"""Date the invoice is due"""
taxes: List[TaxField] = []
taxes: Taxes
"""List of all taxes"""
total_tax: AmountField
"""Sum total of all taxes"""
Expand Down Expand Up @@ -117,11 +117,7 @@ def _build_from_api_prediction(
self.customer_address = TextField(
api_prediction["customer_address"], page_n=page_n
)

self.taxes = [
TaxField(tax_prediction, page_n=page_n, value_key="value")
for tax_prediction in api_prediction["taxes"]
]
self.taxes = Taxes(api_prediction["taxes"], page_id=page_n)
self.supplier_payment_details = [
PaymentDetails(payment_detail, page_n=page_n)
for payment_detail in api_prediction["supplier_payment_details"]
Expand All @@ -143,6 +139,15 @@ def _build_from_api_prediction(
api_prediction["subcategory"], page_n=page_n
)

@staticmethod
def _line_items_separator(char: str):
out_str = " "
out_str += f"+{char * 38}"
out_str += f"+{char * 10}"
out_str += f"+{char * 14}"
out_str += f"+{char * 12}"
return out_str + "+"

def __str__(self) -> str:
supplier_company_registrations = "; ".join(
[str(n.value) for n in self.supplier_company_registrations]
Expand All @@ -154,38 +159,38 @@ def __str__(self) -> str:
payment_details = "\n ".join(
[str(p) for p in self.supplier_payment_details]
)
taxes = "\n ".join(f"{t}" for t in self.taxes)
line_items = "\n"
if self.line_items:
line_items = "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n"
for item in self.line_items:
line_items += f" {item}\n"

return clean_out_string(
"----- Financial Document V1 -----\n"
f"Filename: {self.filename or ''}\n"
f"Document type: {self.document_type}\n"
f"Category: {self.category}\n"
f"Subcategory: {self.subcategory}\n"
f"Locale: {self.locale}\n"
f"Invoice number: {self.invoice_number}\n"
f"Reference numbers: {reference_numbers}\n"
f"Date: {self.date}\n"
f"Due date: {self.due_date}\n"
f"Time: {self.time}\n"
f"Supplier name: {self.supplier_name}\n"
f"Supplier address: {self.supplier_address}\n"
f"Supplier company registrations: {supplier_company_registrations}\n"
f"Supplier payment details: {payment_details}\n"
f"Customer name: {self.customer_name}\n"
f"Customer address: {self.customer_address}\n"
f"Customer company registrations: {customer_company_registrations}\n"
f"Tip: {self.tip}\n"
f"Taxes: {taxes}\n"
f"Total tax: {self.total_tax}\n"
f"Total net: {self.total_net}\n"
f"Total amount: {self.total_amount}\n"
f"Line Items: {line_items}"
"----------------------"
"Financial Document V1 Prediction\n"
"================================\n"
f":Filename: {self.filename or ''}\n"
f":Document type: {self.document_type}\n"
f":Category: {self.category}\n"
f":Subcategory: {self.subcategory}\n"
f":Locale: {self.locale}\n"
f":Invoice number: {self.invoice_number}\n"
f":Reference numbers: {reference_numbers}\n"
f":Date: {self.date}\n"
f":Due date: {self.due_date}\n"
f":Time: {self.time}\n"
f":Supplier name: {self.supplier_name}\n"
f":Supplier address: {self.supplier_address}\n"
f":Supplier company registrations: {supplier_company_registrations}\n"
f":Supplier payment details: {payment_details}\n"
f":Customer name: {self.customer_name}\n"
f":Customer address: {self.customer_address}\n"
f":Customer company registrations: {customer_company_registrations}\n"
f":Tip: {self.tip}\n"
f":Taxes: {self.taxes}\n"
f":Total tax: {self.total_tax}\n"
f":Total net: {self.total_net}\n"
f":Total amount: {self.total_amount}\n"
f":Line Items: {line_items}"
)

def _checklist(self) -> None:
Expand Down
47 changes: 21 additions & 26 deletions mindee/documents/invoice/invoice_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mindee.fields.date import DateField
from mindee.fields.locale import LocaleField
from mindee.fields.payment_details import PaymentDetails
from mindee.fields.tax import TaxField
from mindee.fields.tax import Taxes
from mindee.fields.text import TextField


Expand All @@ -27,7 +27,7 @@ class InvoiceV3(Document):
"""Invoice number"""
due_date: DateField
"""Date the invoice is due"""
taxes: List[TaxField] = []
taxes: Taxes
"""List of all taxes"""
total_tax: AmountField
"""Sum total of all taxes"""
Expand Down Expand Up @@ -103,11 +103,7 @@ def _build_from_api_prediction(
self.customer_address = TextField(
api_prediction["customer_address"], page_n=page_n
)

self.taxes = [
TaxField(tax_prediction, page_n=page_n, value_key="value")
for tax_prediction in api_prediction["taxes"]
]
self.taxes = Taxes(api_prediction["taxes"], page_id=page_n)
self.payment_details = [
PaymentDetails(payment_detail, page_n=page_n)
for payment_detail in api_prediction["payment_details"]
Expand Down Expand Up @@ -142,27 +138,26 @@ def __str__(self) -> str:
payment_details = "\n ".join(
[str(p) for p in self.payment_details]
)
taxes = "\n ".join(f"{t}" for t in self.taxes)

return clean_out_string(
"----- Invoice V3 -----\n"
f"Filename: {self.filename or ''}\n"
f"Invoice number: {self.invoice_number}\n"
f"Total amount including taxes: {self.total_amount}\n"
f"Total amount excluding taxes: {self.total_net}\n"
f"Invoice date: {self.invoice_date}\n"
f"Invoice due date: {self.due_date}\n"
f"Supplier name: {self.supplier}\n"
f"Supplier address: {self.supplier_address}\n"
f"Customer name: {self.customer_name}\n"
f"Customer company registration: {customer_company_registration}\n"
f"Customer address: {self.customer_address}\n"
f"Payment details: {payment_details}\n"
f"Company numbers: {company_numbers}\n"
f"Taxes: {taxes}\n"
f"Total taxes: {self.total_tax}\n"
f"Locale: {self.locale}\n"
"----------------------"
"Invoice V3 Prediction\n"
"=====================\n"
f":Filename: {self.filename or ''}\n"
f":Invoice number: {self.invoice_number}\n"
f":Total amount: {self.total_amount}\n"
f":Total net: {self.total_net}\n"
f":Invoice date: {self.invoice_date}\n"
f":Invoice due date: {self.due_date}\n"
f":Supplier name: {self.supplier}\n"
f":Supplier address: {self.supplier_address}\n"
f":Customer name: {self.customer_name}\n"
f":Customer company registration: {customer_company_registration}\n"
f":Customer address: {self.customer_address}\n"
f":Payment details: {payment_details}\n"
f":Company numbers: {company_numbers}\n"
f":Taxes: {self.taxes}\n"
f":Total tax: {self.total_tax}\n"
f":Locale: {self.locale}"
)

def _reconstruct(self) -> None:
Expand Down
50 changes: 23 additions & 27 deletions mindee/documents/invoice/invoice_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mindee.fields.date import DateField
from mindee.fields.locale import LocaleField
from mindee.fields.payment_details import PaymentDetails
from mindee.fields.tax import TaxField
from mindee.fields.tax import Taxes
from mindee.fields.text import TextField


Expand All @@ -30,7 +30,7 @@ class InvoiceV4(Document):
"""List of Reference numbers including PO number."""
due_date: DateField
"""Date the invoice is due"""
taxes: List[TaxField] = []
taxes: Taxes
"""List of all taxes"""
total_tax: AmountField
"""Sum total of all taxes"""
Expand Down Expand Up @@ -113,10 +113,7 @@ def _build_from_api_prediction(
api_prediction["customer_address"], page_n=page_n
)

self.taxes = [
TaxField(tax_prediction, page_n=page_n, value_key="value")
for tax_prediction in api_prediction["taxes"]
]
self.taxes = Taxes(api_prediction["taxes"], page_id=page_n)
self.supplier_payment_details = [
PaymentDetails(payment_detail, page_n=page_n)
for payment_detail in api_prediction["supplier_payment_details"]
Expand All @@ -140,34 +137,33 @@ def __str__(self) -> str:
payment_details = "\n ".join(
[str(p) for p in self.supplier_payment_details]
)
taxes = "\n ".join(f"{t}" for t in self.taxes)
line_items = "\n"
if self.line_items:
line_items = "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n"
for item in self.line_items:
line_items += f" {item}\n"

return clean_out_string(
"----- Invoice V4 -----\n"
f"Filename: {self.filename or ''}\n"
f"Locale: {self.locale}\n"
f"Invoice number: {self.invoice_number}\n"
f"Reference numbers: {reference_numbers}\n"
f"Invoice date: {self.invoice_date}\n"
f"Invoice due date: {self.due_date}\n"
f"Supplier name: {self.supplier_name}\n"
f"Supplier address: {self.supplier_address}\n"
f"Supplier company registrations: {supplier_company_registrations}\n"
f"Supplier payment details: {payment_details}\n"
f"Customer name: {self.customer_name}\n"
f"Customer company registrations: {customer_company_registrations}\n"
f"Customer address: {self.customer_address}\n"
f"Line Items: {line_items}"
f"Taxes: {taxes}\n"
f"Total taxes: {self.total_tax}\n"
f"Total amount excluding taxes: {self.total_net}\n"
f"Total amount including taxes: {self.total_amount}\n"
"----------------------"
"Invoice V4 Prediction\n"
"=====================\n"
f":Filename: {self.filename or ''}\n"
f":Locale: {self.locale}\n"
f":Invoice number: {self.invoice_number}\n"
f":Reference numbers: {reference_numbers}\n"
f":Invoice date: {self.invoice_date}\n"
f":Invoice due date: {self.due_date}\n"
f":Supplier name: {self.supplier_name}\n"
f":Supplier address: {self.supplier_address}\n"
f":Supplier company registrations: {supplier_company_registrations}\n"
f":Supplier payment details: {payment_details}\n"
f":Customer name: {self.customer_name}\n"
f":Customer company registrations: {customer_company_registrations}\n"
f":Customer address: {self.customer_address}\n"
f":Line Items: {line_items}"
f":Taxes: {self.taxes}\n"
f":Total tax: {self.total_tax}\n"
f":Total net: {self.total_net}\n"
f":Total amount: {self.total_amount}"
)

def _reconstruct(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions mindee/documents/receipt/line_item_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def __str__(self) -> str:
if len(description) > 32:
description = description[:32] + "..."
row = [
description,
float_to_string(self.quantity),
float_to_string(self.unit_price),
float_to_string(self.total_amount),
description,
float_to_string(self.unit_price),
]
return "| {:<8} | {:<8} | {:<9} | {:<34} |".format(*row)
return "| {:<36} | {:<8} | {:<12} | {:<10} |".format(*row)
42 changes: 16 additions & 26 deletions mindee/documents/receipt/receipt_v3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List, Optional, TypeVar
from typing import Optional, TypeVar

from mindee.documents.base import Document, TypeApiPrediction, clean_out_string
from mindee.fields.amount import AmountField
from mindee.fields.base import field_array_confidence, field_array_sum
from mindee.fields.classification import ClassificationField
from mindee.fields.date import DateField
from mindee.fields.locale import LocaleField
from mindee.fields.tax import TaxField
from mindee.fields.tax import Taxes
from mindee.fields.text import TextField


Expand All @@ -23,7 +23,7 @@ class ReceiptV3(Document):
"""Service category"""
merchant_name: TextField
"""Merchant's name"""
taxes: List[TaxField]
taxes: Taxes
"""List of all taxes"""
total_tax: AmountField
"""Sum total of all taxes"""
Expand Down Expand Up @@ -54,20 +54,19 @@ def __init__(
self._reconstruct()

def __str__(self) -> str:
taxes = "\n ".join(f"{t}" for t in self.taxes)
return clean_out_string(
"-----Receipt data-----\n"
f"Filename: {self.filename or ''}\n"
f"Total amount including taxes: {self.total_incl}\n"
f"Total amount excluding taxes: {self.total_excl}\n"
f"Date: {self.date}\n"
f"Category: {self.category}\n"
f"Time: {self.time}\n"
f"Merchant name: {self.merchant_name}\n"
f"Taxes: {taxes}\n"
f"Total taxes: {self.total_tax}\n"
f"Locale: {self.locale}\n"
"----------------------"
"Receipt V3 Prediction\n"
"=====================\n"
f":Filename: {self.filename or ''}\n"
f":Total amount: {self.total_incl}\n"
f":Total net: {self.total_excl}\n"
f":Date: {self.date}\n"
f":Category: {self.category}\n"
f":Time: {self.time}\n"
f":Merchant name: {self.merchant_name}\n"
f":Taxes: {self.taxes}\n"
f":Total tax: {self.total_tax}\n"
f":Locale: {self.locale}"
)

def _build_from_api_prediction(
Expand All @@ -87,16 +86,7 @@ def _build_from_api_prediction(
api_prediction["supplier"], value_key="value", page_n=page_n
)
self.time = TextField(api_prediction["time"], value_key="value", page_n=page_n)
self.taxes = [
TaxField(
tax_prediction,
page_n=page_n,
value_key="value",
rate_key="rate",
code_key="code",
)
for tax_prediction in api_prediction["taxes"]
]
self.taxes = Taxes(api_prediction["taxes"], page_id=page_n)
self.total_tax = AmountField({"value": None, "confidence": 0.0}, page_n=page_n)
self.total_excl = AmountField({"value": None, "confidence": 0.0}, page_n=page_n)

Expand Down
Loading