22
33from mindee .documents .base import Document
44from mindee .fields import Field
5- from mindee .fields .date import Date
65from mindee .fields .amount import Amount
6+ from mindee .fields .date import Date
77from mindee .fields .locale import Locale
88from mindee .fields .orientation import Orientation
99from mindee .fields .payment_details import PaymentDetails
@@ -38,6 +38,8 @@ def __init__(
3838 document_type = "invoice" ,
3939 ):
4040 """
41+ Invoice document.
42+
4143 :param api_prediction: Raw prediction from HTTP response
4244 :param input_file: Input object
4345 :param page_n: Page number for multi pages pdf input
@@ -51,6 +53,8 @@ def __init__(
5153
5254 def build_from_api_prediction (self , api_prediction : dict , page_n = 0 ):
5355 """
56+ Build the object from the prediction API JSON.
57+
5458 :param api_prediction: Raw prediction from HTTP response
5559 :param page_n: Page number for multi pages pdf input
5660 :return: (void) set the object attributes with api prediction values
@@ -126,26 +130,23 @@ def __str__(self) -> str:
126130 @staticmethod
127131 def request (endpoints : List [Endpoint ], input_file , include_words = False ):
128132 """
129- Make request to expense_receipts endpoint
133+ Make request to prediction endpoint.
134+
130135 :param input_file: Input object
131136 :param endpoints: Endpoints config
132137 :param include_words: Include Mindee vision words in http_response
133138 """
134139 return endpoints [0 ].predict_request (input_file , include_words )
135140
136141 def _reconstruct (self ) -> None :
137- """
138- Call fields reconstruction methods
139- """
142+ """Call fields reconstruction methods."""
140143 self .__reconstruct_total_tax_from_tax_lines ()
141144 self .__reconstruct_total_excl_from_tcc_and_taxes ()
142145 self .__reconstruct_total_incl_from_taxes_plus_excl ()
143146 self .__reconstruct_total_tax_from_incl_and_excl ()
144147
145148 def _checklist (self ) -> None :
146- """
147- Call check methods
148- """
149+ """Call check methods."""
149150 self .checklist = {
150151 "taxes_match_total_incl" : self .__taxes_match_total_incl (),
151152 "taxes_match_total_excl" : self .__taxes_match_total_excl (),
@@ -155,7 +156,8 @@ def _checklist(self) -> None:
155156 # Checks
156157 def __taxes_match_total_incl (self ) -> bool :
157158 """
158- Check invoice rule of matching between taxes and total_incl
159+ Check invoice matching rule between taxes and total_incl.
160+
159161 :return: True if rule matches, False otherwise
160162 """
161163 # Ensure taxes and total_incl exist
@@ -191,7 +193,8 @@ def __taxes_match_total_incl(self) -> bool:
191193
192194 def __taxes_match_total_excl (self ) -> bool :
193195 """
194- Check invoice rule of matching between taxes and total_excl
196+ Check invoice matching rule between taxes and total_excl.
197+
195198 :return: True if rule matches, False otherwise
196199 """
197200 # Check taxes and total excl exist
@@ -228,7 +231,9 @@ def __taxes_match_total_excl(self) -> bool:
228231
229232 def __taxes_plus_total_excl_match_total_incl (self ) -> bool :
230233 """
231- Check invoice rule of matching : sum(taxes) + total_excluding_taxes = total_including_taxes
234+ Check invoice matching rule.
235+
236+ Rule is: sum(taxes) + total_excluding_taxes = total_including_taxes
232237 :return: True if rule matches, False otherwise
233238 """
234239 # Check total_tax, total excl and total incl exist
@@ -267,7 +272,8 @@ def __taxes_plus_total_excl_match_total_incl(self) -> bool:
267272 # Reconstruct
268273 def __reconstruct_total_incl_from_taxes_plus_excl (self ) -> None :
269274 """
270- Set self.total_incl with Amount object
275+ Set self.total_incl with Amount object.
276+
271277 The total_incl Amount value is the sum of total_excl and sum of taxes
272278 The total_incl Amount confidence is the product of self.taxes probabilities
273279 multiplied by total_excl confidence
@@ -292,7 +298,8 @@ def __reconstruct_total_incl_from_taxes_plus_excl(self) -> None:
292298
293299 def __reconstruct_total_excl_from_tcc_and_taxes (self ) -> None :
294300 """
295- Set self.total_excl with Amount object
301+ Set self.total_excl with Amount object.
302+
296303 The total_excl Amount value is the difference between total_incl and sum of taxes
297304 The total_excl Amount confidence is the product of self.taxes probabilities
298305 multiplied by total_incl confidence
@@ -317,7 +324,8 @@ def __reconstruct_total_excl_from_tcc_and_taxes(self) -> None:
317324
318325 def __reconstruct_total_tax_from_tax_lines (self ) -> None :
319326 """
320- Set self.total_tax with Amount object
327+ Set self.total_tax with Amount object.
328+
321329 The total_tax Amount value is the sum of all self.taxes value
322330 The total_tax Amount confidence is the product of self.taxes probabilities
323331 """
@@ -335,7 +343,8 @@ def __reconstruct_total_tax_from_tax_lines(self) -> None:
335343
336344 def __reconstruct_total_tax_from_incl_and_excl (self ) -> None :
337345 """
338- Set self.total_tax with Amount object
346+ Set self.total_tax with Amount object.
347+
339348 Check if the total tax was already set
340349 If not, set thta total tax amount to the diff of incl and excl
341350 """
0 commit comments