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

[14.0][IMP] stock_reserve_rule: add full lot strategy #1834

Closed
wants to merge 11 commits into from

Conversation

geomer198
Copy link
Contributor

New removal strategy is added.

@geomer198 geomer198 marked this pull request as draft September 8, 2023 23:50
@geomer198 geomer198 marked this pull request as ready for review September 11, 2023 10:12
@geomer198 geomer198 force-pushed the 14.0-t2780-stock_reserve_rule-imp branch from 3e791e2 to edd4fdc Compare September 15, 2023 11:05
Copy link

@aayartsev aayartsev left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Contributor

@francesco-ooops francesco-ooops left a comment

Choose a reason for hiding this comment

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

functional ok!

@OCA/logistics-maintainers good for merge?

@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). 🤖

Copy link
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

Can you clarify what you try to achieve ? What are your real use cases ?

I have the impression that you try to minimize the amount of locations from which you reserve

stock_reserve_rule/models/stock_reserve_rule.py Outdated Show resolved Hide resolved
@elvise
Copy link

elvise commented Sep 19, 2023

Can you clarify what you try to achieve ? What are your real use cases ?

I have the impression that you try to minimize the amount of locations from which you reserve

Hi @jbaudoux thanks for review!
The final goal is to have a configuration on which lot to reserve.
For example, for some fabrics we only reserve lots that meet the reserved quantity without shipping several lots to reach the required quantity.

@jbaudoux jbaudoux changed the title [14.0][IMP] stock_reserve_rule [14.0][IMP] stock_reserve_rule: add single lot strategy Sep 19, 2023
@jbaudoux
Copy link
Contributor

@OCA/logistics-maintainers good for merge?

Please also drop a review on #1831 :)

@elvise
Copy link

elvise commented Oct 1, 2023

@francesco-ooops @geomer198 looks tolerance doesn’t work :(

@geomer198
Copy link
Contributor Author

@francesco-ooops @geomer198 looks tolerance doesn’t work :(

Yes, I only added fields without functional.

@elvise
Copy link

elvise commented Oct 16, 2023

@jbaudoux please take a look :)

@geomer198 geomer198 force-pushed the 14.0-t2780-stock_reserve_rule-imp branch 2 times, most recently from f8c45ef to 9352c9d Compare October 25, 2023 19:33
@geomer198
Copy link
Contributor Author

@geomer198 Could you fix tests and pre-commit ?

Done, fixed it!

@francesco-ooops
Copy link
Contributor

@jbaudoux feedback?

@francesco-ooops
Copy link
Contributor

@jbaudoux gentle reminder!

Copy link
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

There are still issues to be addressed. Main concern is the group by location which does not seems inline with the intention of the module.
Also use float_compare and make a plain compare method.

@geomer198
Copy link
Contributor Author

There are still issues to be addressed. Main concern is the group by location which does not seems inline with the intention of the module. Also use float_compare and make a plain compare method.

Could you check my changes? Is now ok?

@geomer198 geomer198 force-pushed the 14.0-t2780-stock_reserve_rule-imp branch from 781bd70 to 9a62218 Compare November 18, 2023 18:35
@elvise
Copy link

elvise commented Nov 21, 2023

There are still issues to be addressed. Main concern is the group by location which does not seems inline with the intention of the module. Also use float_compare and make a plain compare method.

Could you check my changes? Is now ok?

@jbaudoux gentle reminder :)

if computation == "percentage":
# need + rounding < product_qty <= need * (100 + tolerance) / 100
return (
float_compare(need, product_qty, rounding) == -1
Copy link
Contributor

@jbaudoux jbaudoux Nov 21, 2023

Choose a reason for hiding this comment

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

Why don't you accept exact value when you give a tolerance? It should be in the limit defined by the tolerance but if the quantity is exactly the need, it should also be valid, isn't it?

Suggested change
float_compare(need, product_qty, rounding) == -1
float_compare(need, product_qty, rounding) <= 0

Copy link
Contributor

@jbaudoux jbaudoux Nov 21, 2023

Choose a reason for hiding this comment

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

Some unit tests on _compare_with_tolerance with real figures would be helpful. Just the call to the method without picking.
Tests with inside tolerance, at the lower limit of tolerance, at the upper limit of the tolerance, below tolerance, above tolerance

  • no tolerance
  • upper_limit, percentage
  • upper_limit, absolute
  • lower_limit, percentage
  • lower_limit, absolute

Copy link
Contributor

Choose a reason for hiding this comment

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

@elvise This still needs to be fixed or answered

Copy link

Choose a reason for hiding this comment

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

@francesco-ooops @geomer198 please take care

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux Done! Please check tests.

Copy link

Choose a reason for hiding this comment

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

@jbaudoux Done! Please check tests.

@geomer198 can you add tests with decimals (qty)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux Done! Please check tests.

@geomer198 can you add tests with decimals (qty)?

Yes) Done!

