[FIX] account_statement_import_file: avoid duplicate and slow statement imports - #979
Open
feg-adhoc wants to merge 1 commit into
Open
[FIX] account_statement_import_file: avoid duplicate and slow statement imports#979feg-adhoc wants to merge 1 commit into
feg-adhoc wants to merge 1 commit into
Conversation
Contributor
|
Hi @alexis-via, |
There was a problem hiding this comment.
Pull request overview
This PR improves the performance and reliability of bank statement file imports by preventing Odoo Enterprise (account_accountant) from synchronously rendering and attaching a statement PDF during account.bank.statement.create(), which can be slow and resource-intensive for large imports.
Changes:
- Add
skip_pdf_attachment_generationto the create context when creating imported bank statements, to avoid Enterprise’s heavy synchronous PDF rendering during import.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| st_vals["line_ids"] = [[0, False, line] for line in st_lines_to_create] | ||
| # Skip the Enterprise synchronous PDF render on create, too heavy | ||
| # for large imports (no-op if account_accountant is not installed). | ||
| context.setdefault("skip_pdf_attachment_generation", True) |
feg-adhoc
force-pushed
the
19.0-h-123605-feg
branch
4 times, most recently
from
July 24, 2026 17:55
34e81c1 to
e0e45cd
Compare
feg-adhoc
force-pushed
the
19.0-h-123605-feg
branch
2 times, most recently
from
July 24, 2026 18:31
7efe914 to
7df490f
Compare
account_accountant (Enterprise) overrides account.bank.statement.create() to synchronously render a full PDF of the statement via wkhtmltopdf, unless the context flag skip_pdf_attachment_generation is set. For large imported statements this render is prohibitively slow and heavy (~17ms/line; several seconds for a few hundred lines), causing request timeouts, dropped connections and serialization retries that re-run the whole import, so nothing gets imported. In environments with a broken wkhtmltopdf it fails outright. Set skip_pdf_attachment_generation when creating statements during import. The imported source file is already attached to the statement, and the PDF can still be generated manually. No-op when account_accountant is absent.
feg-adhoc
force-pushed
the
19.0-h-123605-feg
branch
from
July 24, 2026 20:34
7df490f to
63a1920
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.
Problem
Importing a bank statement file can create duplicate bank statements (the same file imported several times). From the user's point of view the import seems to "loop" and never confirm — even though they clicked Import only once.
Root cause
This is a chain of events; the duplication is the important part:
account.movecreated for the statement lines (per-move work that also grows with the journal history).account_accountant(Enterprise) is installed,account.bank.statement.create()synchronously renders a full PDF of the statement through wkhtmltopdf on every create, unless the context flagskip_pdf_attachment_generationis set. This is very slow and memory-heavy for large statements.import_file_buttonis not idempotent: each re-sent request re-runs the whole import and creates another statement. Sheet-based mappings without aunique_import_idcolumn have no per-line dedup, so nothing stops the duplicates.Net effect: a single user click produces several identical statements and a "looping" UI.
Fix
Two changes, both scoped to the import:
Skip the Enterprise synchronous PDF render during import — set
skip_pdf_attachment_generationin the statement creation context. The imported source file is already attached to the statement, and the PDF can still be generated manually afterwards. No dependency onaccount_accountantis added (it is a no-op when that module is absent).Make
import_file_buttonidempotent:As a result, a user who triggered a single import never sees an error and never ends up with duplicates, regardless of how the proxy behaves.
Why fix idempotency, and not "why does the import re-run / recompute in the first place?"
This is a fair review question, so to address it up front — we deliberately patch idempotency instead of chasing the underlying slowness first:
account.move; the synchronous PDF render is Enterpriseaccount_accountantbehaviour. Optimising core move creation is a large, risky, cross-module effort — and even a much faster import would still leave the correctness hole open (a short or misconfigured proxy timeout would still duplicate).Note on behaviour
Re-importing the exact same file now returns the already-imported statement instead of creating a new one — consistent with the module's existing dedup intent (
unique_import_id). To genuinely re-import a file, remove the previous statement first.