Skip to content

[18.0][FIX] l10n_fr_einvoicing: don't recompute the whole history when the issuer's entity type is set - #37

Closed
njeudy wants to merge 1 commit into
akretion:18.0from
Alusage:18.0-fix-einvoicing-required-recompute
Closed

[18.0][FIX] l10n_fr_einvoicing: don't recompute the whole history when the issuer's entity type is set#37
njeudy wants to merge 1 commit into
akretion:18.0from
Alusage:18.0-fix-einvoicing-required-recompute

Conversation

@njeudy

@njeudy njeudy commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #36.

Setting the entity type on the issuer's partner — the first step of the onboarding, via Directory Sync — currently recomputes fr_einvoicing_required on every invoice of the company in a single transaction, and dies in MemoryError on any real history. Details, traceback and reasoning in #36.

What changes

fr_directory_company_entity_type is dropped from the @api.depends of _compute_einvoicing_required: it is a related on the company's partner, so one value was driving a stored field on the whole company.

The refresh becomes explicit and batched, in res_company._fr_ctc_recompute_einvoicing_required(), mirroring what the module already does for company_fr_directory_line_id with _fr_ctc_compute_invoice_company_dir_line() — same hard_lock_date filter included.

The customer-side dependency is untouched: it is bounded by one partner's invoices, and the directory sync walks partners one at a time.

Notes

… type change

fr_einvoicing_required is stored and depends on
fr_directory_company_entity_type, a related on
company_id.partner_id.fr_directory_entity_type. One value therefore drives the
field on every invoice of the company: setting the issuer's entity type — a
one-off, done through the Directory Sync button when the reform is switched on
— invalidates the entire history in a single transaction.

On a production-sized database (877k journal entries, 497k customer invoices)
the worker dies before writing anything:

    File "l10n_fr_einvoicing/models/account_move.py", in _compute_einvoicing_required
        move.move_type in ("out_invoice", "out_refund")
    MemoryError

Drop that dependency and recompute explicitly, in committed batches, through
_fr_ctc_recompute_einvoicing_required(). This mirrors what the module already
does for company_fr_directory_line_id, which depends only on company_id and
has _fr_ctc_compute_invoice_company_dir_line() to refresh it — including the
hard_lock_date filter, which keeps locked years out of the way.

Closes akretion#36
@ak-git-bot

Copy link
Copy Markdown

Hi @alexis-via,
some modules you are maintaining are being modified, check this out!

@njeudy

njeudy commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by 6f74991 on 18.0, which drops store=True from fr_einvoicing_required altogether. That removes the mass recompute at the root rather than narrowing its @api.depends, so this PR has no purpose any more — closing it.

For anyone landing here from #36: the symptom was a MemoryError when setting the issuer's entity type on a database with a real invoicing history (497k customer invoices out of 877k journal entries on ours), and 6f74991 fixes it. The equivalent commits are on 16.0 and 19.0 too, and the local fix carried on #33 and #34 has been dropped from both branches in favour of it.

@njeudy njeudy closed this Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:l10n_fr_einvoicing Module l10n_fr_einvoicing series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MemoryError: setting the issuer's directory entity type recomputes fr_einvoicing_required on the whole company history

2 participants