11from typing import List , Optional
22
33from mindee .documents .base import Document
4- from mindee .fields import Field
54from mindee .fields .amount import Amount
5+ from mindee .fields .base import Field , TypedField
66from mindee .fields .date import Date
77from mindee .fields .locale import Locale
88from mindee .fields .orientation import Orientation
@@ -21,10 +21,10 @@ class Invoice(Document):
2121 supplier : Field
2222 supplier_address : Field
2323 customer_name : Field
24- customer_company_registration : Field
24+ customer_company_registration : List [ TypedField ] = []
2525 customer_address : Field
2626 payment_details : List [PaymentDetails ] = []
27- company_number : List [Field ] = []
27+ company_number : List [TypedField ] = []
2828 total_tax : Amount
2929 # orientation is only present on page-level, not document-level
3030 orientation : Optional [Orientation ] = None
@@ -62,8 +62,8 @@ def build_from_api_prediction(self, api_prediction: dict, page_n=0):
6262 self .orientation = Orientation (api_prediction ["orientation" ], page_n = page_n )
6363
6464 self .company_number = [
65- Field ( company_reg , extra_fields = { "type" } , page_n = page_n )
66- for company_reg in api_prediction ["company_registration" ]
65+ TypedField ( field_dict , page_n = page_n )
66+ for field_dict in api_prediction ["company_registration" ]
6767 ]
6868 self .invoice_date = Date (
6969 api_prediction ["date" ], value_key = "value" , page_n = page_n
@@ -78,9 +78,10 @@ def build_from_api_prediction(self, api_prediction: dict, page_n=0):
7878 self .supplier = Field (api_prediction ["supplier" ], page_n = page_n )
7979 self .supplier_address = Field (api_prediction ["supplier_address" ], page_n = page_n )
8080 self .customer_name = Field (api_prediction ["customer" ], page_n = page_n )
81- self .customer_company_registration = Field (
82- api_prediction ["customer_company_registration" ], page_n = page_n
83- )
81+ self .customer_company_registration = [
82+ TypedField (field_dict , page_n = page_n )
83+ for field_dict in api_prediction ["customer_company_registration" ]
84+ ]
8485 self .customer_address = Field (api_prediction ["customer_address" ], page_n = page_n )
8586
8687 self .taxes = [
@@ -103,6 +104,9 @@ def build_from_api_prediction(self, api_prediction: dict, page_n=0):
103104
104105 def __str__ (self ) -> str :
105106 company_numbers = "; " .join ([str (n .value ) for n in self .company_number ])
107+ customer_company_registration = "; " .join (
108+ [str (n .value ) for n in self .customer_company_registration ]
109+ )
106110 payments = ", " .join ([str (p ) for p in self .payment_details ])
107111 taxes = ", " .join (f"{ t } " for t in self .taxes )
108112 return (
@@ -116,7 +120,7 @@ def __str__(self) -> str:
116120 f"Supplier name: { self .supplier } \n "
117121 f"Supplier address: { self .supplier_address } \n "
118122 f"Customer name: { self .customer_name } \n "
119- f"Customer company registration: { self . customer_company_registration } \n "
123+ f"Customer company registration: { customer_company_registration } \n "
120124 f"Customer address: { self .customer_address } \n "
121125 f"Payment details: { payments } \n "
122126 f"Company numbers: { company_numbers } \n "
0 commit comments