Skip to content

[16.0][ADD] l10n_br_fiscal, l10n_br_stock_account: custo líquido de aquisição pela creditabilidade do CST#4744

Open
mileo wants to merge 2 commits into
OCA:16.0from
kmee:16.0-add-l10n_br_fiscal-net-cost-core
Open

[16.0][ADD] l10n_br_fiscal, l10n_br_stock_account: custo líquido de aquisição pela creditabilidade do CST#4744
mileo wants to merge 2 commits into
OCA:16.0from
kmee:16.0-add-l10n_br_fiscal-net-cost-core

Conversation

@mileo

@mileo mileo commented Jul 20, 2026

Copy link
Copy Markdown
Member

O que

Custo líquido de aquisição de estoque para o Brasil (Art. 301 RIR/2018, CPC 16): o
custo das mercadorias compradas deve excluir os impostos recuperáveis (ICMS, IPI,
PIS/COFINS quando creditáveis) e manter no custo os não recuperáveis (ICMS-ST, FCP-ST,
II, despesas aduaneiras, frete, seguro). Hoje o valor que chega na valorização de
estoque é o preço cheio da NF, o que superavalia estoque e CMV e faz dupla contagem do
crédito fiscal.

Este PR consolida duas propostas anteriores de mantenedores para exatamente este
problema, portando-as para a 16.0 e unindo cada uma onde é mais forte:

Substitui a abordagem de resolver/product_destination do #4730 (mesmo autor), que é
fechado em favor deste.

Como

  • Booleano default_creditable_tax no l10n_br_fiscal.cst, definido por CST no
    arquivo de dados: se aquele CST permite crédito na entrada por natureza. Defaults
    auditados contra a legislação (LC 87/96, RIPI e jurisprudência do STF para o IPI,
    Leis 10.637/10.833 para PIS/COFINS, LC 123/2006 para Simples/CSOSN).
  • Novo mixin abstrato l10n_br_fiscal.stock.price.mixin com o campo calculado
    cost_unit (total da linha líquido dos impostos creditáveis) e os booleanos de
    creditabilidade por linha.
  • Os booleanos icms/ipi/pis/cofins_tax_is_creditable são calculados (store=True,
    readonly=False): o valor deriva do default_creditable_tax do CST da linha E do
    gate do regime tributário da empresa compradora (Simples não credita nada; IPI só
    indústria/equiparado; PIS/COFINS só no regime não cumulativo, Lucro Real). Por serem
    calculados, os fluxos programáticos (movimentos gerados por pedido de compra,
    documentos importados) recebem a creditabilidade correta sem onchange; por serem
    readonly=False, o usuário fiscal ainda pode sobrepor uma linha (o mesmo produto pode
    ser comprado com destinações diferentes).
  • O stock.move de entrada passa a ser valorizado pelo cost_unit. Isto é opt-in
    por empresa (stock_valuation_via_stock_price, padrão False), de modo que bases
    existentes mantêm o comportamento atual até optarem por ligar.

Valores testados

NF de referência: preço 800,00 + IPI 26,00 = total fiscal 826,00, ICMS 96,00.

Regime do comprador cost_unit
Lucro Real (indústria, credita ICMS+IPI+PIS+COFINS) 630,00
Lucro Presumido (indústria, credita ICMS+IPI) 704,00
Simples Nacional (sem crédito) 800,00

7 testes em TestCostUnit; suíte completa do l10n_br_stock_account verde.

Créditos

Design e código original de @DiegoParadeda (#3158) e @renatonlima (#3819). Os próximos
passos (recomputo da valorização de estoque, UI de decisão de compra, conciliação
contábil anglo-saxã, landed costs, transferências, importação de NF-e) constroem sobre
esta fundação.

…ST and stock price mixin

Port of the design from OCA#3158 to 16.0:

* l10n_br_fiscal.cst gets a default_creditable_tax boolean, defined per CST
  in the data file, stating whether that CST allows an input tax credit by
  its nature.
* New abstract mixin l10n_br_fiscal.stock.price.mixin with per-line
  creditable flags (icms/ipi/pis/cofins/icmsst/issqn/irpj), freight,
  insurance and other cost toggles, and a stock_price_br computed field:
  the line total net of creditable taxes (net acquisition cost,
  art. 301 RIR/2018 and CPC 16).
* stock.move inherits the mixin and incoming moves are valued at the net
  cost instead of the purchase price.
* Company flag stock_valuation_via_stock_price to enable the behavior.

Adaptations from the original 14.0 branch: amount_total was renamed to
fiscal_amount_total in 16.0; duplicated field label fixed; CSTs added
after 14.0 (IBS/CBS/IS and single-phase fuel ICMS) default to False.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @mbcosta, @rvalyi, @renatonlima,
some modules you are maintaining are being modified, check this out!

… from CST and company tax regime

Builds on the previous commit (design from OCA#3158 by Diego Paradeda) and on
the principle of OCA#3819 by Renato
Lima: the net cost must be derived together with the fiscal computation,
never depending on UI interaction.

* The per-line creditable flags (icms/ipi/pis/cofins) become computed
  fields (store=True, readonly=False) instead of onchange-driven: the
  value derives from the line CST default_creditable_tax AND the buyer
  company tax regime gate:
  - Simples Nacional buyer takes no credit (LC 123/2006, art. 23);
  - IPI only credits industries and assimilated (RIPI);
  - PIS/COFINS only credit in the non-cumulative regime (Lucro Real,
    Leis 10.637/2002 and 10.833/2003).
  Programmatic flows (purchase orders creating moves, imported fiscal
  documents) now get the right creditability with no UI interaction,
  while the flags remain editable line by line (the same product may be
  bought with different destinations).
* icmsst/issqn/irpj flags become manual-only (default False): there is
  no general legal input credit for them - ICMS-ST in particular must
  stay in the inventory cost by default (art. 301 RIR/2018).
* stock_price_br is renamed to cost_unit (name from OCA#3819).
* cost_unit also deducts the transferable CSOSN 101/201 credit when the
  buyer is not Simples (LC 123/2006, art. 23, §§ 1-2). The ICMS relief
  (desoneração) is already netted out of fiscal_amount_total, so it is
  not subtracted again.
* Valuation switch becomes opt-in: company flag defaults to False and
  gates the incoming _get_price_unit branch, preserving the current
  behavior of existing databases.
* CST creditability defaults audited against the legislation, fixing 19
  entries from the original branch (e.g. ICMS 10/70 do credit the own
  highlighted tax even with ST; ICMS 50/51, IPI 02/04/05 and PIS/COFINS
  71/72/74/75 do not credit) and setting the whole IS group to False
  (excise, non-creditable by nature).
* Tests: creditability derivation per regime, reference net cost values
  (Real 630.00 / Presumido 704.00 on the 800.00 + IPI 26.00 demo
  invoice), per-line manual override and the valuation opt-in gate.
@mileo
mileo force-pushed the 16.0-add-l10n_br_fiscal-net-cost-core branch from e31c769 to 315233b Compare July 20, 2026 23:02
@mileo
mileo requested a review from renatonlima July 24, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:l10n_br_fiscal Module l10n_br_fiscal mod:l10n_br_stock_account Module l10n_br_stock_account series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants