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
Merged
Show file tree
Hide file tree
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 Apr 20, 2017
91ce90f
10.0 base multi company lmi (#1)
lmignon May 5, 2017
21c7c41
PR fixes (+1 squashed commit)
lasley May 5, 2017
737dec5
[FIX] base_multi_company: Allow child_of/parent_of operator into sear…
lmignon May 10, 2017
123cb62
- Remove depends as company_id is not stored anymore
May 10, 2017
1b854f5
OCA Transbot updated translations from Transifex
oca-transbot May 20, 2017
0787cdb
[IMP] base_multi_company: Improve ReadMe
lasley Sep 9, 2017
1fd4688
[MIG] *_multi_company: OpenUpgrade migration scripts
pedrobaeza Dec 15, 2017
6adcdbd
Edit unit test + fix bug
acsonefho Mar 27, 2018
da5f3bf
[FIX] Insert in company_ids relation's table only ids of records that…
SimoRubi Apr 21, 2018
952faa2
[UPD] Update base_multi_company.pot
oca-travis Jun 23, 2018
dbfbfd2
Translated using Weblate (Portuguese)
pedrocs-exo Jul 26, 2018
81f46a4
[MIG] base_multi_company: Migration to 11.0
rodrigets Jul 31, 2018
5c50b39
[UPD] Update base_multi_company.pot
oca-travis Aug 2, 2018
bcfee2c
[FIX] base_multi_company: Fix tests
pedrobaeza Nov 16, 2018
9cee705
Update translation files
oca-transbot Dec 9, 2018
636792e
[FIX] base_multi_company: Fix several things:
pedrobaeza Jan 17, 2019
b9ba8d0
[UPD] Update base_multi_company.pot
oca-travis Jan 17, 2019
432acd1
Update translation files
oca-transbot Jan 17, 2019
ad34fea
[MIG] partner_multi_company: Finish migration to 11.0
pedrobaeza Jan 19, 2019
1f1c34c
[UPD] Update base_multi_company.pot
oca-travis Jan 19, 2019
a92fac9
Update translation files
oca-transbot Jan 19, 2019
a9a8441
Migrate base_multi_company to v12
florian-dacosta May 4, 2019
2be4f5a
Improve performance adding a techical field used in ir rules
florian-dacosta May 4, 2019
a474721
fixup! Migrate base_multi_company to v12
florian-dacosta Jul 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base_multi_company/__init__.py
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
18 changes: 18 additions & 0 deletions base_multi_company/__manifest__.py
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',
],
}
85 changes: 85 additions & 0 deletions base_multi_company/hooks.py
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': (
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

"['|', ('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)]"
),
})
65 changes: 65 additions & 0 deletions base_multi_company/i18n/base_multi_company.pot
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 ""

69 changes: 69 additions & 0 deletions base_multi_company/i18n/es.po
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 ""
69 changes: 69 additions & 0 deletions base_multi_company/i18n/fr.po
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 ""
71 changes: 71 additions & 0 deletions base_multi_company/i18n/hr.po
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"
Loading