Skip to content
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

[16.0][FIX] stock_reserve_rule: Don't select negative quants #2229

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

rousseldenis
Copy link
Contributor

@rousseldenis rousseldenis commented Jan 9, 2025

The conditions to reproduce the problem are:
- A demand of a X quantity
- A positive quant (old) with a big quantity > X
- A positive quant with a little quantity > X but with all quantities reserved
- A negative quant (recent) of a quantity < 0 and abs(quantity) < X

The move reservation should lead to one move line creation

The conditions to reproduce the problem are:
    - A demand of a X quantity
    - A positive quant with a big quantity > X (recent)
    - A positive quant with a little quantity > X but with all quantities reserved
    - A negative quant of a quantity < 0 and abs(quantity) < X

The move reservation should lead to one move line creation
@rousseldenis
Copy link
Contributor Author

@jbaudoux

@jbaudoux
Copy link
Contributor

jbaudoux commented Jan 9, 2025

@sebalix Issue occurs when quants merge is disabled

# Don't take into account those quants as that can lead
# to a negative demand in the created move line
# Mimic odoo behavior in move _action_assign() method.
if location_quantity <= 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using float_compare ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that. I don't know why Odoo does not use it.

https://github.com/odoo/odoo/blob/16.0/addons/stock/models/stock_move.py#L1702

@rousseldenis
Copy link
Contributor Author

@sebalix Issue occurs when quants merge is disabled

Not only. If quantities are forced, negative quants can occur.

Comment on lines +806 to +807
# Create it without inventory mode as it could merge it with the other one
self.env["stock.quant"].with_context(inventory_mode=True).create(
Copy link
Contributor

Choose a reason for hiding this comment

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

It says it creates a quant without inventory mode while setting inventory_mode=True in the context?

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.

3 participants