The invoice module

class magento.models.invoice.Invoice(data, client)View on GitHub
View Source Code
class Invoice(Model): """Wrapper for the ``invoices`` endpoint""" DOCUMENTATION = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/invoices' IDENTIFIER = 'entity_id'
def __init__(self, data: dict, client: Client): """Initialize an Invoice object using an API response from the ``invoices`` endpoint :param data: API response from the ``invoices`` endpoint :param client: an initialized :class:`~.Client` object """ super().__init__( data=data, client=client, endpoint='invoices', private_keys=True )
def __repr__(self): return f'<Magento Invoice: #{self.number}> for {self.order}' @property def excluded_keys(self) -> List[str]: return ['items'] @property def id(self) -> int: """Alias for ``entity_id``""" return getattr(self, 'entity_id', None) @property def number(self) -> str: """Alias for ``increment_id``""" return getattr(self, 'increment_id', None) @cached_property def order(self) -> Order: """The corresponding :class:`~.Order`""" return self.client.orders.by_id(self.order_id) @cached_property def customer(self) -> Customer: """The corresponding :class:`~.Customer`""" return self.client.customers.by_invoice(self) @cached_property def items(self) -> List[InvoiceItem]: """The invoiced items, returned as a list of :class:`InvoiceItem` objects""" return [InvoiceItem(item, self) for item in self.__items if item['order_item_id'] in self.order.item_ids]

Bases: Model

Wrapper for the invoices endpoint

DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/invoices'

Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model

IDENTIFIER: str = 'entity_id'

The API response field that the endpoint’s uid comes from

__init__(data, client)View on GitHub
View Source Code
def __init__(self, data: dict, client: Client): """Initialize an Invoice object using an API response from the ``invoices`` endpoint :param data: API response from the ``invoices`` endpoint :param client: an initialized :class:`~.Client` object """ super().__init__( data=data, client=client, endpoint='invoices', private_keys=True )

Initialize an Invoice object using an API response from the invoices endpoint

Parameters
  • data (dict) – API response from the invoices endpoint

  • client (Client) – an initialized Client object

property excluded_keys: List[str]

API response keys that shouldn’t be set as object attributes by set_attrs()

Returns

list of API response keys that shouldn’t be set as attributes

property id: int

Alias for entity_id

property number: str

Alias for increment_id

property order: Order

The corresponding Order

property customer: Customer

The corresponding Customer

property items: List[InvoiceItem]

The invoiced items, returned as a list of InvoiceItem objects

class magento.models.invoice.InvoiceItem(item, invoice)View on GitHub
View Source Code
class InvoiceItem(Model): """Wraps an item entry of an :class:`Invoice`""" DOCUMENTATION = "https://adobe-commerce.redoc.ly/2.3.7-admin/tag/invoicesid" IDENTIFIER = 'entity_id'
def __init__(self, item: dict, invoice: Invoice): """Initialize an InvoiceItem of an :class:`Invoice` :param item: API response to use as source data :param invoice: the :class:`Invoice` that this is an item of """ super().__init__( data=item, client=invoice.client, endpoint=f'invoices/{invoice.id}' ) self.invoice = invoice
def __repr__(self): return f"<InvoiceItem ({self.sku})> from {self.invoice}"
def data_endpoint(self, scope: Optional[str] = None) -> None: """No data endpoint exists for invoice items""" return self.logger.info("There is no API endpoint for individual invoice items")
def query_endpoint(self) -> None: """No search endpoint exists for invoice items""" return self.logger.info("There is no API endpoint for querying invoice items")
@property def excluded_keys(self) -> List[str]: return ['product_id'] @property def order(self) -> Order: """The :class:`~.Order` this item is from""" return self.invoice.order @cached_property def order_item(self) -> OrderItem: """The item's corresponding :class:`~.OrderItem`""" for item in self.order.items: if item.item_id == self.order_item_id: return item @property def product(self) -> Product: """The item's corresponding simple :class:`~.Product`""" return self.order_item.product @property def product_id(self) -> int: """Id of the corresponding simple :class:`~.Product`""" return self.order_item.product_id

Bases: Model

Wraps an item entry of an Invoice

DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/invoicesid'

Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model

IDENTIFIER: str = 'entity_id'

The API response field that the endpoint’s uid comes from

__init__(item, invoice)View on GitHub
View Source Code
def __init__(self, item: dict, invoice: Invoice): """Initialize an InvoiceItem of an :class:`Invoice` :param item: API response to use as source data :param invoice: the :class:`Invoice` that this is an item of """ super().__init__( data=item, client=invoice.client, endpoint=f'invoices/{invoice.id}' ) self.invoice = invoice

Initialize an InvoiceItem of an Invoice

Parameters
  • item (dict) – API response to use as source data

  • invoice (Invoice) – the Invoice that this is an item of

data_endpoint(scope=None)View on GitHub
View Source Code
def data_endpoint(self, scope: Optional[str] = None) -> None: """No data endpoint exists for invoice items""" return self.logger.info("There is no API endpoint for individual invoice items")

No data endpoint exists for invoice items

query_endpoint()View on GitHub
View Source Code
def query_endpoint(self) -> None: """No search endpoint exists for invoice items""" return self.logger.info("There is no API endpoint for querying invoice items")

No search endpoint exists for invoice items

property excluded_keys: List[str]

API response keys that shouldn’t be set as object attributes by set_attrs()

Returns

list of API response keys that shouldn’t be set as attributes

property order: Order

The Order this item is from

property order_item: OrderItem

The item’s corresponding OrderItem

property product: Product

The item’s corresponding simple Product

property product_id: int

Id of the corresponding simple Product