Skip to content

[18.0][MIG] l10n_br_sped_efd_icms_ipi: Migration to 18.0#4657

Draft
ygcarvalh wants to merge 40 commits into
OCA:18.0from
kmee:18.0-mig-l10n_br_sped_efd_icms_ipi
Draft

[18.0][MIG] l10n_br_sped_efd_icms_ipi: Migration to 18.0#4657
ygcarvalh wants to merge 40 commits into
OCA:18.0from
kmee:18.0-mig-l10n_br_sped_efd_icms_ipi

Conversation

@ygcarvalh

@ygcarvalh ygcarvalh commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Migração do l10n_br_sped_efd_icms_ipi (EFD ICMS/IPI) da 16.0 da Akretion para a 18.0.

Além das adaptações de API da 18.0 (manifest, post_init_hook(env), views list), troquei o amount_total do documento por amount_financial_total e deixei o 0002 sair só para estabelecimento industrial.

A partir da empresa demo o módulo gera o bloco 0, o bloco C (o C100 com os documentos, o C170 com os itens e o C190 agregando por CST, CFOP e alíquota) e a apuração do ICMS no bloco E (E110), com o débito das saídas menos o crédito das entradas.

No caminho encontrei dois bugs que já vinham da 16.0 e que só apareciam quando havia mais documentos autorizados na base. O 0200 estourava Expected singleton, porque o filtered podia trazer mais de uma linha do mesmo produto; e o 0220 tinha um _odoo_query que devolvia um set no lugar da tupla (query, params), o que quebrava o cr.execute. Corrigi os dois.

Testei com o round-trip que já existia e com um teste novo que confere que C100, 0200, C190 e E110 saem. Ainda falta os registros de ajuste da apuração (E111 e afins) e validar no PVA.

@OCA-git-bot OCA-git-bot added series:18.0 mod:l10n_br_sped_efd_icms_ipi Module l10n_br_sped_efd_icms_ipi labels Jul 9, 2026

@rvalyi rvalyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se vc realmente quiser adiantar isso sem encher o saco com mais AI slope vindo da Kmee, parte por favor do PR #4043 que deveria entrar e segue https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-18.0
Além disso vai depender do módulo l10n_br_stock_account que ainda está como PR na 18.

@ygcarvalh
ygcarvalh force-pushed the 18.0-mig-l10n_br_sped_efd_icms_ipi branch from af96a08 to d4dadfb Compare July 9, 2026 17:12
@ygcarvalh ygcarvalh changed the title [18.0][ADD] l10n_br_sped_efd_icms_ipi: EFD ICMS/IPI (SPED Fiscal) [18.0][MIG] l10n_br_sped_efd_icms_ipi: Migration to 18.0 Jul 9, 2026
rvalyi and others added 25 commits July 14, 2026 11:12
applied: sed -i 's/_description = textwrap\.dedent("    %s" %
(__doc__,))/_description = textwrap.dedent(f"    {__doc__}")/g'  file.py
[IMP] l10n_br_sped_efd_icms_ipi: fiscal domain

[FIX] Set correct reference for registry for bloco 0
rvalyi and others added 15 commits July 14, 2026 11:12
Why previous mapping contributed by KMEE was untested shit:

1. The SQL Logic is a Paradox (It will always return 0 rows)

Look closely at the WHERE clause in the existing code:
code SQL

where
    fd.id = fdl.document_id
    and uom.id = fdl.uot_id       <--- Condition A
    and ...
    and uom.id <> fdl.uot_id      <--- Condition B

It requires uom.id to be equal to fdl.uot_id AND not equal to fdl.uot_id at the same time. This is a logical impossibility. This query will silently return 0 rows every single time it is run.

2. Fatal Python Syntax Error

It is using curly braces {}. In Python, this creates a set. A set is unordered.
The Sped base module expects a tuple (query, [parameters]) to pass to self._cr.execute(). When self._cr.execute(*self._odoo_query(...)) unpacks this set, psycopg2 will instantly crash because it will receive the query string and the dates in a random, unpredictable order, and not as a parameterized list.

3. It breaks the SPED Hierarchy (Missing Parent Context)

In the SPED layout, 0220 is a child register of 0200 (Product). It must only report the conversion factors for the specific product currently being processed.
The existing query lacks AND fdl.product_id = %s. It queries the entire database globally. If it actually worked, it would print every unit conversion in the system under every single product, causing massive duplication and a rejection by the SEFAZ PVA.
@ygcarvalh
ygcarvalh force-pushed the 18.0-mig-l10n_br_sped_efd_icms_ipi branch from d4dadfb to de8b111 Compare July 14, 2026 14:15
@ygcarvalh

Copy link
Copy Markdown
Contributor Author

Alterações feitas conforme o review: refeito a partir da branch do PR #4043, seguindo o wiki de migração.

@ygcarvalh

Copy link
Copy Markdown
Contributor Author

@rvalyi sobre a dependência de stock: a base 16.0 declarava stock_account (core), mas o código na 18.0 não usa stock, então deixei o manifesto só com l10n_br_sped_base + l10n_br_account. você prefere que ele dependa do stock_account (core) ou do l10n_br_stock_account (OCA, #4590)? se for o da OCA, o PR fica bloqueado até o #4590 entrar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:l10n_br_sped_efd_icms_ipi Module l10n_br_sped_efd_icms_ipi series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants