Skip to content

[ADD] l10n_fr_einvoicing_directory_import: maintain directory lines v… - #31

Open
njeudy wants to merge 9 commits into
akretion:18.0from
Alusage:18.0-add-directory-import
Open

[ADD] l10n_fr_einvoicing_directory_import: maintain directory lines v…#31
njeudy wants to merge 9 commits into
akretion:18.0from
Alusage:18.0-add-directory-import

Conversation

@njeudy

@njeudy njeudy commented Jul 27, 2026

Copy link
Copy Markdown

…ia CSV

When the AFNOR directory API is not activated, this module lets users export the SIREN list to deposit on the official directory (headerless, one SIREN per line) and import the returned CSV (Chorus Pro format) to create/update fr.directory.line records. One CSV row maps to one directory line, matched to its partner by SIREN and disambiguated by SIRET when several companies share a SIREN. The line type (siren/siret/routing_code/suffix) is derived from the electronic address structure. A wizard exposes both steps.

Annuaire: https://facturation.chorus-pro.gouv.fr/annuaire/

@ak-git-bot ak-git-bot added series:18.0 mod:l10n_fr_einvoicing_directory_import Module l10n_fr_einvoicing_directory_import labels Jul 27, 2026
@njeudy
njeudy force-pushed the 18.0-add-directory-import branch 3 times, most recently from aae9f9b to ff844c3 Compare July 27, 2026 08:13
…ia CSV

When the AFNOR directory API is not activated, this module lets users export
the SIREN list to deposit on the official directory (headerless, one SIREN per
line) and import the returned CSV (Chorus Pro format) to create/update
fr.directory.line records. One CSV row maps to one directory line, matched to
its partner by SIREN and disambiguated by SIRET when several companies share a
SIREN. The line type (siren/siret/routing_code/suffix) is derived from the
electronic address structure. A wizard exposes both steps.

Annuaire: https://facturation.chorus-pro.gouv.fr/annuaire/
@njeudy
njeudy force-pushed the 18.0-add-directory-import branch from ff844c3 to 73df28b Compare July 27, 2026 08:15
njeudy added 2 commits July 27, 2026 10:20
…panies

After an import, collect the partners whose directory lines were created or
updated and expose a button on the wizard to open them in a list view.
@njeudy

njeudy commented Jul 27, 2026

Copy link
Copy Markdown
Author
image

@njeudy njeudy changed the title WIP: [ADD] l10n_fr_einvoicing_directory_import: maintain directory lines v… [ADD] l10n_fr_einvoicing_directory_import: maintain directory lines v… Jul 27, 2026
njeudy added 2 commits July 27, 2026 11:16
…-registered

The native API sync fills partner-level directory fields; the CSV import now
does the same (fr_directory_entity_type=private by default, siren/siret,
last sync date) so the directory section and default line selector show up on
the partner and BT-49 can resolve.
… active match

After a directory return import, when a partner ends up with exactly one
active directory line and no default routing line, set it as the default
(BT-49 source). The field is a manual selector natively, so this saves a
per-partner pick when the annuaire confirms a single billing address.
@alexis-via

Copy link
Copy Markdown
Member

Could you give an example of underlying scenario ? I understand that you are not using a regular PA with AFNOR-API (otherwise, you would not need this), but use an external tool to send invoice ?

njeudy added 4 commits July 29, 2026 14:13
A real directory return holds one row per company (7000+ on a mid-sized
database). The import did one search and one write per row, and every write
re-triggered the stored computes on res.partner, so the request hit the
server time limit and was killed before committing anything.

The import now works in two passes: rows are parsed and matched to partners
first, existing lines are pre-loaded in a single query indexed by
(partner, identifier), then writes are grouped by identical values and
creations issued in one call. Partner marking is grouped the same way.
Tracking is disabled during the import so it no longer posts one chatter
message per line.
…ial_partner_id

Resolving the directory status of a company walks its invoices, so the CSV
import issues one such query per company. Odoo leaves that column unindexed,
making every lookup a sequential scan of account_move — 877k rows on the FPV
database, tens of seconds each. The import was killed by the server time
limit before writing anything, whatever the batching applied on the Odoo side.

Indexing the column also speeds up every partner-centric accounting view.
…update

`index=True` on the inherited field is enough on a clean database, but any
module redefining commercial_partner_id without it would silently drop the
index. Recreating it in `init()` makes the module self-healing: Odoo's
`create_index` is a no-op when the index is already there.
…tches

Marking a partner as present in the directory invalidates the stored
fr_einvoicing_required on account.move, which depends on the partner entity
type. Importing a whole directory return in one transaction therefore made
Odoo recompute that field across the partners' entire invoice history at
flush time: on a production database (877k moves) the worker ran out of
memory before committing anything.

Partners are now processed in batches of 200, each committed on its own, and
the cache is dropped between batches so recomputes stay bounded. Progress is
logged batch by batch.

The import is no longer atomic; this is deliberate. A directory return is
idempotent — lines are upserted by (partner, identifier) — so re-running it
after a failure resumes where it stopped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:l10n_fr_einvoicing_directory_import Module l10n_fr_einvoicing_directory_import series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants