|
| 1 | +from typing import Optional, TypeVar |
| 2 | + |
| 3 | +from mindee.documents.base import Document, TypeApiPrediction, clean_out_string |
| 4 | +from mindee.fields.text import TextField |
| 5 | + |
| 6 | +from .bank_account_details_v2_bban import BankAccountDetailsV2Bban |
| 7 | + |
| 8 | + |
| 9 | +class BankAccountDetailsV2(Document): |
| 10 | + """Bank Account Details v2 prediction results.""" |
| 11 | + |
| 12 | + account_holders_names: TextField |
| 13 | + """Full extraction of the account holders names.""" |
| 14 | + bban: BankAccountDetailsV2Bban |
| 15 | + """Full extraction of BBAN, including: branch code, bank code, account and key.""" |
| 16 | + iban: TextField |
| 17 | + """Full extraction of the IBAN number.""" |
| 18 | + swift_code: TextField |
| 19 | + """Full extraction of the SWIFT code.""" |
| 20 | + |
| 21 | + def __init__( |
| 22 | + self, |
| 23 | + api_prediction=None, |
| 24 | + input_source=None, |
| 25 | + page_n: Optional[int] = None, |
| 26 | + ): |
| 27 | + """ |
| 28 | + Bank Account Details v2 prediction results. |
| 29 | +
|
| 30 | + :param api_prediction: Raw prediction from HTTP response |
| 31 | + :param input_source: Input object |
| 32 | + :param page_n: Page number for multi pages pdf input |
| 33 | + """ |
| 34 | + super().__init__( |
| 35 | + input_source=input_source, |
| 36 | + document_type="bank_account_details", |
| 37 | + api_prediction=api_prediction, |
| 38 | + page_n=page_n, |
| 39 | + ) |
| 40 | + self._build_from_api_prediction(api_prediction["prediction"], page_n=page_n) |
| 41 | + |
| 42 | + def _build_from_api_prediction( |
| 43 | + self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None |
| 44 | + ) -> None: |
| 45 | + """ |
| 46 | + Build the object from the prediction API JSON. |
| 47 | +
|
| 48 | + :param api_prediction: Raw prediction from HTTP response |
| 49 | + :param page_n: Page number |
| 50 | + """ |
| 51 | + self.account_holders_names = TextField( |
| 52 | + api_prediction["account_holders_names"], |
| 53 | + page_id=page_n, |
| 54 | + ) |
| 55 | + self.bban = BankAccountDetailsV2Bban( |
| 56 | + api_prediction["bban"], |
| 57 | + page_id=page_n, |
| 58 | + ) |
| 59 | + self.iban = TextField( |
| 60 | + api_prediction["iban"], |
| 61 | + page_id=page_n, |
| 62 | + ) |
| 63 | + self.swift_code = TextField( |
| 64 | + api_prediction["swift_code"], |
| 65 | + page_id=page_n, |
| 66 | + ) |
| 67 | + |
| 68 | + def __str__(self) -> str: |
| 69 | + return clean_out_string( |
| 70 | + "FR Bank Account Details V2 Prediction\n" |
| 71 | + "=====================================\n" |
| 72 | + f":Filename: {self.filename or ''}\n" |
| 73 | + f":Account Holder's Names: {self.account_holders_names}\n" |
| 74 | + f":Basic Bank Account Number:\n{self.bban.to_field_list()}\n" |
| 75 | + f":IBAN: {self.iban}\n" |
| 76 | + f":SWIFT Code: {self.swift_code}\n" |
| 77 | + ) |
| 78 | + |
| 79 | + |
| 80 | +TypeBankAccountDetailsV2 = TypeVar( |
| 81 | + "TypeBankAccountDetailsV2", bound=BankAccountDetailsV2 |
| 82 | +) |
0 commit comments