Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/TI-Sin-Problemas/erpnext_mexico_compliance/llms.txt

Use this file to discover all available pages before exploring further.

CFDI Stamping Settings is a singleton DocType (one record per ERPNext site). It controls all aspects of CFDI stamping, including API credentials for the TI Sin Problemas web service, auto-stamp behavior on document submission, credit balance warnings, and optional email notifications with CFDI attachments.
Because this is a singleton, only one record exists per ERPNext site. Navigate to it via ERPNext Mexico Compliance → CFDI Stamping Settings.

Fields reference

Web Service

These fields configure the connection to the TI Sin Problemas CFDI stamping web service. The api_key and api_secret values can be overridden at the site level via site_config.json (using the keys cfdi_api_key, cfdi_api_secret, and cfdi_test_mode). When set in site_config.json, they cannot be changed from the UI.
api_key
Data
API Key for the TI Sin Problemas CFDI web service. Pair this with api_secret to authenticate all stamping requests. When test_mode is enabled, requests are routed to https://cfdi.tisp-staging.com; when disabled, requests go to https://tisinproblemas.com.
api_secret
Password
API Secret for the TI Sin Problemas CFDI web service. Stored encrypted. Combined with api_key to form the HTTP Basic authentication token (api_key:api_secret).
test_mode
Check
default:"1"
Enable test (staging) mode. While enabled, all stamping requests are sent to https://cfdi.tisp-staging.com and do not consume production credits or generate legally valid CFDIs. Disable this field before going live in production.
is_premium
Check (virtual)
default:"0"
Read-only virtual field — its value is computed at runtime by the is_premium Python property and is never stored in the database. When both api_key and api_secret are configured and the account has an active subscription, this property returns True and unlocks the Premium Features section. The subscription check result is cached in Redis for 12 hours via the module-level get_is_premium() function.
enable_low_credits_warning
Check
default:"1"
Show an orange alert banner when the available CFDI credit balance falls below low_credits_threshold. The credit check is performed by calling get_available_credits() against the web service.
low_credits_threshold
Int
default:"50"
Numeric threshold for the low-credits alert. The warning fires when remaining credits are strictly less than this value. Only visible when enable_low_credits_warning is checked.

Stamp Behavior

stamp_on_submit
Check
default:"0"
Automatically stamp eligible documents (Sales Invoice, Payment Entry) when they are submitted in ERPNext. When enabled, the default_csds table becomes mandatory so the system knows which Digital Signing Certificate to use for each company.
default_csds
Table → Default CSD
Maps each company to its active Digital Signing Certificate used for automatic stamping. Each row contains a company (Link → Company) and a csd (Link → Digital Signing Certificate). This table is only visible and required when stamp_on_submit is enabled.
ColumnTypeRequiredDescription
companyLink → CompanyThe ERPNext Company for which this CSD applies
csdLink → Digital Signing CertificateThe active CSD record to use when stamping documents for this company

Premium Features

Fields in this section depend on is_premium evaluating to True. They are visible in the form but have no effect on non-premium accounts.
pdf_templates
Table → CFDI PDF Template
Custom Jinja/HTML PDF templates to use instead of the default layout when generating the CFDI PDF attachment. Each row specifies a company and document_type (e.g., Sales Invoice, Payment Entry). Duplicate combinations of company + document type are rejected on save. Only visible when is_premium is True.
send_email_on_stamp
Check
default:"0"
When enabled, an email carrying the stamped CFDI XML and PDF as attachments is sent automatically after each successful stamp operation. Only visible when is_premium is True.
send_email_to
Select
Determines which contact receives the post-stamp email. Only visible when both send_email_on_stamp and is_premium are set. Valid options:
ValueBehavior
All Billing ContactsSends the email to every contact on the customer record that has the Billing contact type
Document ContactSends the email only to the contact explicitly linked on the Sales Invoice or Payment Entry
This field is mandatory when send_email_on_stamp is enabled.
email_templates
Table → CFDI Email Template
Frappe Email Template to use per document type. Each row links a document_type to an email_template (Link → Email Template). When send_email_on_stamp is enabled and is_premium is True, this table is mandatory. The template is rendered with the full document as context (subject and HTML body).

Permissions

RoleReadWriteCreateDelete
System Manager

Whitelisted methods

The following method is exposed via frappe.call and can be invoked from the browser or through the Frappe REST API.

get_available_credits()

Returns the number of available stamping credits from the TI Sin Problemas subscription endpoint.
settings = frappe.get_single("CFDI Stamping Settings")
credits: int = settings.get_available_credits()
Returns: int — the number of available credits reported by the web service.

Internal methods

The following methods exist on the CFDIStampingSettings document but are not exposed as whitelisted endpoints. They are used internally by the stamping and email pipeline.

check_low_credits()

Fetches the current credit balance via get_available_credits() and displays an orange alert if the balance is below low_credits_threshold. No return value; the alert is shown in-app via frappe.msgprint.
settings = frappe.get_single("CFDI Stamping Settings")
settings.check_low_credits()

can_send_emails(doctype)

Returns True if all conditions for sending a post-stamp email are met for the given document type: the account is premium, send_email_on_stamp is checked, send_email_to is set, and the doctype has a configured entry in email_templates.
settings = frappe.get_single("CFDI Stamping Settings")
if settings.can_send_emails("Sales Invoice"):
    # proceed with email dispatch
    ...
Parameters:
ParameterTypeDescription
doctype"Payment Entry" | "Sales Invoice"The document type to check
Returns: bool

get_email_template(doctype, doc)

Renders the configured Frappe Email Template for the given document type using doc as the Jinja context. Raises StopIteration if no template is configured for the doctype.
settings = frappe.get_single("CFDI Stamping Settings")
result: dict = settings.get_email_template("Sales Invoice", invoice.as_dict())
# result = {"subject": "...", "message": "<html>...</html>"}
Parameters:
ParameterTypeDescription
doctype"Payment Entry" | "Sales Invoice"The document type whose template should be rendered
docdictThe document as a dictionary, used as Jinja template context
Returns: dict with keys subject (str) and message (str HTML).

Site config overrides

API credentials and test mode can be locked to values set by the site administrator in site_config.json. When a site-config value is present, the UI field is overwritten on every before_validate hook and a notice is shown to inform users that only the site admin can change it.
{
  "cfdi_api_key": "your-api-key",
  "cfdi_api_secret": "your-api-secret",
  "cfdi_test_mode": 0
}
Setting cfdi_test_mode to 0 in site_config.json enables production stamping site-wide. Ensure your api_key and api_secret are valid production credentials before making this change.

Build docs developers (and LLMs) love