Skip to content

Commit

Permalink
unify syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianMindee committed Oct 16, 2023
1 parent 54c6566 commit 62979b2
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
55 changes: 26 additions & 29 deletions mindee/product/invoice/invoice_v4_line_item.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
37 changes: 17 additions & 20 deletions mindee/product/receipt/receipt_v5_line_item.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 62979b2

Please sign in to comment.