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][ADD] repair_stock_move_restrict_lot: Assign lot on stock move creation. #74

Merged

Conversation

AaronHForgeFlow
Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow commented Dec 13, 2024

This is a new module. It is needed when using repair_stock_move and using lots. Otherwise in the_action_assign it may reserve the incorrect quant and then and error is raised when unreserving the quant: https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_move_line.py#L388

Steps to reproduce. Create a product tracked with serial number and create multiple quants for various serials. It may happen that the reservation is done in the incorrect serial. See test case added for reference

Without this module you may get this error:

  File "/opt/odoo/auto/addons/stock_account/models/stock_move_line.py", line 49, in write
    res = super(StockMoveLine, self).write(vals)
  File "/opt/odoo/auto/addons/stock/models/stock_move_line.py", line 373, in write
    Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
  File "/opt/odoo/auto/addons/stock/models/stock_quant.py", line 685, in _update_reserved_quantity
    raise UserError(_('It is not possible to unreserve more products of %s than you have in stock.', product_id.display_name))
odoo.exceptions.UserError: It is not possible to unreserve more products of Acoustic Magic Bloc than you have in stock.

cc @ForgeFlow

@AaronHForgeFlow AaronHForgeFlow force-pushed the 15.0-fix-repair_stock_move-reservation branch from 04875c2 to 8c18c88 Compare December 13, 2024 11:35
@AaronHForgeFlow AaronHForgeFlow changed the title [FIX] repair_stock_move: Assign lot on stock move creation. [15.0][FIX] repair_stock_move: Assign lot on stock move creation. Dec 13, 2024
@AaronHForgeFlow
Copy link
Contributor Author

AaronHForgeFlow commented Dec 13, 2024

In addition, if for some reason the correct quant is reserved but then we try to cancel the repair order you may end with this error, because the system is trying to unreserve the incorrect quant again:
image

@AaronHForgeFlow AaronHForgeFlow force-pushed the 15.0-fix-repair_stock_move-reservation branch from 8c18c88 to c7f1136 Compare December 13, 2024 12:28
@AaronHForgeFlow AaronHForgeFlow changed the title [15.0][FIX] repair_stock_move: Assign lot on stock move creation. [15.0][ADD] repair_stock_move_restrict_lot: Assign lot on stock move creation. Dec 13, 2024
Glue module between repair_stock_move and stock_restrict_lot.
It assigns the repair lot to the stock moves on creation. Otherwise in the
_action_assign it may reserve the incorrect quant and then and error is raised
when unreserving the quant: https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_move_line.py#L388
@AaronHForgeFlow AaronHForgeFlow force-pushed the 15.0-fix-repair_stock_move-reservation branch from c7f1136 to d161c4c Compare December 13, 2024 12:32
Copy link

@LoisRForgeFlow LoisRForgeFlow left a comment

Choose a reason for hiding this comment

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

Code review 👍

Copy link

@JordiMForgeFlow JordiMForgeFlow left a comment

Choose a reason for hiding this comment

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

code review LGTM

@LoisRForgeFlow
Copy link

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 15.0-ocabot-merge-pr-74-by-LoisRForgeFlow-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit faa303b into OCA:15.0 Dec 13, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

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

@LoisRForgeFlow LoisRForgeFlow deleted the 15.0-fix-repair_stock_move-reservation branch December 13, 2024 14:53
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.

4 participants