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

[15.0[FIX] product_lot_sequence: Fix sequence incrementation opening detailed operations #1323

Conversation

grindtildeath
Copy link
Contributor

When opening the detailed operations view of a stock move, Odoo is calling stock.production.lot._get_next_serial to set stock.move.next_serial field anytime the product is tracked by serial and the move is assigned.

If we use this module with product or global policy, the respective sequence will therefore be called and incremented anytime this view is open, even if the picking is not creating lots (e.g. delivery orders or internal transfers)

To avoid incrementing the sequence unnecessarily, we only allow to get the next sequence number the first time this view is opened and if the move has to create new serial numbers.
Otherwise, we force the value to be set to stock.move.next_serial field to an empty string if no serial has to be created through this move, or to the next_serial value assigned on the first opening of the view.

@kanda999
Copy link

Thank you for PR.
I was not satisfied with the logic proposed by First SN in the product_lot_sequence module from before.
This PR fixes the problem of the First SN being updated every time the wizard is opened.

However, I still think the first SN proposal is not complete and there are still problems.
It happens in the following operations.

ex)

1, Five (or multiple) serial numbers are assigned to serial-managed products in one delivery.
2023-04-17_17h34_54

2, This delivery is verified and received.

3, Create a new delivery. But then the first SN proposed is 0000002.
2023-04-17_17h36_15

4, Assign the first SN proposed and verified delivery and then get "The serial number has already been asigned" because 0000002 is already in stock.

To solve this problem, the first SN proposal should be the next largest number the assigned SN.
I may work on this issue. I would then use this PR change. Do you have any good solutions to this problem?

@grindtildeath
Copy link
Contributor Author

Hello @kanda999

Thanks for your comment.

I agree there is an issue with the actual implementation of the module and the way this view is working. My gut feeling is that it's probably counter intuitive to use sequence objects to handle generation and creation of lots/SN in the newer version, at least for goods that are purchased and where lots/SN are usually provided by the supplier.

I see two possible solutions:

  • either we remove the ability to set "First SN" on the stock move view, and use the "Assign serial numbers" action to call the sequence as many times as we have "Number of SN", so that the sequence will still be in sync with the serials that are generated. (in that case I'm also wondering if we shouldn't just remove the call I'm modifying here to increment the sequence on the opening of the view)
  • avoid using sequences altogether and rely on the search of last lot/SN as is now the case in standard (https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_production_lot.py#L68-L70). Eventually remove the product parameter for the search to use a "global" sequence, or add extra parameters to mimic a "product" specific sequence.

First one would be the more logical move, but I tend to think the second looks like the better long term solution although that would of course require an extra hook in Odoo (or overriding search with a context key).

@AdriaGForgeFlow @LoisRForgeFlow what do you think?

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

@yostashiro
Copy link
Member

yostashiro commented Apr 19, 2023

I see two possible solutions:

  • either we remove the ability to set "First SN" on the stock move view, and use the "Assign serial numbers" action to call the sequence as many times as we have "Number of SN", so that the sequence will still be in sync with the serials that are generated. (in that case I'm also wondering if we shouldn't just remove the call I'm modifying here to increment the sequence on the opening of the view)
  • avoid using sequences altogether and rely on the search of last lot/SN as is now the case in standard (https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_production_lot.py#L68-L70). Eventually remove the product parameter for the search to use a "global" sequence, or add extra parameters to mimic a "product" specific sequence.

First one would be the more logical move, but I tend to think the second looks like the better long term solution although that would of course require an extra hook in Odoo (or overriding search with a context key).

@grindtildeath Thank you very much for this PR. I agree. The second option sounds better for the long term as it's more in line with the standard design.

In the meantime, our workaround for our client for now is to use https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_auto_create_lot together with this module (containing the update of his PR). Not sure there is actually a situation where manual intervention is required in SN generation, when numbering rule is pre-defined (either for the product or globally). Therefore the use of stock_picking_auto_create_lot works well for us to bypass the design incompatibility between this module and the standard SN generation.

@simahawk
Copy link
Contributor

@grindtildeath can you create an issue to follow up w/ #1323 (comment) and link it in the roadmap? Then we can merge I think.

@grindtildeath grindtildeath force-pushed the 15.0-fix-product_lot_sequence_move_detailed_operations branch from b2b1c8d to ca381bd Compare April 24, 2023 12:30
When opening the detailed operations view of a stock move, Odoo is calling
stock.production.lot._get_next_serial to set stock.move.next_serial field
anytime the product is tracked by serial and the move is assigned.

If we use this module with product or global policy, the respective sequence
will therefore be called and incremented anytime this view is open, even
if the picking is not creating lots (e.g. delivery orders or internal transfers)

To avoid incrementing the sequence unnecessarily, we only allow to get the next
sequence number the first time this view is opened and if the move has
to create new serial numbers.
Otherwise, we force the value to be set to stock.move.next_serial field to
an empty string if no serial has to be created through this move, or to the
next_serial value assigned on the first opening of the view.
@grindtildeath grindtildeath force-pushed the 15.0-fix-product_lot_sequence_move_detailed_operations branch from ca381bd to c886da5 Compare April 24, 2023 12:40
@grindtildeath
Copy link
Contributor Author

@simahawk #1326 added in roadmap

@simahawk
Copy link
Contributor

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 15.0-ocabot-merge-pr-1323-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 0c1ead8 into OCA:15.0 May 16, 2023
@OCA-git-bot
Copy link
Contributor

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

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.

8 participants