-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6ad39d7
[ADD] base_multi_company: Create new module
lasley 91ce90f
10.0 base multi company lmi (#1)
lmignon 21c7c41
PR fixes (+1 squashed commit)
lasley 737dec5
[FIX] base_multi_company: Allow child_of/parent_of operator into sear…
lmignon 123cb62
- Remove depends as company_id is not stored anymore
1b854f5
OCA Transbot updated translations from Transifex
oca-transbot 0787cdb
[IMP] base_multi_company: Improve ReadMe
lasley 1fd4688
[MIG] *_multi_company: OpenUpgrade migration scripts
pedrobaeza 6adcdbd
Edit unit test + fix bug
acsonefho da5f3bf
[FIX] Insert in company_ids relation's table only ids of records that…
SimoRubi 952faa2
[UPD] Update base_multi_company.pot
oca-travis dbfbfd2
Translated using Weblate (Portuguese)
pedrocs-exo 81f46a4
[MIG] base_multi_company: Migration to 11.0
rodrigets 5c50b39
[UPD] Update base_multi_company.pot
oca-travis bcfee2c
[FIX] base_multi_company: Fix tests
pedrobaeza 9cee705
Update translation files
oca-transbot 636792e
[FIX] base_multi_company: Fix several things:
pedrobaeza b9ba8d0
[UPD] Update base_multi_company.pot
oca-travis 432acd1
Update translation files
oca-transbot ad34fea
[MIG] partner_multi_company: Finish migration to 11.0
pedrobaeza 1f1c34c
[UPD] Update base_multi_company.pot
oca-travis a92fac9
Update translation files
oca-transbot a9a8441
Migrate base_multi_company to v12
florian-dacosta 2be4f5a
Improve performance adding a techical field used in ir rules
florian-dacosta a474721
fixup! Migrate base_multi_company to v12
florian-dacosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright 2017 LasLabs Inc. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
from .hooks import create_company_assignment_view | ||
|
||
from . import models |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2017 LasLabs Inc. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
{ | ||
'name': 'Multi Company Base', | ||
'summary': 'Provides a base for adding multi-company support to models.', | ||
'version': '12.0.1.0.0', | ||
'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", | ||
'category': 'base', | ||
'website': 'https://github.com/OCA/multi-company', | ||
'license': 'LGPL-3', | ||
'installable': True, | ||
'application': False, | ||
'pre_init_hook': 'create_company_assignment_view', | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> | ||
# Copyright 2017 LasLabs Inc. | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import api, SUPERUSER_ID | ||
|
||
|
||
__all__ = [ | ||
'create_company_assignment_view', | ||
'post_init_hook', | ||
'uninstall_hook', | ||
] | ||
|
||
|
||
def create_company_assignment_view(cr): | ||
cr.execute(""" | ||
CREATE OR REPLACE VIEW res_company_assignment | ||
AS SELECT id, name, parent_id | ||
FROM res_company; | ||
""") | ||
|
||
|
||
def set_security_rule(env, rule_ref): | ||
"""Set the condition for multi-company in the security rule. | ||
|
||
:param: env: Environment | ||
:param: rule_ref: XML-ID of the security rule to change. | ||
""" | ||
rule = env.ref(rule_ref) | ||
if not rule: # safeguard if it's deleted | ||
return | ||
rule.write({ | ||
'active': True, | ||
'domain_force': ( | ||
"['|', ('company_ids', 'in', user.company_id.ids)," | ||
" ('visible_for_all_companies', '=', True)]" | ||
), | ||
}) | ||
|
||
|
||
def post_init_hook(cr, rule_ref, model_name): | ||
""" Set the `domain_force` and default `company_ids` to `company_id`. | ||
|
||
Args: | ||
cr (Cursor): Database cursor to use for operation. | ||
rule_ref (string): XML ID of security rule to write the | ||
`domain_force` from. | ||
model_name (string): Name of Odoo model object to search for | ||
existing records. | ||
""" | ||
with api.Environment.manage(): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
set_security_rule(env, rule_ref) | ||
# Copy company values | ||
model = env[model_name] | ||
table_name = model._fields['company_ids'].relation | ||
column1 = model._fields['company_ids'].column1 | ||
column2 = model._fields['company_ids'].column2 | ||
SQL = """ | ||
INSERT INTO %s | ||
(%s, %s) | ||
SELECT id, company_id FROM %s WHERE company_id IS NOT NULL | ||
""" % (table_name, column1, column2, model._table) | ||
env.cr.execute(SQL) | ||
|
||
|
||
def uninstall_hook(cr, rule_ref): | ||
""" Restore product rule to base value. | ||
|
||
Args: | ||
cr (Cursor): Database cursor to use for operation. | ||
rule_ref (string): XML ID of security rule to remove the | ||
`domain_force` from. | ||
""" | ||
with api.Environment.manage(): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
# Change access rule | ||
rule = env.ref(rule_ref) | ||
rule.write({ | ||
'active': False, | ||
'domain_force': ( | ||
" ['|', ('company_id', '=', user.company_id.id)," | ||
" ('company_id', '=', False)]" | ||
), | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_multi_company | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_product_template_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_partner_company_ids | ||
msgid "Companies" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id | ||
msgid "Company" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_display_name | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_id | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract___last_update | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment___last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_multi_company_abstract | ||
msgid "Multi-Company Abstract" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_name | ||
msgid "Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id | ||
msgid "Parent" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_res_company_assignment | ||
msgid "res.company.assignment" | ||
msgstr "" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_multi_company | ||
# | ||
# Translators: | ||
# OCA Transbot <transbot@odoo-community.org>, 2017 | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 10.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-12-16 02:03+0000\n" | ||
"PO-Revision-Date: 2017-12-16 02:03+0000\n" | ||
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" | ||
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" | ||
"Language: es\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_product_template_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_partner_company_ids | ||
msgid "Companies" | ||
msgstr "Compañías" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id | ||
msgid "Company" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_display_name | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_id | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract___last_update | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment___last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_multi_company_abstract | ||
msgid "Multi-Company Abstract" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_name | ||
msgid "Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id | ||
msgid "Parent" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_res_company_assignment | ||
msgid "res.company.assignment" | ||
msgstr "" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_multi_company | ||
# | ||
# Translators: | ||
# OCA Transbot <transbot@odoo-community.org>, 2017 | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 10.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-12-16 02:03+0000\n" | ||
"PO-Revision-Date: 2017-12-16 02:03+0000\n" | ||
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n" | ||
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" | ||
"Language: fr\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=(n > 1);\n" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_product_template_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_partner_company_ids | ||
msgid "Companies" | ||
msgstr "Sociétés" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id | ||
msgid "Company" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_display_name | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_id | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract___last_update | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment___last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_multi_company_abstract | ||
msgid "Multi-Company Abstract" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_name | ||
msgid "Name" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id | ||
msgid "Parent" | ||
msgstr "" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_res_company_assignment | ||
msgid "res.company.assignment" | ||
msgstr "" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_multi_company | ||
# | ||
# Translators: | ||
# Bole <bole@dajmi5.com>, 2018 | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 10.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-01-27 07:37+0000\n" | ||
"PO-Revision-Date: 2018-01-27 07:37+0000\n" | ||
"Last-Translator: Bole <bole@dajmi5.com>, 2018\n" | ||
"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" | ||
"Language: hr\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" | ||
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_product_template_company_ids | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_partner_company_ids | ||
msgid "Companies" | ||
msgstr "Tvrtke" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id | ||
msgid "Company" | ||
msgstr "Tvrtka" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_display_name | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_display_name | ||
msgid "Display Name" | ||
msgstr "Naziv za prikaz" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_id | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_id | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract___last_update | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment___last_update | ||
msgid "Last Modified on" | ||
msgstr "Zadnje modificirano" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_multi_company_abstract | ||
msgid "Multi-Company Abstract" | ||
msgstr "Multi Tvrtka - Apstraktno" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_name | ||
msgid "Name" | ||
msgstr "Naziv" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id | ||
#, fuzzy | ||
msgid "Parent" | ||
msgstr "ID Nadređenog" | ||
|
||
#. module: base_multi_company | ||
#: model:ir.model,name:base_multi_company.model_res_company_assignment | ||
msgid "res.company.assignment" | ||
msgstr "res.company.assignment" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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