ERPNext Mexico Compliance registers one scheduled job that automatically reconciles CFDI cancellation status with the SAT web service. The job is declared inDocumentation 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.
hooks.py under scheduler_events and is managed entirely by the Frappe background worker infrastructure — no manual cron setup is required.
check_cancellation_status (hourly)
| Property | Value |
|---|---|
| Function | erpnext_mexico_compliance.tasks.check_cancellation_status |
| Frequency | Hourly |
| Queue | Default (short) |
Sales Invoice and every Payment Entry whose mx_cfdi_status field equals "Pending Cancellation". For each matching document it calls update_cancellation_status(), which contacts the SAT web service and automatically cancels the document in ERPNext if the SAT confirms the cancellation.
tasks.py
The job processes every site individually. If your Frappe installation serves multiple sites, each site runs its own scheduler — there is no cross-site leakage.
update_cancellation_status logic
update_cancellation_status() is defined on CommonController, the shared base class for both SalesInvoice and PaymentEntry. The sequence is:
Fetch SAT status
Instantiates the configured web service client and calls
ws.get_status(cfdi), passing the parsed CFDI object. The web service returns a CfdiStatus dataclass instance.Handle NOT_CANCELLABLE
If
status.is_cancellable == status.CancellableStatus.NOT_CANCELLABLE, the document is no longer eligible for cancellation. The method sets mx_is_cancellable = 0 and mx_cfdi_status = "Valid", then saves the document. No cancellation takes place.controllers/common.py (excerpt)
self.flags.ignore_links = True is set before _cancel() so that linked documents (e.g. payment reconciliations) do not block the ERPNext cancellation when the SAT has already confirmed the CFDI is cancelled.Manual status check
In addition to the automated hourly job, any user with document write access can trigger an on-demand status check directly from the Sales Invoice or Payment Entry form by clicking the Check Cancellation Status button. This calls the whitelistedcheck_cancellation_status method on the document, which displays the raw SAT response in a popup (CFDI code, document status, cancellability, and cancellation status) before calling update_cancellation_status() if the SAT reports the document as cancelled.
CfdiStatus model
Thews_client.models module defines the CfdiStatus dataclass and its nested enums. These are the canonical status values used throughout the app when interacting with the SAT web service.
ws_client/models.py
code field holds the raw SAT response code returned by the web service. is_cancellable and cancellation_status may be None when the SAT does not return those fields (for example, when a CFDI has never had a cancellation request submitted).
Internal CFDI status values
TheCFDIStatus string enum in controllers/common.py maps to the mx_cfdi_status field stored on the ERPNext document:
| CFDIStatus value | mx_cfdi_status field | Meaning |
|---|---|---|
CFDIStatus.VALID | "Valid" | CFDI is active and valid with the SAT |
CFDIStatus.PENDING_CANCELLATION | "Pending Cancellation" | Cancellation request submitted; awaiting SAT confirmation |
CFDIStatus.CANCELLED | "Cancelled" | SAT has confirmed cancellation; document is cancelled in ERPNext |