Skip to content

[15.0][FIX] mrp_project: assign parent MO project to child MO#159

Open
IriaAlonso wants to merge 1 commit into15.0from
15.0-fix-mrp_project-set_project_mo_child
Open

[15.0][FIX] mrp_project: assign parent MO project to child MO#159
IriaAlonso wants to merge 1 commit into15.0from
15.0-fix-mrp_project-set_project_mo_child

Conversation

@IriaAlonso
Copy link
Copy Markdown
Contributor

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

@dalonsod
Copy link
Copy Markdown
Contributor

Thanks @IriaAlonso . I'll wait for @DantePereyra 's review...

Copy link
Copy Markdown
Contributor

@DantePereyra DantePereyra left a comment

Choose a reason for hiding this comment

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

Some minor suggestions

Comment thread mrp_project/models/mrp_production.py
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
@IriaAlonso IriaAlonso force-pushed the 15.0-fix-mrp_project-set_project_mo_child branch from a26578b to c5cf87f Compare April 28, 2026 07:24
Comment on lines +34 to +35
if production._get_sources():
production.project_id = production._get_sources().project_id
Copy link
Copy Markdown
Contributor

@dalonsod dalonsod Apr 28, 2026

Choose a reason for hiding this comment

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

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
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants