Skip to content
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

[FIX] fields: inherited fields keep parent's modules #30116

Closed

Conversation

mart-e
Copy link
Contributor

@mart-e mart-e commented Jan 10, 2019

On a field created through a _inherits, the fields on the child model did not
benefit from the parent _modules information.

If two models are created in module base

class Partner(models.Model):
    _name = 'res.partner'

class User(models.Model):
    _inherits = {'res.partner': 'partner_id'}

   partner_id = fields.Many2one('res.partner')

and a second module auth_signup adds a field on the parent model

class ResPartner(models.Model):
    _inherit = 'res.partner'

    signup_token = fields.Char()

Both res.users and res.partner should have an ir.model.data created:

  • auth_signup.field_res_partner__signup_token was correctly created but
  • auth_signup.field_res_users__signup_token was not created.

The reason is was, in the call to _reflect_model, since 574f4c3, the
creation of ir.model.data is based on the set field._modules.
However, the field res.partner.signup_token did not propagate its _modules value
to the related field res.users.signup_token.

With this patch, both ir.model.data are created.

This allow a proper uninstallation of fields as well as translations.

This PR also adds a test to test the scenario fixed.

Creating a new test module is necessary as the bug is only revealed when the
current module is different than the model._original_module (cf c9837ac)

Before that commit, was failing only the second search of test_ir_model_data_inherits_depends.
Add other test to avoid regression of the bugs corrected at 574f4c3 and c9837ac.

On a field created through a _inherits, the fields on the child model did not
benefit from the parent _modules information.

If two models are created in module base

class Partner(models.Model):
    _name = 'res.partner'

class User(models.Model):
    _inherits = {'res.partner': 'partner_id'}

   partner_id = fields.Many2one('res.partner')

and a second module auth_signup adds a field on the parent model

class ResPartner(models.Model):
    _inherit = 'res.partner'

    signup_token = fields.Char()

Both res.users and res.partner should have an ir.model.data create

base_setup.field_res_partner__signup_token was correctly created but
base_setup.field_res_users__signup_token was not created

The reason is was, in the call to _reflect_model, since 574f4c3, the
creation of ir.model.data is based on the field._modules
However, the field res.partner.signup_token did not propagate its _modules value
to the related field res.users.signup_token

With this patch, both ir.model.data are created.

This allow a proper uninstallation of fields as well as translation.
@mart-e mart-e force-pushed the 12.0-inherits-fields-different-module-mat branch 2 times, most recently from eba8527 to 58b9c4b Compare January 10, 2019 15:11
Copy link
Member

@rco-odoo rco-odoo left a comment

Choose a reason for hiding this comment

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

Good to me.

Can you add the usual licencing comment on top of you files?

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

This commit adds a test to test the scenario fixed in the parent commit.

Creating a new test module is necessary as the bug is only revealed when the
current module is different than the model._original_module (cf c9837ac)

Before that commit, was failing only the second search of
test_ir_model_data_inherits_depends.
Add other test to avoid regression of the bugs corrected at 574f4c3 and c9837ac
@mart-e mart-e force-pushed the 12.0-inherits-fields-different-module-mat branch from 58b9c4b to 1eedff4 Compare January 10, 2019 15:28
@mart-e
Copy link
Contributor Author

mart-e commented Jan 10, 2019

robodoo r+

@C3POdoo C3POdoo added the RD research & development, internal work label Jan 10, 2019
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Jan 10, 2019
@robodoo
Copy link
Contributor

robodoo commented Jan 10, 2019

Because this PR has multiple commits, I need to know how to merge it:

  • merge to merge directly, using the PR as merge commit message
  • rebase-merge to rebase and merge, using the PR as merge commit message
  • rebase-ff to rebase and fast-forward

@KangOl
Copy link
Contributor

KangOl commented Jan 11, 2019

@robodoo rebase-ff

@robodoo
Copy link
Contributor

robodoo commented Jan 11, 2019

Merge method set to rebase and fast-forward

robodoo pushed a commit that referenced this pull request Jan 11, 2019
This commit adds a test to test the scenario fixed in the parent commit.

Creating a new test module is necessary as the bug is only revealed when the
current module is different than the model._original_module (cf c9837ac)

Before that commit, was failing only the second search of
test_ir_model_data_inherits_depends.
Add other test to avoid regression of the bugs corrected at 574f4c3 and c9837ac

closes #30116
@robodoo
Copy link
Contributor

robodoo commented Jan 11, 2019

Merged, thanks!

@robodoo robodoo closed this Jan 11, 2019
@mart-e mart-e deleted the 12.0-inherits-fields-different-module-mat branch January 14, 2019 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI 🤖 Robodoo has seen passing statuses RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants