-
-
Notifications
You must be signed in to change notification settings - Fork 214
[14.0][PERF] dynamic routing #722
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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,10 +1,14 @@ | ||
| # Copyright 2020 Camptocamp SA | ||
| # Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
| # Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
| import logging | ||
|
|
||
| from odoo import models | ||
| from odoo.tools.float_utils import float_compare | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class StockMove(models.Model): | ||
| _inherit = "stock.move" | ||
|
|
@@ -18,22 +22,33 @@ def _action_assign(self): | |
| unconfirmed_moves = unconfirmed_moves.filtered( | ||
| lambda m: m.state in ["confirmed", "partially_available"] | ||
| ) | ||
| unconfirmed_moves._apply_source_relocate() | ||
| if unconfirmed_moves: | ||
| unconfirmed_moves._apply_source_relocate() | ||
|
|
||
| def _apply_source_relocate(self): | ||
| # Read the `reserved_availability` field of the moves out of the loop | ||
| # to prevent unwanted cache invalidation when actually reserving. | ||
| reserved_availability = {move: move.reserved_availability for move in self} | ||
| roundings = {move: move.product_id.uom_id.rounding for move in self} | ||
| relocated_ids = [] | ||
| _logger.debug( | ||
| "Try to relocate moves of operation type (%s)" | ||
| % ", ".join(self.picking_type_id.mapped("name")) | ||
| ) | ||
| for move in self: | ||
| # We don't need to ignore moves with "_should_bypass_reservation() | ||
| # is True" because they are reserved at this point. | ||
| relocation = self.env["stock.source.relocate"]._rule_for_move(move) | ||
| if not relocation or relocation.relocate_location_id == move.location_id: | ||
| continue | ||
| move._apply_source_relocate_rule( | ||
| relocated = move._apply_source_relocate_rule( | ||
| relocation, reserved_availability, roundings | ||
| ) | ||
| if relocated: | ||
| relocated_ids.append(relocated.id) | ||
| if relocated_ids: | ||
| _logger.debug("Relocated moves %s" % relocated_ids) | ||
| self.browse(relocated_ids)._after_apply_source_relocate_rule() | ||
|
|
||
| def _apply_source_relocate_rule(self, relocation, reserved_availability, roundings): | ||
| self.ensure_one() | ||
|
|
@@ -63,3 +78,7 @@ def _apply_source_relocate_rule(self, relocation, reserved_availability, roundin | |
| new_move.location_id = relocation.relocate_location_id | ||
| self._action_assign() | ||
| return new_move | ||
|
|
||
| def _after_apply_source_relocate_rule(self): | ||
| # Hook for stock_dynamic_routing | ||
|
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. Not sure we need to mention this module in |
||
| return | ||
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,3 +1,4 @@ | ||
| * Guewen Baconnier <guewen.baconnier@camptocamp.com> | ||
| * Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
| * `Trobz <https://trobz.com>`_: | ||
| * Dung Tran <dungtd@trobz.com> |
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
1 change: 1 addition & 0 deletions
1
stock_move_source_relocate_dynamic_routing/readme/CONTRIBUTORS.rst
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 +1,2 @@ | ||
| * Guewen Baconnier <guewen.baconnier@camptocamp.com> | ||
| * Jacques-Etienne Baudoux (BCIM) <je@bcim.be> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it change something to check the recordset here?
Should we instead do this check in the
_apply_source_relocatemethod, ifselfis empty return.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No the method should not be called if not necessary.
Otherwise, all methods in odoo would start with
if not self: returnwhich is uglyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, here except the debug log the method will do nothing. And as the Odoo API tends to be "functional-programming" in some way it's OK to call methods on an object without thinking if it's empty or not.