From 62979b29c1071f6e2d2afb6cb52097e346fe64d4 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Mon, 16 Oct 2023 15:03:19 +0200 Subject: [PATCH] unify syntax --- .../financial_document_v1_line_item.py | 55 +++++++++---------- .../bank_account_details_v2_bban.py | 36 ++++++------ .../product/invoice/invoice_v4_line_item.py | 55 +++++++++---------- .../product/receipt/receipt_v5_line_item.py | 37 ++++++------- 4 files changed, 86 insertions(+), 97 deletions(-) diff --git a/mindee/product/financial_document/financial_document_v1_line_item.py b/mindee/product/financial_document/financial_document_v1_line_item.py index b659ccd4..9b8d218d 100644 --- a/mindee/product/financial_document/financial_document_v1_line_item.py +++ b/mindee/product/financial_document/financial_document_v1_line_item.py @@ -1,6 +1,6 @@ from typing import Dict, Optional -from mindee.parsing.common import StringDict, format_for_display +from mindee.parsing.common import StringDict, clean_out_string, format_for_display from mindee.parsing.standard import ( FieldConfidenceMixin, FieldPositionMixin, @@ -55,39 +55,36 @@ def __init__( def _printable_values(self) -> Dict[str, str]: """Return values for printing.""" - return { - "description": format_for_display(self.description, 36), - "product_code": format_for_display(self.product_code, None), - "quantity": float_to_string(self.quantity), - "tax_amount": float_to_string(self.tax_amount), - "tax_rate": float_to_string(self.tax_rate), - "total_amount": float_to_string(self.total_amount), - "unit_price": float_to_string(self.unit_price), - } + out_dict: Dict[str, str] = {} + out_dict["description"] = format_for_display(self.description, 36) + out_dict["product_code"] = format_for_display(self.product_code, None) + out_dict["quantity"] = float_to_string(self.quantity) + out_dict["tax_amount"] = float_to_string(self.tax_amount) + out_dict["tax_rate"] = float_to_string(self.tax_rate) + out_dict["total_amount"] = float_to_string(self.total_amount) + out_dict["unit_price"] = float_to_string(self.unit_price) + return out_dict def to_table_line(self) -> str: """Output in a format suitable for inclusion in an rST table.""" printable = self._printable_values() - return ( - "|" - f" {printable['description']:<36} |" - f" {printable['product_code']:<12} |" - f" {printable['quantity']:<8} |" - f" {printable['tax_amount']:<10} |" - f" {printable['tax_rate']:<12} |" - f" {printable['total_amount']:<12} |" - f" {printable['unit_price']:<10} |" - ) + out_str: str = f"| {printable['description']:<36} | " + out_str += f"{printable['product_code']:<12} | " + out_str += f"{printable['quantity']:<8} | " + out_str += f"{printable['tax_amount']:<10} | " + out_str += f"{printable['tax_rate']:<12} | " + out_str += f"{printable['total_amount']:<12} | " + out_str += f"{printable['unit_price']:<10} | " + return clean_out_string(out_str) def __str__(self) -> str: """Default string representation.""" printable = self._printable_values() - return ( - f"Description: {printable['description']}, " - f"Product code: {printable['product_code']}, " - f"Quantity: {printable['quantity']}, " - f"Tax Amount: {printable['tax_amount']}, " - f"Tax Rate (%): {printable['tax_rate']}, " - f"Total Amount: {printable['total_amount']}, " - f"Unit Price: {printable['unit_price']}, " - ).strip() + out_str: str = f"Description: {printable['description']}, \n" + out_str += f"Product code: {printable['product_code']}, \n" + out_str += f"Quantity: {printable['quantity']}, \n" + out_str += f"Tax Amount: {printable['tax_amount']}, \n" + out_str += f"Tax Rate (%): {printable['tax_rate']}, \n" + out_str += f"Total Amount: {printable['total_amount']}, \n" + out_str += f"Unit Price: {printable['unit_price']}, \n" + return clean_out_string(out_str) diff --git a/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.py b/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.py index fec8ee67..25a8543b 100644 --- a/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.py +++ b/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.py @@ -1,6 +1,6 @@ from typing import Dict, Optional -from mindee.parsing.common import StringDict, format_for_display +from mindee.parsing.common import StringDict, clean_out_string, format_for_display from mindee.parsing.standard import FieldConfidenceMixin, FieldPositionMixin @@ -41,29 +41,27 @@ def __init__( def _printable_values(self) -> Dict[str, str]: """Return values for printing.""" - return { - "bban_bank_code": format_for_display(self.bban_bank_code, None), - "bban_branch_code": format_for_display(self.bban_branch_code, None), - "bban_key": format_for_display(self.bban_key, None), - "bban_number": format_for_display(self.bban_number, None), - } + out_dict: Dict[str, str] = {} + out_dict["bban_bank_code"] = format_for_display(self.bban_bank_code, None) + out_dict["bban_branch_code"] = format_for_display(self.bban_branch_code, None) + out_dict["bban_key"] = format_for_display(self.bban_key, None) + out_dict["bban_number"] = format_for_display(self.bban_number, None) + return out_dict def to_field_list(self) -> str: """Output the object in a format suitable for inclusion in an rST field list.""" printable = self._printable_values() - return ( - f" :Bank Code: {printable['bban_bank_code']}\n" - f" :Branch Code: {printable['bban_branch_code']}\n" - f" :Key: {printable['bban_key']}\n" - f" :Account Number: {printable['bban_number']}" - ) + out_str: str = f" :Bank Code: {printable['bban_bank_code']}\n" + out_str += f" :Branch Code: {printable['bban_branch_code']}\n" + out_str += f" :Key: {printable['bban_key']}\n" + out_str += f" :Account Number: {printable['bban_number']}\n" + return out_str.rstrip() def __str__(self) -> str: """Default string representation.""" printable = self._printable_values() - return ( - f"Bank Code: {printable['bban_bank_code']}, " - f"Branch Code: {printable['bban_branch_code']}, " - f"Key: {printable['bban_key']}, " - f"Account Number: {printable['bban_number']}, " - ).strip() + out_str: str = f"Bank Code: {printable['bban_bank_code']}, \n" + out_str += f"Branch Code: {printable['bban_branch_code']}, \n" + out_str += f"Key: {printable['bban_key']}, \n" + out_str += f"Account Number: {printable['bban_number']}, \n" + return clean_out_string(out_str) diff --git a/mindee/product/invoice/invoice_v4_line_item.py b/mindee/product/invoice/invoice_v4_line_item.py index f8e8e678..cb3e89ed 100644 --- a/mindee/product/invoice/invoice_v4_line_item.py +++ b/mindee/product/invoice/invoice_v4_line_item.py @@ -1,6 +1,6 @@ from typing import Dict, Optional -from mindee.parsing.common import StringDict, format_for_display +from mindee.parsing.common import StringDict, clean_out_string, format_for_display from mindee.parsing.standard import ( FieldConfidenceMixin, FieldPositionMixin, @@ -55,39 +55,36 @@ def __init__( def _printable_values(self) -> Dict[str, str]: """Return values for printing.""" - return { - "description": format_for_display(self.description, 36), - "product_code": format_for_display(self.product_code, None), - "quantity": float_to_string(self.quantity), - "tax_amount": float_to_string(self.tax_amount), - "tax_rate": float_to_string(self.tax_rate), - "total_amount": float_to_string(self.total_amount), - "unit_price": float_to_string(self.unit_price), - } + out_dict: Dict[str, str] = {} + out_dict["description"] = format_for_display(self.description, 36) + out_dict["product_code"] = format_for_display(self.product_code, None) + out_dict["quantity"] = float_to_string(self.quantity) + out_dict["tax_amount"] = float_to_string(self.tax_amount) + out_dict["tax_rate"] = float_to_string(self.tax_rate) + out_dict["total_amount"] = float_to_string(self.total_amount) + out_dict["unit_price"] = float_to_string(self.unit_price) + return out_dict def to_table_line(self) -> str: """Output in a format suitable for inclusion in an rST table.""" printable = self._printable_values() - return ( - "|" - f" {printable['description']:<36} |" - f" {printable['product_code']:<12} |" - f" {printable['quantity']:<8} |" - f" {printable['tax_amount']:<10} |" - f" {printable['tax_rate']:<12} |" - f" {printable['total_amount']:<12} |" - f" {printable['unit_price']:<10} |" - ) + out_str: str = f"| {printable['description']:<36} | " + out_str += f"{printable['product_code']:<12} | " + out_str += f"{printable['quantity']:<8} | " + out_str += f"{printable['tax_amount']:<10} | " + out_str += f"{printable['tax_rate']:<12} | " + out_str += f"{printable['total_amount']:<12} | " + out_str += f"{printable['unit_price']:<10} | " + return clean_out_string(out_str) def __str__(self) -> str: """Default string representation.""" printable = self._printable_values() - return ( - f"Description: {printable['description']}, " - f"Product code: {printable['product_code']}, " - f"Quantity: {printable['quantity']}, " - f"Tax Amount: {printable['tax_amount']}, " - f"Tax Rate (%): {printable['tax_rate']}, " - f"Total Amount: {printable['total_amount']}, " - f"Unit Price: {printable['unit_price']}, " - ).strip() + out_str: str = f"Description: {printable['description']}, \n" + out_str += f"Product code: {printable['product_code']}, \n" + out_str += f"Quantity: {printable['quantity']}, \n" + out_str += f"Tax Amount: {printable['tax_amount']}, \n" + out_str += f"Tax Rate (%): {printable['tax_rate']}, \n" + out_str += f"Total Amount: {printable['total_amount']}, \n" + out_str += f"Unit Price: {printable['unit_price']}, \n" + return clean_out_string(out_str) diff --git a/mindee/product/receipt/receipt_v5_line_item.py b/mindee/product/receipt/receipt_v5_line_item.py index 23cdef4f..706fdb70 100644 --- a/mindee/product/receipt/receipt_v5_line_item.py +++ b/mindee/product/receipt/receipt_v5_line_item.py @@ -1,6 +1,6 @@ from typing import Dict, Optional -from mindee.parsing.common import StringDict, format_for_display +from mindee.parsing.common import StringDict, clean_out_string, format_for_display from mindee.parsing.standard import ( FieldConfidenceMixin, FieldPositionMixin, @@ -46,30 +46,27 @@ def __init__( def _printable_values(self) -> Dict[str, str]: """Return values for printing.""" - return { - "description": format_for_display(self.description, 36), - "quantity": float_to_string(self.quantity), - "total_amount": float_to_string(self.total_amount), - "unit_price": float_to_string(self.unit_price), - } + out_dict: Dict[str, str] = {} + out_dict["description"] = format_for_display(self.description, 36) + out_dict["quantity"] = float_to_string(self.quantity) + out_dict["total_amount"] = float_to_string(self.total_amount) + out_dict["unit_price"] = float_to_string(self.unit_price) + return out_dict def to_table_line(self) -> str: """Output in a format suitable for inclusion in an rST table.""" printable = self._printable_values() - return ( - "|" - f" {printable['description']:<36} |" - f" {printable['quantity']:<8} |" - f" {printable['total_amount']:<12} |" - f" {printable['unit_price']:<10} |" - ) + out_str: str = f"| {printable['description']:<36} | " + out_str += f"{printable['quantity']:<8} | " + out_str += f"{printable['total_amount']:<12} | " + out_str += f"{printable['unit_price']:<10} | " + return clean_out_string(out_str) def __str__(self) -> str: """Default string representation.""" printable = self._printable_values() - return ( - f"Description: {printable['description']}, " - f"Quantity: {printable['quantity']}, " - f"Total Amount: {printable['total_amount']}, " - f"Unit Price: {printable['unit_price']}, " - ).strip() + out_str: str = f"Description: {printable['description']}, \n" + out_str += f"Quantity: {printable['quantity']}, \n" + out_str += f"Total Amount: {printable['total_amount']}, \n" + out_str += f"Unit Price: {printable['unit_price']}, \n" + return clean_out_string(out_str)