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
[IMP] stock: Add hybrid procure method 'mts_else_mto' #32642
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -44,10 +44,13 @@ class StockRule(models.Model): | |
route_id = fields.Many2one('stock.location.route', 'Route', required=True, ondelete='cascade') | ||
procure_method = fields.Selection([ | ||
('make_to_stock', 'Take From Stock'), | ||
('make_to_order', 'Trigger Another Rule')], string='Move Supply Method', | ||
('make_to_order', 'Trigger Another Rule'), | ||
('mts_else_mto', 'Take From Stock, if unavailable, Trigger Another Rule')], string='Move Supply Method', | ||
default='make_to_stock', required=True, | ||
help="""Create Procurement: A procurement will be created in the source location and the system will try to find a rule to resolve it. The available stock will be ignored. | ||
Take from Stock: The products will be taken from the available stock.""") | ||
help="Take From Stock: the products will be taken from the available stock of the source location.\n" | ||
"Trigger Another Rule: the system will try to find a stock rule to bring the products in the source location. The available stock will be ignored.\n" | ||
"Take From Stock, if Unavailable, Trigger Another Rule: the products will be taken from the available stock of the source location." | ||
"If there is no stock available, the system will try to find a rule to bring the products in the source location.") | ||
route_sequence = fields.Integer('Route Sequence', related='route_id.sequence', store=True, readonly=False) | ||
picking_type_id = fields.Many2one( | ||
'stock.picking.type', 'Operation Type', | ||
|
@@ -109,6 +112,8 @@ def _get_message_dict(self): | |
suffix = "" | ||
if self.procure_method == 'make_to_order' and self.location_src_id: | ||
suffix = _("<br>A need is created in <b>%s</b> and a rule will be triggered to fulfill it.") % (source) | ||
if self.procure_method == 'mts_else_mto' and self.location_src_id: | ||
suffix = _("<br>If the products are not available in <b>%s</b>, a rule will be triggered to bring products in this location.") % source | ||
message_dict = { | ||
'pull': _('When products are needed in <b>%s</b>, <br/> <b>%s</b> are created from <b>%s</b> to fulfill the need.') % (destination, operation, source) + suffix, | ||
'push': _('When products arrive in <b>%s</b>, <br/> <b>%s</b> are created to send them in <b>%s</b>.') % (source, operation, destination) | ||
|
@@ -167,6 +172,21 @@ def _push_prepare_move_copy_values(self, move_to_copy, new_date): | |
} | ||
return new_move_vals | ||
|
||
def _get_procure_method(self, product, qty_needed, location): | ||
""" When the procure_method of the rule is 'mts_else_mto', we need to get the quantity forcasted to know if | ||
we have to apply MTS or MTO on the moves of the procurement. | ||
:param product: The product of the move | ||
:param qty_needed: The amount needed of that product | ||
:param location: The location source of the product | ||
:return: The procure_method to apply on the move | ||
""" | ||
if self.procure_method == 'mts_else_mto': | ||
qty_available = product.with_context(location=location.id).virtual_available | ||
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. can't you batch virtual_available? read it for all products where the rule is mts_then_mto and pass the values there |
||
if float_compare(qty_needed, qty_available, precision_rounding=product.uom_id.rounding) <= 0: | ||
return 'make_to_stock' | ||
return 'make_to_order' | ||
return self.procure_method | ||
|
||
@api.model | ||
def _run_pull(self, procurements): | ||
moves_values_by_company = defaultdict(list) | ||
|
@@ -219,7 +239,7 @@ def _get_stock_move_values(self, product_id, product_qty, product_uom, location_ | |
'location_dest_id': location_id.id, | ||
'move_dest_ids': values.get('move_dest_ids', False) and [(4, x.id) for x in values['move_dest_ids']] or [], | ||
'rule_id': self.id, | ||
'procure_method': self.procure_method, | ||
'procure_method': self._get_procure_method(product_id, product_qty, self.location_src_id), | ||
'origin': origin, | ||
'picking_type_id': self.picking_type_id.id, | ||
'group_id': group_id, | ||
|
This file contains 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 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
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.
newline