more rich reprs

This commit is contained in:
2022-04-23 18:47:25 +02:00
parent 5cc90be8b6
commit fbcc48b5af
2 changed files with 29 additions and 24 deletions

View File

@@ -1,11 +1,8 @@
import typing import typing
import rich.repr
WHAT = "client" WHAT = "client"
@rich.repr.auto
class FreshbooksContact(typing.NamedTuple): class FreshbooksContact(typing.NamedTuple):
contact_id: int contact_id: int
first_name: str first_name: str
@@ -23,9 +20,13 @@ class FreshbooksContact(typing.NamedTuple):
"fname": self.first_name, "fname": self.first_name,
"lname": self.last_name, "lname": self.last_name,
} }
def __rich_repr__(self):
yield "contact_id", self.contact_id
yield "first_name", self.first_name
yield "last_name", self.last_name
yield "email", self.email
@rich.repr.auto
class FreshbooksClient(typing.NamedTuple): class FreshbooksClient(typing.NamedTuple):
client_id: int client_id: int
email: str email: str
@@ -57,6 +58,14 @@ class FreshbooksClient(typing.NamedTuple):
email_contact_id_lookup=email_contact_id_lookup, email_contact_id_lookup=email_contact_id_lookup,
) )
def __rich_repr__(self):
yield "client_id", self.client_id
yield "email", self.email
yield "organization", self.organization
yield "first_name", self.first_name
yield "last_name", self.last_name
yield "contacts", self.contacts
class NoResult(Exception): class NoResult(Exception):
pass pass

View File

@@ -3,8 +3,6 @@ import decimal
import functools import functools
import typing import typing
import rich.repr
WHAT = "invoice" WHAT = "invoice"
@@ -25,7 +23,6 @@ class InvalidField(Exception):
pass pass
@rich.repr.auto
class FreshbooksLine(typing.NamedTuple): class FreshbooksLine(typing.NamedTuple):
invoice_id: int invoice_id: int
client_id: int client_id: int
@@ -58,16 +55,15 @@ class FreshbooksLine(typing.NamedTuple):
"quantity": str(self.quantity), "quantity": str(self.quantity),
} }
# def __rich_repr__(self): def __rich_repr__(self):
# yield "line_id", self.line_id yield "line_id", self.line_id
# yield "description", self.description yield "description", self.description
# yield "amount", self.amount yield "amount", self.amount
# yield "quantity", self.quantity yield "quantity", self.quantity
# yield "rate", self.rate yield "rate", self.rate
# yield "name", self.name yield "name", self.name
@rich.repr.auto
class FreshbooksInvoice(typing.NamedTuple): class FreshbooksInvoice(typing.NamedTuple):
lines: list[FreshbooksLine] lines: list[FreshbooksLine]
notes: str notes: str
@@ -120,15 +116,15 @@ class FreshbooksInvoice(typing.NamedTuple):
status=kwargs["v3_status"], status=kwargs["v3_status"],
) )
# def __rich_repr__(self): def __rich_repr__(self):
# yield "invoice_id", self.invoice_id yield "invoice_id", self.invoice_id
# yield "organization", self.organization yield "invoice_number", self.number
# yield "date", self.date yield "organization", self.organization
# yield "status", self.status yield "date", self.date
# yield "amount", self.amount yield "status", self.status
# yield "lines", self.lines yield "amount", self.amount
# yield "contacts", self.contacts yield "lines", self.lines
# yield "invoice_number", self.number yield "contacts", self.contacts
def get_all_draft_invoices(*, get_func: typing.Callable) -> list[FreshbooksInvoice]: def get_all_draft_invoices(*, get_func: typing.Callable) -> list[FreshbooksInvoice]: