# Understand how the fiscal document gets the CFOP and the taxes

> See the order in which Odoo chooses the fiscal operation, the operation line, the CFOP, the taxes and the messages of each item of the fiscal document.

Fonte: https://docs.kmee.com.br/en/odoo/localizacoes/brasil/tributacao/como-a-nota-recebe-cfop-e-impostos/

See the order in which Odoo chooses the fiscal operation, the operation line, the CFOP, the taxes and the messages of each item of the fiscal document, and know which record to change when a value needs to be different.

## Before you start

Use a user with the Fiscal Manager profile. Keep at hand a draft invoice with a known customer and product: each stage of this guide can be checked in it before posting the fiscal document.

## Step by step

### 1. Start with the three records

The decision starts from three records.

- The **company** provides the origin UF, the tax regime and the ICMS regulation.
- The **customer or supplier** provides the UF, the country, the **ICMS Taxpayer** field, the fiscal profile and the **Final Consumer Operation**.
- The **product** provides the fiscal type, the origin, the NCM and the CEST.

The product fiscal type and origin are stored per company. In a group with several companies, check the Fiscal tab of the product with each company active.

### 2. The fiscal operation comes from the order

The sales order opens with the company default sales operation, and the purchase order with the default purchase operation. The inventory transfer uses the operation of the inventory operation type. In a manual invoice, choose the **Document Type** and then the **Fiscal Operation**.

Only **Approved** operations appear for selection. The operation gives the fiscal document the nature of the operation, which is the operation name itself, the purpose and the journal.

### 3. The operation line is the one that best matches the item

Each operation has lines, such as **Revenda**, **Revenda ST** and **Revenda não Contribuinte**. For each item, Odoo discards the lines whose conditions do not match the fiscal document: the company regime and the partner regime, the partner **ICMS Taxpayer**, the **Product Fiscal Type**, the product tax (ICMS or ISSQN) and the **Origin**. A blank condition matches everything.

Among the remaining lines, the one with more conditions filled in wins. When the operation has a line with ST, the products that the ICMS regulation subjects to tax substitution at that destination go to the line with ST. The chosen line appears in the **Operation Line** column of the invoice item.

### 4. The CFOP comes from the customer UF and country

The chosen line has three CFOPs. A customer in the same UF as the company receives the **Internal CFOP**, a customer in another UF receives the **External CFOP** and a customer in another country receives the **Foreign CFOP**. The customer billing address is what counts.

Example: Guatambu Móveis, in São Paulo, sells a table bought for resale to a taxpayer customer in Porto Alegre. The **Revenda** line wins and the item comes out with CFOP 6102, sale of goods acquired from third parties to another UF. For a taxpayer customer in the city of São Paulo, the same line gives 5102. The CFOP numbering follows the unnumbered Agreement of December 15, 1970, as worded by SINIEF Adjustment 07/2001.

### 5. The taxes come in layers

For each tax, Odoo reads six places in this order, and the last layer that has a rule for that tax wins:

1. the company rules;
2. the product NCM, for IPI, PIS and COFINS;
3. the **ICMS Regulation**, for ICMS, ST and FCP by origin and destination UF;
4. the **Fiscal Definitions** tab of the operation line;
5. the CFOP;
6. the partner fiscal profile.

In Simples Nacional companies, the ICMS comes from the company, the operation line, the CFOP or the profile. At the end, a product taxed by ICMS has no ISSQN, and a service taxed by ISSQN has no ICMS.

### 6. Within the ICMS regulation, the most specific rule wins

In the **ICMS Regulation**, among the approved rules from the company UF to the customer UF, Odoo prefers the benefit rule, then the rule with NCM, CEST or product, and lastly the general rule.

Example: from São Paulo to São Paulo, the general rule is 18%. A product whose NCM is in its own 12% rule comes out with 12%. For Rio Grande do Sul and for Minas Gerais, the interstate rule is 12%, and for Mato Grosso it is 7%, under Resolution 22/1989 of the Federal Senate. An imported product sold to another UF uses the 4% rate of Resolution 13/2012 of the Federal Senate.

### 7. Check the result in the invoice, the XML and the DANFE

In the draft invoice, the **Fiscal Taxes** column of the item shows the chosen taxes, such as ICMS 12%, PIS 0.65% and COFINS 3%. Open the item to see the CFOP, the CST, the base and the amount of each tax.

After confirming, open the XML: the CFOP is in prod/CFOP (CFOP of the item), the ICMS in the ICMS group of the item and the DIFAL in the ICMSUFDest (ICMS for the destination state) group. In the DANFE, the CFOP, the CST and the rates appear in the item columns, and the totals in the **Cálculo do imposto** box. The automatic messages of the operation appear in the **Dados adicionais** box.

## Expected result

You know where each fiscal value of the item came from: the operation, the operation line, the CFOP and each tax, and you know which record to change to change the result.

## If something goes wrong

- The item came out without CFOP and without taxes: check that the product has a **Product Fiscal Type** in the active company and that the customer **ICMS Taxpayer** field matches some line of the operation.

- A CFOP for another UF came out for a local customer: check the UF in the customer billing address.

- A tax came out different from what you expected: look for the rule for that tax from the last layer to the first, starting with the partner fiscal profile.

## Continue the process

- [Configure the fiscal operation, its lines and the CFOP](https://docs.kmee.com.br/en/odoo/enterprise/localizacoes/brasil/tributacao/operacoes-e-cfop/)
- [Prepare a company for Brazilian fiscal operations](https://docs.kmee.com.br/en/odoo/enterprise/localizacoes/brasil/implantacao/)
