Skip to content

[18.0][IMP] l10n_it_edi_extension: batch-write EDI amount fields on import#5192

Open
micheledic wants to merge 1 commit into
OCA:18.0from
stesi:18.0_perf_l10n_it_edi_extension
Open

[18.0][IMP] l10n_it_edi_extension: batch-write EDI amount fields on import#5192
micheledic wants to merge 1 commit into
OCA:18.0from
stesi:18.0_perf_l10n_it_edi_extension

Conversation

@micheledic

Copy link
Copy Markdown
Contributor

Problem

_l10n_it_edi_get_extra_info runs two += loops on stored Monetary
fields l10n_it_edi_amount_untaxed and l10n_it_edi_amount_tax: one
iteration per DettaglioLinee, one per DatiRiepilogo. Every iteration
goes through account.move.write() and reschedules dependent recomputes.
Total work scales with N+M per invoice.

Fix

Replace both loops with two sum() calls and one write({...}) under
skip_invoice_sync=True. Final field values match the previous code.

Performance (clean DB, in-process bench, min of 3 runs)

Lines Summaries OLD NEW Speedup
50 10 0.052 s 0.010 s 5.4x
200 10 0.134 s 0.009 s 15.8x
500 10 0.297 s 0.010 s 30.5x
1000 10 0.624 s 0.016 s 38.3x

@OCA-git-bot OCA-git-bot added series:18.0 mod:l10n_it_edi_extension Module l10n_it_edi_extension labels May 6, 2026

@andreampiovesana andreampiovesana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@monen17 monen17 added the missing issue PRs must be linked to an issue. See the wiki. label May 8, 2026
@micheledic micheledic force-pushed the 18.0_perf_l10n_it_edi_extension branch from eaf5af9 to 7ca81b0 Compare June 5, 2026 08:37
…mport

Replace the per-iteration "self.l10n_it_edi_amount_untaxed += ..." and
"self.l10n_it_edi_amount_tax += ..." accumulation loops in
_l10n_it_edi_get_extra_info with two sum() expressions and a single
write({...}) executed under skip_invoice_sync=True.

Each += on a stored Monetary field rescheduled the recompute chain of
its dependents (l10n_it_edi_amount_total, l10n_it_edi_validation_message)
N+M times, making XML parsing O(N) for very large invoices.

Benchmark on a clean DB (200 lines, 10 summaries -> 16x; 500 -> 30x;
1000 -> 38x). Behaviour and final field values are unchanged.
@micheledic micheledic force-pushed the 18.0_perf_l10n_it_edi_extension branch from 7ca81b0 to 3cb72b8 Compare June 12, 2026 07:52
@micheledic

Copy link
Copy Markdown
Contributor Author

@OCA/local-italy-maintainers potete dare un check ?

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

Labels

missing issue PRs must be linked to an issue. See the wiki. mod:l10n_it_edi_extension Module l10n_it_edi_extension series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants