mx

package
v0.59.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 13 Imported by: 2

README ¶

🇲🇽 GOBL Mexico Tax Regime

Mexico uses the CFDI (Comprobante Fiscal Digital por Internet) format for their e-invoicing system.

Example MX GOBL files can be found in the examples (YAML uncalculated documents) and examples/out (JSON calculated envelopes) subdirectories.

Public Documentation

Zones

In Mexican GOBL documents, the supplier and customer addresses are optional, however the parties’ tax identity zones must be included and contain the fiscal address’ postal code of each party. The supplier’s tax identity zone will map to the LugarExpedicion (Place of issue) CFDI field, and the customer’s one will map to the DomicilioFiscalReceptor (Recipient Fiscal Address) field in the CFDI.

Example

The following example will set 21000 as the LugarExpedicion of the CFDI and 86991 as the DomicilioFiscalReceptor:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",
  // [...]
  "supplier": {
    "name": "ESCUELA KEMPER URGATE",
    "tax_id": {
      "country": "MX",
      "zone": "21000",
      "code": "EKU9003173C9"
    },
    // [...]
  },
  "customer": {
    "name": "UNIVERSIDAD ROBOTICA ESPAÑOLA",
    "tax_id": {
      "country": "MX",
      "zone": "86991",
      "code": "URE180429TM6"
    },
  // [...]
}

Local Codes

Mexican invoices as defined in the CFDI specification must include a set of specific codes that will either need to be known in advance by the supplier or requested from the customer during their purchase process.

The following sections highlight these codes and how they can be defined inside your GOBL documents.

RegimenFiscal - Fiscal Regime

Every Supplier and Customer in a Mexican invoice must be associated with a fiscal regime code. You'll need to ensure this field's value is requested from customers when they require an invoice.

In GOBL the mx-cfdi-fiscal-regime extension key is used alongside the value expected by the SAT.

Example

The following example will associate the supplier with the 601 fiscal regime code:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",
  // [...]
  "supplier": {
    "name": "ESCUELA KEMPER URGATE",
    "tax_id": {
      "country": "MX",
      "zone": "26015",
      "code": "EKU9003173C9"
    },
    "ext": {
      "mx-cfdi-fiscal-regime": "601"
    }
  }
  // [...]
}
UsoCFDI - CFDI Use

The CFDI’s UsoCFDI field specifies how the invoice's recipient will use the invoice to deduce taxes for the expenditure made. In a GOBL Invoice, include the mx-cfdi-use extension in the customer.

This field will be validated for presence and will be checked against the list of codes defined as part of the CFDI specification.

Example

The following GOBL maps to the G03 (Gastos en general) value of the UsoCFDI field:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",

  // [...]

  "customer": {
    "name": "UNIVERSIDAD ROBOTICA ESPAÑOLA",
    "tax_id": {
      "country": "MX",
      "zone": "65000",
      "code": "URE180429TM6"
    },
    "ext": {
      "mx-cfdi-fiscal-regime": "601"
      "mx-cfdi-use": "G01"
    }
  }

  // [...]
}
FormaPago - Payment Means

The CFDI’s FormaPago field specifies an invoice's means of payment. The following table lists all the supported values and how GOBL will map them from the invoice's payment instructions key:

Code Name GOBL Payment Instructions Key
01 Efectivo cash
02 Cheque nominativo cheque
03 Transferencia electrónica de fondos credit-transfer
04 Tarjeta de crédito card
05 Monedero electrónico online+wallet
06 Dinero electrónico online
08 Vales de despensa other+grocery-vouchers
12 Dación en pago other+in-kind
13 Pago por subrogación other+subrogation
14 Pago por consignación other+consignment
15 Condonación other+debt-relief
17 Compensación netting
23 Novación other+novation
24 Confusión other+merger
25 Remisión de deuda other+remission
26 Prescripción o caducidad other+expiration
27 A satisfacción del acreedor other+satisfy-creditor
28 Tarjeta de débito card+debit
29 Tarjeta de servicios card+services
30 Aplicación de anticipos other+advance
31 Intermediario pagos other+intermediary
99 Por definir other
Example

The following GOBL maps to the 05 (Monedero electrónico) value of the FormaPago field:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",

  // [...]

  "payment": {
    "instructions": {
      "key": "online+wallet"
    }
  }
}
ClaveUnidad - Unit Code

The CFDI’s ClaveUnidad field specifies the unit in which the quantity of an invoice's line is given. These are UNECE codes that GOBL will map directly from the invoice's line item unit. See the source code for the full list of supported units with their associated UNECE codes.

Example

The following GOBL maps to the KGM (Kilogram) value of the ClaveUnidad field:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",

  // [...]

  "lines": [
    {
      // [...]

      "item": {
        "name": "Jasmine rice",
        "unit": "kg",
        "price": "1.27"
      },
    }
  ]
}
ClaveProdServ - Product or Service Code

The CFDI’s ClaveProdServ field specifies the type of an invoice's line item. GOBL uses the line item extension key mx-cfdi-prod-serv to map the code directly to the ClaveProdServ field.

The catalogue of available Product or Service codes that form part of the CFDI standard is immense with some 50.000 entries to choose from. Due the huge number of codes GOBL will not validate these fields, you'll have to check with local accountants to check which code should be used for your products or services.

Example

The following GOBL maps to the 10101602 ("live ducks") value to the ClaveProdServ field:

{
  "$schema": "https://gobl.org/draft-0/bill/invoice",

  // [...]

  "lines": [
    {
      // [...]

      "item": {
        "name": "Selección de patos vivos",
        "ext": {
          "mx-cfdi-prod-serv": "10101602"
        }
      },
    }
  ]
}

Documentation ¶

Overview ¶

Package mx provides the Mexican tax regime.

Index ¶

Constants ¶

View Source
const (
	ExtKeyCFDIFiscalRegime = "mx-cfdi-fiscal-regime"
	ExtKeyCFDIUse          = "mx-cfdi-use"
	ExtKeyCFDIProdServ     = "mx-cfdi-prod-serv" // name from XML field: ClaveProdServ
)

Mexican CFDI extension keys required by the SAT (tax authority in Mexico) in all invoices and cannot be determined automatically.

View Source
const (
	KeySATFormaPago         cbc.Key = "sat-forma-pago"          // for mapping to c_FormaPago’s codes
	KeySATTipoDeComprobante cbc.Key = "sat-tipo-de-comprobante" // for mapping to c_TipoDeComprobante’s codes
	KeySATTipoRelacion      cbc.Key = "sat-tipo-relacion"       // for mapping to c_TipoRelacion’s codes
)

Custom keys used typically in meta or codes information.

View Source
const (
	MeansKeyWallet          cbc.Key = "wallet"
	MeansKeyGroceryVouchers cbc.Key = "grocery-vouchers"
	MeansKeyInKind          cbc.Key = "in-kind"
	MeansKeySubrogation     cbc.Key = "subrogation"
	MeansKeyConsignment     cbc.Key = "consignment"
	MeansKeyDebtRelief      cbc.Key = "debt-relief"
	MeansKeyNovation        cbc.Key = "novation"
	MeansKeyMerger          cbc.Key = "merger"
	MeansKeyRemission       cbc.Key = "remission"
	MeansKeyExpiration      cbc.Key = "expiration"
	MeansKeySatisfyCreditor cbc.Key = "satisfy-creditor"
	MeansKeyDebit           cbc.Key = "debit"
	MeansKeyServices        cbc.Key = "services"
	MeansKeyAdvance         cbc.Key = "advance"
	MeansKeyIntermediary    cbc.Key = "intermediary"
)

Regime Specific Payment Means Extension Keys

View Source
const (
	TaxIdentityTypePerson  cbc.Key = "person"
	TaxIdentityTypeCompany cbc.Key = "company"
)

Tax Identity Type

View Source
const (
	TaxIdentityPatternPerson  = `^([A-ZÑ&]{4})([0-9]{6})([A-Z0-9]{3})$`
	TaxIdentityPatternCompany = `^([A-ZÑ&]{3})([0-9]{6})([A-Z0-9]{3})$`
)

Tax Identity Patterns

View Source
const (
	StampProviderSATUUID cbc.Key = "sat-uuid" // a.k.a. Folio Fiscal
)

SAT official codes to include in stamps.

View Source
const (
	TaxIdentityCodeForeign cbc.Code = "XEXX010101000"
)

Constants used to specific tax identity codes.

View Source
const (
	TaxRateExempt cbc.Key = "exempt"
)

Tax rates specific to Mexico.

Variables ¶

View Source
var (
	TaxIdentityRegexpPerson  = regexp.MustCompile(TaxIdentityPatternPerson)
	TaxIdentityRegexpCompany = regexp.MustCompile(TaxIdentityPatternCompany)
)

Tax Identity Regexp

Functions ¶

func Calculate ¶

func Calculate(doc interface{}) error

Calculate performs regime specific calculations.

func DetermineTaxCodeType ¶

func DetermineTaxCodeType(code cbc.Code) cbc.Key

DetermineTaxCodeType determines the type of tax code or provides an empty key if it looks invalid.

func New ¶

func New() *tax.Regime

New provides the tax region definition

func Validate ¶

func Validate(doc interface{}) error

Validate validates a document against the tax regime.

Types ¶

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL