|
| 1 | +from typing import Optional, TypeVar |
| 2 | + |
| 3 | +from mindee.documents.base import Document, TypeApiPrediction, clean_out_string |
| 4 | +from mindee.fields.position import PositionField |
| 5 | +from mindee.fields.text import TextField |
| 6 | + |
| 7 | + |
| 8 | +class W9V1(Document): |
| 9 | + """US W9 v1 prediction results.""" |
| 10 | + |
| 11 | + address: TextField |
| 12 | + """The street address (number, street, and apt. or suite no.) of the applicant.""" |
| 13 | + business_name: TextField |
| 14 | + """The business name or disregarded entity name, if different from Name.""" |
| 15 | + city_state_zip: TextField |
| 16 | + """The city, state, and ZIP code of the applicant.""" |
| 17 | + ein: TextField |
| 18 | + """The employer identification number.""" |
| 19 | + name: TextField |
| 20 | + """Name as shown on the applicant's income tax return.""" |
| 21 | + signature_date_position: PositionField |
| 22 | + """Position of the signature date on the document.""" |
| 23 | + signature_position: PositionField |
| 24 | + """Position of the signature on the document.""" |
| 25 | + ssn: TextField |
| 26 | + """The applicant's social security number.""" |
| 27 | + tax_classification: TextField |
| 28 | + """The federal tax classification, which can vary depending on the revision date.""" |
| 29 | + tax_classification_llc: TextField |
| 30 | + """Depending on revision year, among S, C, P or D for Limited Liability Company Classification.""" |
| 31 | + tax_classif_other_details: TextField |
| 32 | + """Tax Classification Other Details.""" |
| 33 | + w9_revision_date: TextField |
| 34 | + """The Revision month and year of the W9 form.""" |
| 35 | + |
| 36 | + def __init__( |
| 37 | + self, |
| 38 | + api_prediction=None, |
| 39 | + input_source=None, |
| 40 | + page_n: Optional[int] = None, |
| 41 | + ): |
| 42 | + """ |
| 43 | + US W9 v1 prediction results. |
| 44 | +
|
| 45 | + :param api_prediction: Raw prediction from HTTP response |
| 46 | + :param input_source: Input object |
| 47 | + :param page_n: Page number for multi pages pdf input |
| 48 | + """ |
| 49 | + super().__init__( |
| 50 | + input_source=input_source, |
| 51 | + document_type="w9", |
| 52 | + api_prediction=api_prediction, |
| 53 | + page_n=page_n, |
| 54 | + ) |
| 55 | + self._build_from_api_prediction(api_prediction["prediction"], page_n=page_n) |
| 56 | + |
| 57 | + def _build_from_api_prediction( |
| 58 | + self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None |
| 59 | + ) -> None: |
| 60 | + """ |
| 61 | + Build the object from the prediction API JSON. |
| 62 | +
|
| 63 | + :param api_prediction: Raw prediction from HTTP response |
| 64 | + :param page_n: Page number |
| 65 | + """ |
| 66 | + self.address = TextField( |
| 67 | + api_prediction.get("address", {}), |
| 68 | + page_id=page_n, |
| 69 | + ) |
| 70 | + self.business_name = TextField( |
| 71 | + api_prediction.get("business_name", {}), |
| 72 | + page_id=page_n, |
| 73 | + ) |
| 74 | + self.city_state_zip = TextField( |
| 75 | + api_prediction.get("city_state_zip", {}), |
| 76 | + page_id=page_n, |
| 77 | + ) |
| 78 | + self.ein = TextField( |
| 79 | + api_prediction.get("ein", {}), |
| 80 | + page_id=page_n, |
| 81 | + ) |
| 82 | + self.name = TextField( |
| 83 | + api_prediction.get("name", {}), |
| 84 | + page_id=page_n, |
| 85 | + ) |
| 86 | + self.signature_date_position = PositionField( |
| 87 | + api_prediction.get("signature_date_position", {}), |
| 88 | + page_id=page_n, |
| 89 | + ) |
| 90 | + self.signature_position = PositionField( |
| 91 | + api_prediction.get("signature_position", {}), |
| 92 | + page_id=page_n, |
| 93 | + ) |
| 94 | + self.ssn = TextField( |
| 95 | + api_prediction.get("ssn", {}), |
| 96 | + page_id=page_n, |
| 97 | + ) |
| 98 | + self.tax_classification = TextField( |
| 99 | + api_prediction.get("tax_classification", {}), |
| 100 | + page_id=page_n, |
| 101 | + ) |
| 102 | + self.tax_classification_llc = TextField( |
| 103 | + api_prediction.get("tax_classification_llc", {}), |
| 104 | + page_id=page_n, |
| 105 | + ) |
| 106 | + self.tax_classif_other_details = TextField( |
| 107 | + api_prediction.get("tax_classification_other_details", {}), |
| 108 | + page_id=page_n, |
| 109 | + ) |
| 110 | + self.w9_revision_date = TextField( |
| 111 | + api_prediction.get("w9_revision_date", {}), |
| 112 | + page_id=page_n, |
| 113 | + ) |
| 114 | + |
| 115 | + def __str__(self) -> str: |
| 116 | + return clean_out_string( |
| 117 | + "US W9 V1 Prediction\n" |
| 118 | + "======================\n" |
| 119 | + f":Filename: {self.filename or ''}\n" |
| 120 | + f":Name: {self.name}\n" |
| 121 | + f":SSN: {self.ssn}\n" |
| 122 | + f":Address: {self.address}\n" |
| 123 | + f":City State Zip: {self.city_state_zip}\n" |
| 124 | + f":Business Name: {self.business_name}\n" |
| 125 | + f":EIN: {self.ein}\n" |
| 126 | + f":Tax Classification: {self.tax_classification}\n" |
| 127 | + f":Tax Classification Other Details: {self.tax_classif_other_details}\n" |
| 128 | + f":W9 Revision Date: {self.w9_revision_date}\n" |
| 129 | + f":Signature Position: {self.signature_position}\n" |
| 130 | + f":Signature Date Position: {self.signature_date_position}\n" |
| 131 | + f":Tax Classification LLC: {self.tax_classification_llc}\n" |
| 132 | + ) |
| 133 | + |
| 134 | + |
| 135 | +TypeW9V1 = TypeVar( |
| 136 | + "TypeW9V1", |
| 137 | + bound=W9V1, |
| 138 | +) |
0 commit comments