[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
Open
[16.0][ADD] l10n_br_fiscal, l10n_br_stock_account: custo líquido de aquisição pela creditabilidade do CST#4744mileo wants to merge 2 commits into
mileo wants to merge 2 commits into
Conversation
…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.
Contributor
|
Hi @mbcosta, @rvalyi, @renatonlima, |
… 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
force-pushed
the
16.0-add-l10n_br_fiscal-net-cost-core
branch
from
July 20, 2026 23:02
e31c769 to
315233b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
(
default_creditable_tax), mais um mixin de preço de estoque por linha. Mantido comoo modelo de dados.
fiscal, nunca dependendo de interação de tela; introduziu o campo
cost_unit.Mantido como o princípio de resolução e o nome do campo.
Substitui a abordagem de resolver/
product_destinationdo #4730 (mesmo autor), que éfechado em favor deste.
Como
default_creditable_taxnol10n_br_fiscal.cst, definido por CST noarquivo 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).
l10n_br_fiscal.stock.price.mixincom o campo calculadocost_unit(total da linha líquido dos impostos creditáveis) e os booleanos decreditabilidade por linha.
icms/ipi/pis/cofins_tax_is_creditablesão calculados (store=True,readonly=False): o valor deriva dodefault_creditable_taxdo CST da linha E dogate 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 podeser comprado com destinações diferentes).
stock.movede entrada passa a ser valorizado pelocost_unit. Isto é opt-inpor empresa (
stock_valuation_via_stock_price, padrão False), de modo que basesexistentes 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.
7 testes em
TestCostUnit; suíte completa dol10n_br_stock_accountverde.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.