Skip to content

Invoices

Invoice resource, it includes the class Resource, a request class to create the resource and a class to represent an Invoice Item.

Classes

facturapi.resources.invoices.Invoice dataclass

Invoice resource

Resource for an Invoice. It inherits from Creatable, Deletable, Downloadable, Queryable and Retrievable.

Attributes:

Name Type Description
created_at datetime.datetime

The datetime in which the resource was created.

livemode bool

If the resource was created in test or live mode.

status str

Status of the invoice.

customer_info CustomerBasicInfo

Basic info of the Customer.

customer_uri str

URI representing how to fetch a Customer resource related to the Invoice.

total float

Invoice total.

uuid str

'Folio fiscal' assigned by SAT.

payment_form PaymentForm

Form of payment of the Invoice.

items List[InvoiceItem]

List of items of the Invoice.

currency str

Currency of the invoice in ISO format.

exchange float

Exchange value to Mexican Pesos.

cancellation_status str

If the Invoice was cancelled, the status of the cancellation. Optional.

folio_number int

Folio number. Optional.

series str

Custom series string. Optional. Defaults to None.

related List[str]

UUID of related invoices. Defaults to None.

relation InvoiceRelation

Relation key from the SAT catalogue. Defaults to None.

Attributes

facturapi.resources.invoices.Invoice.customer: Customer property readonly

Fetch and access Customer resource.

This property fetches and maps the customer related to an invoice so it can be accessed through a simple property instead of making a manual retrieve.

Returns:

Type Description
Customer

Customer: Customer related to the invoice.

Methods

facturapi.resources.invoices.Invoice.cancel(invoice_id) classmethod

Cancel an invoice.

Calls a DELETE request on invoice resource.

Parameters:

Name Type Description Default
invoice_id str

The ID of the invoice to cancel.

required

Returns:

Type Description
Invoice

Invoice: The cancelled invoice resource.

Source code in facturapi/resources/invoices.py
@classmethod
def cancel(cls, invoice_id: str) -> 'Invoice':
    """Cancel an invoice.

    Calls a DELETE request on invoice resource.

    Args:
        invoice_id: The ID of the invoice to cancel.

    Returns:
        Invoice: The cancelled invoice resource.

    """
    return cast('Invoice', cls._delete(invoice_id))
facturapi.resources.invoices.Invoice.create(data) classmethod

Create an invoice.

Parameters:

Name Type Description Default
data InvoiceRequest

All the request data to create an invoice.

required

Returns:

Type Description
Invoice

Invoice: The created resource.

Source code in facturapi/resources/invoices.py
@classmethod
def create(cls, data: InvoiceRequest) -> 'Invoice':
    """Create an invoice.

    Args:
        data: All the request data to create an invoice.

    Returns:
        Invoice: The created resource.

    """
    cleaned_data = data.dict(exclude_unset=True, exclude_none=True)
    return cast('Invoice', cls._create(**cleaned_data))

facturapi.resources.invoices.InvoiceItem pydantic-model

Class representing an Item from an Invoice.

Attributes:

Name Type Description
quantity str

Number of items of this type. Defaults to 1.

discount float

Discount on the item price if any. Defaults to 0.

product Union[str, ProductBasicInfo, Dict]

Product ID, info or request to create a resource.

custom_keys List[str]

List of custom product keys. Optional.

complement str

XML code with additional info to add to the invoice. Optional.

parts List[ItemParts]

If the concept includes parts. Optional.

property_tax_account str

'Predial' number. Optional.

facturapi.resources.invoices.InvoiceRequest pydantic-model

This request must be filled to create an Invoice. It contains all information necessary to create this resource.

Attributes:

Name Type Description
customer Union[str, CustomerRequest]

Customer ID or a CustomerRequest to create a new one.

items List[InvoiceItem]

List of items of the invoice.

payment_form PaymentForm

Form of payment.

payment_method PaymentMethod

Method of payment. Defaults to PaymentMethod.contado.

use InvoiceUse

Invoice SAT CFDI use. Defaults to InvoiceUse.adquisicion_mercancias.

folio_number int

Internal folio number. Optional.

series str

Internal series string. Optional.

currency str

Currency of the invoice in ISO format. Defaults to MXN.

exchange float

If a currency is present, the exchange value to Mexican Pesos. Defaults to 1.0.

conditions str

Payment conditions. Optional.

foreign_trade Dict

Info to add a 'Complemento de Comercio Exterior'. Optional.

related List[str]

UUID list of related invoices. Optional.

relation InvoiceRelation

If related invoices are given, their relation key from the SAT catalogue. Optional.

pdf_custom_section str

HTML string code to include content to the invoice's PDF. Optional

addenda str

XML code with Addenda. Optional.

namespaces List[Namespace]

If addenda or an item complement is given, the special namespaces of the XML code. Optional.