Comment on lines 459 to 465
need = (
yield fields.first(lot_quants).location_id,
lot_quantity,
need,
lot,
None,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

You have selected a lot and it can have multiple quants. I think you need to yield each quant one by one by looping on the quants (they should be already sorted by fifo/fefo) decreasing the need until need is 0 or all quants are consumed.
Can you add a test with this?
Example:

  • Loc1, Lot A, 10 units
  • Loc2, Lot A, 5 units
    Need for 15 units. Lot A is selected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux Thank you for your solution! I updated function implementation. Now the strategy looks better!

@jbaudoux
Copy link
Contributor

There are still issues to be addressed. Main concern is the group by location which does not seems inline with the intention of the module. Also use float_compare and make a plain compare method.

Could you check my changes? Is now ok?

Thanks for the work. The code is so much cleaner, easy to read and simple :)

@geomer198
Copy link
Contributor Author

@jbaudoux Please check my changes.

@elvise
Copy link

elvise commented Nov 23, 2023

@jbaudoux gentle reminder :)

1 similar comment
@elvise
Copy link

elvise commented Nov 26, 2023

@jbaudoux gentle reminder :)

Comment on lines 450 to 466
for lot_quant in lot_quants:
product_qty = sum(lot_quant.mapped("quantity"))
lot_quantity = sum(lot_quant.mapped("quantity")) - sum(
lot_quant.mapped("reserved_quantity")
)
if (
lot
and self._compare_with_tolerance(need, product_qty, rounding)
and lot_quantity > 0
):
need = (
yield lot_quant.location_id,
lot_quantity,
need,
lot,
None,
) # noqa
Copy link
Contributor

@jbaudoux jbaudoux Nov 26, 2023

Choose a reason for hiding this comment

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

What about lots that are partially reserved? I think you want to skip them.

product_qty can be computed outside loop.

Suggested change
for lot_quant in lot_quants:
product_qty = sum(lot_quant.mapped("quantity"))
lot_quantity = sum(lot_quant.mapped("quantity")) - sum(
lot_quant.mapped("reserved_quantity")
)
if (
lot
and self._compare_with_tolerance(need, product_qty, rounding)
and lot_quantity > 0
):
need = (
yield lot_quant.location_id,
lot_quantity,
need,
lot,
None,
) # noqa
if not lot:
continue
if any(quant.reserved_quantity in lot_quants):
# skip lots that are partially reserved
continue
product_qty = sum(lot_quants.mapped("quantity"))
if not self._compare_with_tolerance(need, product_qty, rounding):
continue
for lot_quant in lot_quants:
lot_quantity = lot_quant.quantity - lot_quant.reserved_quantity
need = yield (
lot_quant.location_id,
lot_quantity,
need,
lot,
None,
) # noqa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux Could you check my proposed version of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux Your code has an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

            if any(quant.reserved_quantity for quant in lot_quants):

Copy link
Contributor

Choose a reason for hiding this comment

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

@geomer198 was this addressed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@geomer198 was this addressed?

Yes, I added this code.

for lot, lot_quants in quants.filtered(
lambda quant: quant.product_id.id == product.id
and quant.lot_id
and not quant.reserved_quantity
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot exclude quant with reserved quantities before the group by. If the lot is on 2 locations and has a reservation only on one location, you will not end-up with the right result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbaudoux I fixed it. I hope now is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now we lost the exclusion. See my proposed solution above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we lost the exclusion. See my proposed solution above

I didn't understand this line:

                if any(quant.reserved_quantity in lot_quants):
                    # skip lots that are partially reserved
                    continue

In this function only quants variable. And why float must be contain in quant's record set?

@elvise
Copy link

elvise commented Nov 28, 2023

@jbaudoux good now ? :)

@jbaudoux
Copy link
Contributor

@jbaudoux good now ? :)

@elvise @francesco-ooops
Please write a list of tests instead of keeping asking me if this is now good. Write them in English and ask the developer to implement them. Also run your tests manually. You will then have your answer.

Write unit tests for the tolerance. See #1834 (comment)
Write unit test for a lot on multiple locations
Write unit test for anything that has been discussed above and for which you could not tell yourself if it is now good

Copy link

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 Apr 28, 2024
@github-actions github-actions bot closed this Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs review stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants