[15.0][FIX] mrp_project: assign parent MO project to child MO#159
Open
IriaAlonso wants to merge 1 commit into15.0from
Open
[15.0][FIX] mrp_project: assign parent MO project to child MO#159IriaAlonso wants to merge 1 commit into15.0from
IriaAlonso wants to merge 1 commit into15.0from
Conversation
Contributor
|
Thanks @IriaAlonso . I'll wait for @DantePereyra 's review... |
DantePereyra
requested changes
Apr 24, 2026
Contributor
DantePereyra
left a comment
There was a problem hiding this comment.
Some minor suggestions
Comment on lines
+30
to
+35
| @api.model | ||
| def create(self, values): | ||
| production = super().create(values) | ||
| if production.origin: | ||
| production.project_id = self.env['mrp.production'].search([("name", "=", production.origin)]).project_id | ||
| return production |
Contributor
There was a problem hiding this comment.
Suggested change
| @api.model | |
| def create(self, values): | |
| production = super().create(values) | |
| if production.origin: | |
| production.project_id = self.env['mrp.production'].search([("name", "=", production.origin)]).project_id | |
| return production | |
| @api.model_create_multi | |
| def create(self, vals_list): | |
| for vals in vals_list: | |
| origin = vals.get('origin') | |
| if origin: | |
| vals['project_id'] = self.env['mrp.production'].search([("name", "=", origin)]).project_id.id | |
| return super().create(vals_list) |
Could you try this if it gets same result?
Contributor
Author
There was a problem hiding this comment.
Suggested change
| @api.model | |
| def create(self, values): | |
| production = super().create(values) | |
| if production.origin: | |
| production.project_id = self.env['mrp.production'].search([("name", "=", production.origin)]).project_id | |
| return production | |
| @api.model | |
| def create(self, vals_list): | |
| origin = vals_list.get('origin') | |
| if origin: | |
| vals_list['project_id'] = self.env['mrp.production'].search([("name", "=", origin)]).project_id.id | |
| return super().create(vals_list) |
In this way, we would get the same result
When a project is modified in a MO that has child MOs, the changes are automatically applied to those child MOs as well. This only happens if the child MOs already exist; if they are generated later, the changes are not applied. This fix resolves that issue.
a26578b to
c5cf87f
Compare
dalonsod
reviewed
Apr 28, 2026
Comment on lines
+34
to
+35
| if production._get_sources(): | ||
| production.project_id = production._get_sources().project_id |
Contributor
There was a problem hiding this comment.
This code should be properly protected. As we know, _get_sources() could return more than one MO, then production._get_sources().project_id could return a recordset with two or more project, an this code could raise an error. Better try this (not tested, we inspect of only one project is available before assigning it):
Suggested change
| if production._get_sources(): | |
| production.project_id = production._get_sources().project_id | |
| project_ids = production._get_sources().project_id | |
| production.project_id = ( | |
| len(project_ids) == 1 | |
| and project_ids | |
| or False | |
| ) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a project is modified in a MO that has child MOs, the changes are automatically applied to those child MOs as well.
This only happens if the child MOs already exist;
if they are generated later, the changes are not applied. This fix resolves that issue.
@dalonsod