-
-
Notifications
You must be signed in to change notification settings - Fork 209
[16.0][FIX] shopfloor: Fetch qty_available only when needed #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 16.0
Are you sure you want to change the base?
Conversation
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.
rousseldenis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great !
lmignon
left a comment
There was a problem hiding this 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.
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. |
simahawk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense
|
This PR has the |
| 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"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply this?
| if "no_qty_available" not in kw or not kw.get("no_qty_available"): | |
| if not kw.get("no_qty_available"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
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 "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 |
There was a problem hiding this comment.
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.
| 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 ?
Several services use
_data_move_lineto 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.
@lmignon , @rousseldenis