Skip to content

Conversation

@sbejaoui
Copy link

@sbejaoui sbejaoui commented Jun 18, 2025

Several services use _data_move_line to prepare stock move line data for the Shopfloor frontend. However, qty_available is not displayed on all pages where stock move lines are handled.

Since qty_available is computed from quants, accessing it unnecessarily can lead to useless database queries. In high-concurrency environments, this can even trigger deadlocks when reads and writes occur simultaneously across many Shopfloor users.

This fix limits the use of qty_available to cases where it’s strictly needed.

image

@lmignon , @rousseldenis

Several services use `_data_move_line` to prepare stock move line data
for the Shopfloor frontend. However, qty_available is not displayed on
all pages where stock move lines are handled.

Since qty_available is computed from quants, accessing it unnecessarily
can lead to useless database queries. In high-concurrency environments,
this can even trigger deadlocks when reads and writes occur simultaneously
across many Shopfloor users.

This fix limits the use of qty_available to cases where it’s strictly needed.
@OCA-git-bot
Copy link
Contributor

Hi @simahawk, @guewen, @sebalix,
some modules you are maintaining are being modified, check this out!

@sbejaoui sbejaoui changed the title [FIX] shopfloor: Fetch qty_available only when needed [16.0][FIX] shopfloor: Fetch qty_available only when needed Jun 18, 2025
Copy link

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Great !

Copy link

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

Do you've analyzed the domain used in such a case. The qty available is computed for a specific location. I find it hard to believe that there are several people at the same time asking for the same quantity of the same product for the same location... In any case, if you don't need the field because you don't display it, it's time saved.

@sbejaoui
Copy link
Author

Do you've analyzed the domain used in such a case. The qty available is computed for a specific location. I find it hard to believe that there are several people at the same time asking for the same quantity of the same product for the same location... In any case, if you don't need the field because you don't display it, it's time saved.

The quantity is not relevant; the issue is related to the same product from the same location, and it occurs consistently based on the data I analyzed in our use case.

Copy link

@simahawk simahawk left a comment

Choose a reason for hiding this comment

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

make sense

@OCA-git-bot
Copy link
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). 🤖

data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
Copy link
Contributor

Choose a reason for hiding this comment

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

why not simply this?

Suggested change
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
if not kw.get("no_qty_available"):

Choose a reason for hiding this comment

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

@github-actions
Copy link

github-actions bot commented Nov 2, 2025

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 2, 2025
@github-actions github-actions bot closed this Dec 7, 2025
@jbaudoux jbaudoux reopened this Dec 8, 2025
@OCA-git-bot
Copy link
Contributor

Hi @simahawk, @guewen, @sebalix,
some modules you are maintaining are being modified, check this out!

Comment on lines +414 to +417
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to avoid double negations ? not no_qty_available is not really intuitive to read.
For instance, explicitely add a named argument with_qty_available which defaults to True.
When you don't need this information in the data, we can just set with_qty_available=False.
Then you can do this, which IMO is easier to read. and less bug prone.

Suggested change
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
if with_qty_available:
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available

What do you think ?

@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Dec 14, 2025
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.

7 participants