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

[12.0] migrage base multi company + improve performance #123

Merged
merged 25 commits into from
Sep 20, 2019

Conversation

florian-dacosta
Copy link
Contributor

Standard migration + improve performance applying idea proposed by @sbidoul in #109

@Cedric-Pigeon

lasley and others added 23 commits May 4, 2019 15:59
* Create new module to provide base multi company logic and mixin
* Add deactivation by company mixin
* Add company_id/ids handling
* Add break after company is found
Squashed commits:
[854cc36] Increase test coverage
[770bd71] Revert hook view create back to model init
[40e803e] Fix apples and oranges
[7a4dfb4] Use registry correctly
[6e9f170] Switch company_id to computed & move company aliased view creation to post init hook
[faa4fc9] Remove active functionality
[fecfb59] Add explicit tests for active and inactive searches
* Revert "Revert hook view create back to model init"

This reverts commit 770bd71.

* [FIX] base_multi_company: Always create the view into a pre_init_hook to avoid error in log
Squashed commits:
[4c17d04] auto_join company_ids
…ch domain on company_id/company_ids (+1 squashed commit)

Squashed commits:
[fe161fe] [ADD] setup.py
- Test if a company is set in inverse method (+1 squashed commit)
Squashed commits:
[d670f30] [FIX] fix init hooks as company_id is not stored anymore
* Add implementation instructions to ReadMe
[FIX] Fix issue based on the computation of company_id for multi_company_abstract models

[FIX] Fix issue based on the computation of company_id for multi_company_abstract models

[FIX] Fix issue based on the computation of company_id for multi_company_abstract models

[FIX] Bad branch version pushed before

[FIX] Bad branch version pushed before

[FIX] manifest

Fix flake

Flake8 on OCA tests
Currently translated at 88.9% (8 of 9 strings)

Translation: multi-company-10.0/multi-company-10.0-base_multi_company
Translate-URL: https://translation.odoo-community.org/projects/multi-company-10-0/multi-company-10-0-base_multi_company/pt/
Odoo now checks if the user who creates the transient model is the same that is accessing
its data, so we need to create it with the same user.
Updated by Update PO files to match POT (msgmerge) hook in Weblate.
* Abstract model shouldn't have default for `company_ids`. It will be got by
  default `company_id` value.
* Record rule based on `company_id` makes the evaluation slower. Switch to `company_ids` field.
* Add `@api.depends` to `company_id` computation for proper refresh.
* Fix tests that were not correct but luckily previously suceeded. Now that other code has
  been removed, they have been uncovered.
Updated by Update PO files to match POT (msgmerge) hook in Weblate.
Updated by Update PO files to match POT (msgmerge) hook in Weblate.
@pedrobaeza pedrobaeza added this to the 12.0 milestone May 13, 2019
@OCA-git-bot OCA-git-bot mentioned this pull request May 13, 2019
9 tasks
Copy link
Member

@tbaden tbaden left a comment

Choose a reason for hiding this comment

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

please use the fragment readme

@florian-dacosta
Copy link
Contributor Author

@tbaden There is no "Implementation" section and I don't really see a suitable section in the readme files for this part. Any idea?

@pedrobaeza
Copy link
Member

Put it inside usage section with ~~~~ underlining.

@florian-dacosta
Copy link
Contributor Author

@pedrobaeza Thanks for the hint, I'll do that

@florian-dacosta
Copy link
Contributor Author

@tbaden Readme has been split.

Copy link
Member

@tbaden tbaden left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@LoisRForgeFlow LoisRForgeFlow left a comment

Choose a reason for hiding this comment

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

LGTM

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

return
rule.write({
'active': True,
'domain_force': (
Copy link
Member

@kittiu kittiu Jun 18, 2019

Choose a reason for hiding this comment

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

@florian-dacosta I am doing #136 which has error from this rule writing. In partner_multi_company, it will error when I create a new company which also create res.partner.
Can you change to following, because normally we need to have term "or company_id = False" to avoid that error.

Suggested change
'domain_force': (
'domain_force': (
"['|', '|', ('company_ids', 'in', user.company_id.ids),"
" ('visible_for_all_companies', '=', True), ('company_id', '=', False)]"
),

Copy link
Member

Choose a reason for hiding this comment

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

I think now that a better technique is to duplicate the rule, and deactivate the old one, and on uninstall, delete the new one, and activate the old.

Copy link
Member

Choose a reason for hiding this comment

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

Allow me to confirm my understanding,
The domain_force in this base_multi_company should stay like this, and the changes per mentioned goes to partner_multi_company, correct?

Copy link
Member

Choose a reason for hiding this comment

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

Also, this one can be merged soon to fix dependency? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pedrobaeza I think the problem is not the modification of the rule, but the value in domain_force that raise an error when it should not, in a specific case.
It is True that it could be cleaner to do it this way (activate/deactivate) but it won't change this particular problem.

@kittiu I checked a little, I am not sure why it fails exactly, and only in this particular case.
It seems the visible_for_all_companies field is computed too late...
Anyway, I don't think that changing the domain for all models/modules is the good solution.
Indeed, the changes have been made to improve the poor performance of this rule, and adding ('company_id', '=', False) once again revert the performance improvments.

So the domain could eventually be changed in partner_multi_company, to fix this very particular problem, but it will have an impact on performance.

Another ideal which could be implemented in this base module is to add a default value True to visible_for_all_companies field.
This way, the record rule won't fail during creation if visible_for_all_companies is not computed yet.
And if it is computed, it will get the right value...
@pedrobaeza any comment about this?

Copy link
Member

@kittiu kittiu Jun 19, 2019

Choose a reason for hiding this comment

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

@florian-dacosta as you mentioned about default=True, I try add 2 lines in your abstract class, and it works fine.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kittiu Actually the second line is not necessary.
I made the change

@kittiu kittiu mentioned this pull request Jun 18, 2019
1 task
@florian-dacosta
Copy link
Contributor Author

Test are failing, but it seems it is not because of this module.
Still, I don't understand why...

@kittiu
Copy link
Member

kittiu commented Jun 24, 2019

@florian-dacosta I also can't find the exact problem. But I found that, if we run test_multi_company_abstract, we will get this error,

2019-06-24 05:34:21,915 5396 CRITICAL odoo12_base_multi_company odoo.service.server: Failed to initialize database `odoo12_base_multi_company`. 
Traceback (most recent call last):
  File "/home/kittiu/workspace/odoo12/odoo/service/server.py", line 1116, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/home/kittiu/workspace/odoo12/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/home/kittiu/workspace/odoo12/odoo/modules/loading.py", line 497, in load_modules
    registry.init_models(cr, list(models_to_check), {'models_to_check': True})
  File "/home/kittiu/workspace/odoo12/odoo/modules/registry.py", line 301, in init_models
    func()
  File "/home/kittiu/workspace/odoo12/odoo/models.py", line 281, in _reflect
    self.env['ir.model']._reflect_model(self)
  File "/home/kittiu/workspace/odoo12/odoo/addons/base/models/ir_model.py", line 274, in _reflect_model
    ids = query_update(cr, self._table, params, ['model'])
  File "/home/kittiu/workspace/odoo12/odoo/addons/base/models/ir_model.py", line 65, in query_update
    cr.execute(query, values)
  File "/home/kittiu/workspace/odoo12/odoo/sql_db.py", line 147, in wrapper
    raise psycopg2.OperationalError(msg)
psycopg2.OperationalError: Unable to use a closed cursor.

@florian-dacosta
Copy link
Contributor Author

Well I was wrong, the failing was really because of this module.
I did not meet any error in local using pytests, that's why I did not see it.
Anyway, I have fixed the issue, I think this PR is now ready to merge.
@kittiu Could do make a review?

@kittiu
Copy link
Member

kittiu commented Jul 7, 2019

@florian-dacosta thanks for the fix. Now it works, and also works with partner_multi_company too #136

@florian-dacosta
Copy link
Contributor Author

@kittiu
Since you seem satisfied with the migration ,could you approve the PR?

@kittiu
Copy link
Member

kittiu commented Sep 10, 2019

@florian-dacosta how to approve, I don't have rights :p

@florian-dacosta
Copy link
Contributor Author

@kittiu Of course you have!
If you click on "file changed", on the top of the PR, to see the changes made in the PR, you will see a button named "Review changes".
Then you can comment, approve, or request changes, depending if you think it is all good or not.

@florian-dacosta
Copy link
Contributor Author

@pedrobaeza Could you merge this?

@pedrobaeza
Copy link
Member

/ocabot merge

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 12.0-ocabot-merge-pr-123-by-pedrobaeza-bump-no, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Sep 20, 2019
Signed-off-by pedrobaeza
@OCA-git-bot OCA-git-bot merged commit a474721 into OCA:12.0 Sep 20, 2019
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 2ff8a10. Thanks a lot for contributing to OCA. ❤️

@amkarthik
Copy link
Member

@pedrobaeza @florian-dacosta
It seems that this fix is missing v13 branch
Any specific reason for that?

@pedrobaeza
Copy link
Member

This is not a fix, but a migration PR. Anyway, you can do a PR with anything you consider for improving the module.

@amkarthik
Copy link
Member

@pedrobaeza
Thanks

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

Successfully merging this pull request may close these issues.

None yet