-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[16.0][IMP] sale_order_line_cancel: Refactor and create base addon #3894
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
Merged
OCA-git-bot
merged 4 commits into
OCA:16.0
from
mt-software-de:16-refactor-sale_order_line_cancel
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c4bfa57
[IMP] sale_order_line_cancel: Remove dependency to sale_stock to act …
mt-software-de 6ff2931
[IMP] sale_order_line_cancel: Add Laurent Mignon as contributor
mt-software-de b7deb02
[ADD] sale_order_line_cancel_sale_stock: Cancel stock moves on sale o…
mt-software-de b78f15e
[REF] sale_order_line_cancel: Remove unnecessary method from wizard
mt-software-de File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| from . import sale_order_line | ||
| from . import stock_move | ||
| from . import sale_order | ||
| from . import res_company | ||
| from . import res_config_settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| # Copyright 2020 ACSONE SA/NV | ||
| # Copyright 2025 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import _, api, fields, models | ||
| from odoo.tools import float_compare | ||
|
|
||
|
|
@@ -30,35 +29,25 @@ def _compute_can_cancel_remaining_qty(self): | |
| "Product Unit of Measure" | ||
| ) | ||
| for rec in self: | ||
| rec.can_cancel_remaining_qty = ( | ||
| float_compare( | ||
| rec.product_qty_remains_to_deliver, 0, precision_digits=precision | ||
| ) | ||
| == 1 | ||
| and rec.state in ("sale", "done") | ||
| and rec.qty_delivered_method == "stock_move" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is now gone, imo it is not needed to check for |
||
| ) | ||
| rec.can_cancel_remaining_qty = float_compare( | ||
| rec.product_qty_remains_to_deliver, 0, precision_digits=precision | ||
| ) == 1 and rec.state in ("sale", "done") | ||
|
|
||
| @api.depends("qty_to_deliver", "product_qty_canceled") | ||
| @api.depends( | ||
| "product_uom_qty", | ||
| "qty_delivered", | ||
| "product_qty_canceled", | ||
| ) | ||
| def _compute_product_qty_remains_to_deliver(self): | ||
| for line in self: | ||
| qty_remaining = max(0, line.qty_to_deliver - line.product_qty_canceled) | ||
| qty_to_deliver = line.product_uom_qty - line.qty_delivered | ||
| qty_remaining = max(0, qty_to_deliver - line.product_qty_canceled) | ||
| line.product_qty_remains_to_deliver = qty_remaining | ||
|
|
||
| def _get_moves_to_cancel(self): | ||
| lines = self.filtered(lambda l: l.qty_delivered_method == "stock_move") | ||
| return lines.move_ids.filtered(lambda m: m.state not in ("done", "cancel")) | ||
|
|
||
| def _check_moves_to_cancel(self, moves): | ||
| """Override this method to add checks before cancel""" | ||
| self.ensure_one() | ||
|
|
||
| def _update_qty_canceled(self): | ||
| """Update SO line qty canceled only when all remaining moves are canceled""" | ||
| for line in self: | ||
| if line._get_moves_to_cancel(): | ||
| continue | ||
mt-software-de marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| qty_to_deliver = line.qty_to_deliver | ||
| qty_to_deliver = line.product_uom_qty - line.qty_delivered | ||
| vals = {"product_qty_canceled": qty_to_deliver} | ||
| if ( | ||
| line.state == "sale" | ||
|
|
@@ -69,14 +58,12 @@ def _update_qty_canceled(self): | |
|
|
||
| def cancel_remaining_qty(self): | ||
| lines = self.filtered(lambda l: l.can_cancel_remaining_qty) | ||
| lines._update_qty_canceled() | ||
| for line in lines: | ||
| moves_to_cancel = line._get_moves_to_cancel() | ||
| line._check_moves_to_cancel(moves_to_cancel) | ||
| moves_to_cancel._action_cancel() | ||
| line.order_id.message_post( | ||
| body=_( | ||
| "<b>%(product)s</b>: The order line has been canceled", | ||
| product=line.product_id.display_name, | ||
| ) | ||
| ) | ||
| return True | ||
| return lines | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| * Sylvain Van Hoof <sylvain@okia.be> | ||
| * Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
| * Souheil Bejaoui <souheil.bejaoui@acsone.eu.com> | ||
| * Laurent Mignon <laurent.mignon@acsone.eu> | ||
| * Michael Tietz (MT Software) <mtietz@mt-software.de> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.