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

[IMP] Add tests for base_location name_search #585

Merged
merged 4 commits into from
May 16, 2018

Conversation

WohthaN
Copy link
Contributor

@WohthaN WohthaN commented May 4, 2018

Continuing here the discussion/development of MR
#582
which was closed by mistake.

@pedrobaeza
Copy link
Member

But the name_search is not modified in this PR...

@WohthaN
Copy link
Contributor Author

WohthaN commented May 4, 2018

Now it could be ok!

@pedrobaeza
Copy link
Member

And change the module version number...

@pedrobaeza
Copy link
Member

The problem with this PR is that you are breaking inheritance. The problem with name_search is that is very tricky. Check how we were force to do it in res.partner for l10n_es_partner:

https://github.com/OCA/l10n-spain/blob/59f39578f6de75a535c15e58428501257be2cf41/l10n_es_partner/models/res_partner.py#L34-L54

@WohthaN
Copy link
Contributor Author

WohthaN commented May 5, 2018

Now I'm really confused, what do you mean it breaks inheritance?

It hase the same interface as in models.Model, and it's actually implemented exactly in the same way as in models.Model, pretty much line by line (it just skips access rights tests that in this case are not necessary)!

What am I missing?

For reference, current models.Model implementation is:

    @api.model
    def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
        # private implementation of name_search, allows passing a dedicated user
        # for the name_get part to solve some access rights issues
        args = list(args or [])
        # optimize out the default criterion of ``ilike ''`` that matches everything
        if not self._rec_name:
            _logger.warning("Cannot execute name_search, no _rec_name defined on %s", self._name)
        elif not (name == '' and operator == 'ilike'):
            args += [(self._rec_name, operator, name)]
        access_rights_uid = name_get_uid or self._uid
        ids = self._search(args, limit=limit, access_rights_uid=access_rights_uid)
        recs = self.browse(ids)
        return recs.sudo(access_rights_uid).name_get()

@pedrobaeza
Copy link
Member

That's the base model. When you don't call super in your module, and there's other module overwriting the same method, both conflict and you don't know which of the 2 is going to be executed.

@WohthaN
Copy link
Contributor Author

WohthaN commented May 6, 2018

Your argument is actually true for each and every method in a class, and for the little I understand it's a problem intrinsic to the the multi-inheritance scheme odoo is using which bypasses normal pythonic inheritance (in a sane world, inheritance should be predictable, deterministic and hopefully in cortrol of the programmer).

The solution you pointed in l10n-spain is not really solving the problem you described: it's a workaround that actually leaves you with partially undefined behaviour anyway, since you don't know what results you get first if someone else is exending ResPartner again, in the end virtually any subclass is adding search results in a potentially random order and nobody knows what's really coming out of that name_search call. Besides, in that example super is called only if the new search is not producing enough results, not even everytime, so the original behaviour is not always maintained.

Moreover, in the example you pointed out, an existing model, ResPartner, is being extended, hence you do want to extend rather than replace the behaviour of the model being extended. BetterZip is not extending an existing model, it's introducing a new one, so this class is actually the one defining the behaviour of this model, not the one extending it. Your argument could be applied to any class exending BetterZip though...

@pedrobaeza
Copy link
Member

You are totally right, as the model is first defined here! Sorry for the noise.

@WohthaN
Copy link
Contributor Author

WohthaN commented May 6, 2018

No worries, and thanks for the thorough review! Your comments forced me to go back to check and learn lots of stuff i overlooked, which in the end is really really helpful! :)

@pedrobaeza pedrobaeza merged commit c83f32a into OCA:11.0 May 16, 2018
BT-rmartin referenced this pull request in brain-tec/partner-contact May 28, 2018
[FIX] disable position editing on contact

- This is just to see all positions
- If we want to add position go to one company and add contact linked to this partner

[ADD] setup.py [ci skip]

[MIG][11.0] Migration of partner_affiliate to v11 (#579)

* [MIG] Migration of partner_affiliate to v11

* Fixing use of @Class and do not inheriting address from parent company

* Improving legibility and details of fields

* Fixing travis errors

[ADD] setup.py

[IMP] base_location: Include onchange for state

Incredibly not included in Odoo core.

[IMP] base_location: name_search improvement (#585)

Fixing travis errors
aitorbouzas pushed a commit to aitorbouzas/partner-contact that referenced this pull request Oct 8, 2018
aitorbouzas pushed a commit to aitorbouzas/partner-contact that referenced this pull request Oct 8, 2018
pedrobaeza pushed a commit to aitorbouzas/partner-contact that referenced this pull request Oct 16, 2018
victormmtorres pushed a commit to Tecnativa/partner-contact that referenced this pull request Mar 25, 2019
pedrobaeza pushed a commit to Tecnativa/partner-contact that referenced this pull request Sep 30, 2019
pedrobaeza pushed a commit to Tecnativa/partner-contact that referenced this pull request Sep 30, 2019
pedrobaeza pushed a commit to Tecnativa/partner-contact that referenced this pull request Oct 18, 2020
pedrobaeza pushed a commit to Tecnativa/partner-contact that referenced this pull request Oct 7, 2022
victor-champonnois pushed a commit to coopiteasy/partner-contact that referenced this pull request Feb 3, 2023
beagle-cloud pushed a commit to DynAppsNV/partner-contact that referenced this pull request Jan 30, 2024
beagle-cloud pushed a commit to DynAppsNV/partner-contact that referenced this pull request Feb 26, 2024
edlopen pushed a commit to moduon/partner-contact that referenced this pull request Mar 1, 2024
edlopen pushed a commit to moduon/partner-contact that referenced this pull request Mar 1, 2024
Kimkhoi3010 pushed a commit to Kimkhoi3010/partner-contact that referenced this pull request Oct 14, 2024
Kimkhoi3010 pushed a commit to Kimkhoi3010/partner-contact that referenced this pull request Oct 29, 2024
Kimkhoi3010 pushed a commit to Kimkhoi3010/partner-contact that referenced this pull request Oct 29, 2024
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