Skip to content

[18.0][FIX] sale_elaboration_margin: don't leave the temporary line pending to recompute - #290

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
Tecnativa:18.0-FIX-sale_elaboration_margin-temporary-line-recompute
Nov 12, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:18.0from
Tecnativa:18.0-FIX-sale_elaboration_margin-temporary-line-recompute

Conversation

@sergio-teruel

Copy link
Copy Markdown
Contributor

To get the elaboration price, a temporary sale order line is created for the elaboration product and detached from the order afterwards. Detaching it flags its stored computed fields to be recomputed, and nothing ever computes them, so they remain pending in the environment.

The next time one of those fields is read on a real line, the pending temporary line is computed in the same batch. As it has no order, it has neither company nor currency, so any compute method relying on the currency of the line fails with "Expected singleton: res.currency()". This happens for example when selecting a product in a sale order line and the elaboration is filled automatically.

Now the pending computations of the temporary line are discarded once the price is obtained.

@Tecnativa TT64937

ping @carlosdauden @CarlosRoca13

… to recompute

To get the elaboration price, a temporary sale order line is created for the elaboration product and detached from the order afterwards. Detaching it flags its stored computed fields to be recomputed, and nothing ever computes them, so they remain pending in the environment.

The next time one of those fields is read on a real line, the pending temporary line is computed in the same batch. As it has no order, it has neither company nor currency, so any compute method relying on the currency of the line fails with "Expected singleton: res.currency()". This happens for example when selecting a product in a sale order line and the elaboration is filled automatically.

Now the pending computations of the temporary line are discarded once the price is obtained.

@rrebollo rrebollo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ran the module's tests on 18.0 after installing it in a throwaway database: green, and the new regression test fails on the base revision, so the leak is pinned. I reproduced the pending computations on the discarded line but not the Expected singleton: res.currency() itself, which needs more than a bare sale + sale_elaboration stack.

When you have a moment, a review of #257 — the 17.0 backport of sale_margin_delivered_security — would be very welcome in return.

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@pedrobaeza The merge process could not start, because command git fetch --quiet --force --prune https://github.com/OCA/margin-analysis 'refs/heads/*:refs/heads/*' failed with output:

error: cannot fork() for remote-https: Resource temporarily unavailable

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 18.0-ocabot-merge-pr-290-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 034dc22 into OCA:18.0 Nov 12, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at f918747. Thanks a lot for contributing to OCA. ❤️

@pedrobaeza
pedrobaeza deleted the 18.0-FIX-sale_elaboration_margin-temporary-line-recompute branch November 12, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants