From 6ad39d78f782146b00f0edb57e9f430823197b86 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Wed, 19 Apr 2017 19:57:31 -0700 Subject: [PATCH 01/25] [ADD] base_multi_company: Create new module * 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 --- base_multi_company/README.rst | 71 ++++++++++++ base_multi_company/__init__.py | 5 + base_multi_company/__manifest__.py | 21 ++++ base_multi_company/hooks.py | 66 +++++++++++ base_multi_company/models/__init__.py | 6 + .../models/multi_company_abstract.py | 50 +++++++++ .../models/res_company_assignment.py | 22 ++++ .../security/ir.model.access.csv | 3 + .../static/description/icon.png | Bin 0 -> 9455 bytes base_multi_company/tests/__init__.py | 5 + .../tests/test_multi_company_abstract.py | 106 ++++++++++++++++++ .../tests/test_res_company_assignment.py | 26 +++++ 12 files changed, 381 insertions(+) create mode 100644 base_multi_company/README.rst create mode 100644 base_multi_company/__init__.py create mode 100644 base_multi_company/__manifest__.py create mode 100644 base_multi_company/hooks.py create mode 100644 base_multi_company/models/__init__.py create mode 100644 base_multi_company/models/multi_company_abstract.py create mode 100644 base_multi_company/models/res_company_assignment.py create mode 100644 base_multi_company/security/ir.model.access.csv create mode 100644 base_multi_company/static/description/icon.png create mode 100644 base_multi_company/tests/__init__.py create mode 100644 base_multi_company/tests/test_multi_company_abstract.py create mode 100644 base_multi_company/tests/test_res_company_assignment.py diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst new file mode 100644 index 00000000000..55a10786909 --- /dev/null +++ b/base_multi_company/README.rst @@ -0,0 +1,71 @@ +.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.svg + :target: http://www.gnu.org/licenses/LGPL-3.0-standalone.html + :alt: License: LGPL-3 + +================== +Multi Company Base +================== + +This module provides an abstract model to be inherited by models that need to implement multi-company functionality. + +Installation +============ + +To install this module, simply follow the standard install process. + +Configuration +============= + +No configuration is needed or possible. + +Usage +===== + +Todo + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/133/10.0 + +Known Issues / Roadmap +====================== + +* Docs + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smash it by providing detailed and welcomed +feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: + `Icon `_. + +Contributors +------------ + +* Dave Lasley +* Pedro M. Baeza + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/base_multi_company/__init__.py b/base_multi_company/__init__.py new file mode 100644 index 00000000000..fd02263ce34 --- /dev/null +++ b/base_multi_company/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import models diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py new file mode 100644 index 00000000000..f0d32e14adf --- /dev/null +++ b/base_multi_company/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# 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': '10.0.1.0.0', + 'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", + 'category': 'base', + 'website': 'https://laslabs.com', + 'license': 'LGPL-3', + 'installable': True, + 'application': False, + 'depends': [ + 'base', + ], + 'data': [ + 'security/ir.model.access.csv', + ], +} diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py new file mode 100644 index 00000000000..0cec32b0944 --- /dev/null +++ b/base_multi_company/hooks.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Copyright 2015-2016 Pedro M. Baeza +# Copyright 2017 LasLabs Inc. +# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html + +from odoo import api, SUPERUSER_ID + + +__all__ = [ + 'post_init_hook', + 'uninstall_hook', +] + + +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, {}) + # Change access rule + rule = env.ref(rule_ref) + rule.write({ + 'active': True, + 'domain_force': ( + "['|', ('company_ids', 'in', user.company_id.ids)," + " ('company_id', '=', False)]" + ), + }) + # Copy company values + model = env[model_name] + groups = model.read_group([], ['company_id'], ['company_id']) + for group in groups: + if not group['company_id']: + continue + records = model.search(group['__domain']) + records.write({ + 'company_ids': [(6, 0, [group['company_id'][0]])], + }) + + +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)]" + ), + }) diff --git a/base_multi_company/models/__init__.py b/base_multi_company/models/__init__.py new file mode 100644 index 00000000000..26a89509748 --- /dev/null +++ b/base_multi_company/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import multi_company_abstract +from . import res_company_assignment diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py new file mode 100644 index 00000000000..63f53f5ad4d --- /dev/null +++ b/base_multi_company/models/multi_company_abstract.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class MultiCompanyAbstract(models.AbstractModel): + + _name = 'multi.company.abstract' + _description = 'Multi-Company Abstract' + + company_id = fields.Many2one( + string='Company', + comodel_name='res.company', + compute='_compute_company_id', + inverse='_inverse_company_id', + search='_search_company_id', + ) + company_ids = fields.Many2many( + string='Companies', + comodel_name='res.company.assignment', + default=lambda s: s._default_company_ids(), + ) + + @api.model + def _default_company_ids(self): + Companies = self.env['res.company'] + return [ + (6, 0, Companies._company_default_get().ids), + ] + + @api.multi + @api.depends('company_ids') + def _compute_company_id(self): + for record in self: + for company in record.company_ids: + if company.id in self.env.user.company_ids.ids: + record.company_id = company.id + break + + @api.multi + def _inverse_company_id(self): + for record in self: + if record.company_id.id not in record.company_ids.ids: + record.company_ids = [(4, record.company_id.id)] + + @api.model + def _search_company_id(self, operator, value): + return [('company_ids', operator, value)] diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py new file mode 100644 index 00000000000..554999c6494 --- /dev/null +++ b/base_multi_company/models/res_company_assignment.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models, tools + + +class ResCompanyAssignment(models.Model): + + _name = 'res.company.assignment' + _auto = False + + name = fields.Char() + + @api.model_cr + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s + AS SELECT id, name + FROM res_company; + """ % (self._table)) diff --git a/base_multi_company/security/ir.model.access.csv b/base_multi_company/security/ir.model.access.csv new file mode 100644 index 00000000000..09a6b8f9b84 --- /dev/null +++ b/base_multi_company/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_res_company_assignment_group_erp_manager,res_company_assignment group_erp_manager,model_res_company_assignment,base.group_erp_manager,1,1,1,1 +access_res_company_assignment_group_user,res_company_assignment group_user,model_res_company_assignment,base.group_user,1,0,0,0 diff --git a/base_multi_company/static/description/icon.png b/base_multi_company/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)( z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~AW`Yue4kFa^LM3X`8x|}ZUeMnqr}>kH zG%WWW>3ml$Yez?i%)2pbKPI7?5o?hydok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Pz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/base_multi_company/tests/__init__.py b/base_multi_company/tests/__init__.py new file mode 100644 index 00000000000..25e360de4d0 --- /dev/null +++ b/base_multi_company/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html + +from . import test_multi_company_abstract +from . import test_res_company_assignment diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py new file mode 100644 index 00000000000..0177dcea01d --- /dev/null +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html + +from odoo import fields, models +from odoo.tests import common + + +class MultiCompanyAbstractTester(models.TransientModel): + _name = 'multi.company.abstract.tester' + _inherit = 'multi.company.abstract' + + name = fields.Char() + + +class TestMultiCompanyAbstract(common.SavepointCase): + + @classmethod + def _init_test_model(cls, model_cls): + """ It builds a model from model_cls in order to test abstract models. + Note that this does not actually create a table in the database, so + there may be some unidentified edge cases. + Args: + model_cls (odoo.models.BaseModel): Class of model to initialize + Returns: + model_cls: Instance + """ + registry = cls.env.registry + cr = cls.env.cr + inst = model_cls._build_model(registry, cr) + model = cls.env[model_cls._name].with_context(todo=[]) + model._prepare_setup() + model._setup_base(partial=False) + model._setup_fields(partial=False) + model._setup_complete() + model._auto_init() + model.init() + model._auto_end() + cls.test_model_record = cls.env['ir.model'].search([ + ('name', '=', model._name), + ]) + return inst + + @classmethod + def setUpClass(cls): + super(TestMultiCompanyAbstract, cls).setUpClass() + cls.env.registry.enter_test_mode() + cls._init_test_model(MultiCompanyAbstractTester) + cls.test_model = cls.env[MultiCompanyAbstractTester._name] + + @classmethod + def tearDownClass(cls): + cls.env.registry.leave_test_mode() + super(TestMultiCompanyAbstract, cls).tearDownClass() + + def setUp(self): + super(TestMultiCompanyAbstract, self).setUp() + self.Model = self.env['multi.company.abstract.tester'] + self.record = self.Model.create({ + 'name': 'test', + 'active': True, + }) + Companies = self.env['res.company'] + self.company_1 = Companies._company_default_get() + self.company_2 = Companies.create({ + 'name': 'Test Co 2', + }) + + def add_company(self, company): + """ Add company to the test record. """ + self.record.company_ids = [4, company.id] + + def switch_user_company(self, user, company): + """ Add a company to the user's allowed & set to current. """ + user.write({ + 'company_ids': [(6, 0, (company + user.company_ids).ids)], + 'company_id': company.id, + }) + + def test_default_company_ids(self): + """ It should set company_ids to the default company. """ + self.assertEqual( + self.record.company_ids.ids, + self.company_1.ids, + ) + + def test_compute_company_id(self): + """ It should set company_id to the top of the company_ids stack. """ + self.add_company(self.company_2) + self.assertEqual( + self.record.company_id.id, + self.record.company_ids[0].id, + ) + + def test_inverse_company_id(self): + """ It should add the company using company_id. """ + self.record.company_id = self.company_2 + self.assertIn(self.company_2.id, self.record.company_ids.ids) + + def test_search_company_id(self): + """ It should return correct record by searching company_id. """ + record = self.env['multi.company.abstract.tester'].search([ + ('company_id', '=', self.company_1.id), + ('id', '=', self.record.id), + ]) + self.assertEqual(record, self.record) diff --git a/base_multi_company/tests/test_res_company_assignment.py b/base_multi_company/tests/test_res_company_assignment.py new file mode 100644 index 00000000000..6e556c79208 --- /dev/null +++ b/base_multi_company/tests/test_res_company_assignment.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html + +from odoo.tests import common + + +class TestResCompanyAssignment(common.TransactionCase): + + def setUp(self): + super(TestResCompanyAssignment, self).setUp() + self.View = self.env['res.company.assignment'] + self.Model = self.env['res.company'] + self.views = self.View.search([]) + + def test_equality_len(self): + """ The record lengths should match between mirror and original. """ + len_views = len(self.views) + len_records = len(self.Model.search([])) + self.assertEqual(len_views, len_records) + + def test_equality_data(self): + """ The record data should match between mirror and original. """ + view = self.views[0] + record = self.Model.browse(view.id) + self.assertEqual(view.name, record.name) From 91ce90fcbfc88c357326cbf029fb93edfe64dbbe Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Fri, 5 May 2017 16:33:41 +0200 Subject: [PATCH 02/25] 10.0 base multi company lmi (#1) * Revert "Revert hook view create back to model init" This reverts commit 770bd71a919e5801702f0fd9d398a37c08472a70. * [FIX] base_multi_company: Always create the view into a pre_init_hook to avoid error in log --- base_multi_company/__init__.py | 2 ++ base_multi_company/__manifest__.py | 1 + base_multi_company/hooks.py | 9 +++++++++ base_multi_company/models/res_company_assignment.py | 11 +---------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/base_multi_company/__init__.py b/base_multi_company/__init__.py index fd02263ce34..94e9bbafea3 100644 --- a/base_multi_company/__init__.py +++ b/base_multi_company/__init__.py @@ -2,4 +2,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 diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index f0d32e14adf..fc080b5073c 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -12,6 +12,7 @@ 'license': 'LGPL-3', 'installable': True, 'application': False, + 'pre_init_hook': 'create_company_assignment_view', 'depends': [ 'base', ], diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index 0cec32b0944..8717c02f0e8 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -7,11 +7,20 @@ __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 + FROM res_company; + """) + + def post_init_hook(cr, rule_ref, model_name): """ Set the `domain_force` and default `company_ids` to `company_id`. diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py index 554999c6494..68bc8674418 100644 --- a/base_multi_company/models/res_company_assignment.py +++ b/base_multi_company/models/res_company_assignment.py @@ -2,7 +2,7 @@ # Copyright 2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -from odoo import api, fields, models, tools +from odoo import fields, models class ResCompanyAssignment(models.Model): @@ -11,12 +11,3 @@ class ResCompanyAssignment(models.Model): _auto = False name = fields.Char() - - @api.model_cr - def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) - self.env.cr.execute(""" - CREATE OR REPLACE VIEW %s - AS SELECT id, name - FROM res_company; - """ % (self._table)) From 21c7c41c5642104cb3d1a5f875c789f5a98395de Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Fri, 5 May 2017 07:35:19 -0700 Subject: [PATCH 03/25] PR fixes (+1 squashed commit) Squashed commits: [4c17d04] auto_join company_ids --- base_multi_company/__manifest__.py | 3 --- base_multi_company/models/multi_company_abstract.py | 1 + base_multi_company/models/res_company_assignment.py | 8 ++++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index fc080b5073c..9aefea737c2 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -13,9 +13,6 @@ 'installable': True, 'application': False, 'pre_init_hook': 'create_company_assignment_view', - 'depends': [ - 'base', - ], 'data': [ 'security/ir.model.access.csv', ], diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 63f53f5ad4d..5164055dfed 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -21,6 +21,7 @@ class MultiCompanyAbstract(models.AbstractModel): string='Companies', comodel_name='res.company.assignment', default=lambda s: s._default_company_ids(), + auto_join=True, ) @api.model diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py index 68bc8674418..b458211c798 100644 --- a/base_multi_company/models/res_company_assignment.py +++ b/base_multi_company/models/res_company_assignment.py @@ -6,6 +6,14 @@ class ResCompanyAssignment(models.Model): + """ This model circumvents company domains to allow assignments. + + Normally when using a multi company setup, you are restricted to seeing + only records owned by the company your user is operating under + (`user.company_id`). This creates a catch 22 with multi-company records, + because in order to assign to another company you have to be able to view + that company. + """ _name = 'res.company.assignment' _auto = False From 737dec59fd3394eecfa9818c6cd77084534b4f8d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 10 May 2017 15:36:28 +0200 Subject: [PATCH 04/25] [FIX] base_multi_company: Allow child_of/parent_of operator into search domain on company_id/company_ids (+1 squashed commit) Squashed commits: [fe161fe] [ADD] setup.py --- base_multi_company/README.rst | 1 + base_multi_company/hooks.py | 2 +- .../models/res_company_assignment.py | 5 +++++ .../tests/test_multi_company_abstract.py | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst index 55a10786909..e3627f50a4b 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/README.rst @@ -54,6 +54,7 @@ Contributors * Dave Lasley * Pedro M. Baeza +* Laurent Mignon Maintainer ---------- diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index 8717c02f0e8..d20068c37e3 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -16,7 +16,7 @@ def create_company_assignment_view(cr): cr.execute(""" CREATE OR REPLACE VIEW res_company_assignment - AS SELECT id, name + AS SELECT id, name, parent_id FROM res_company; """) diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py index b458211c798..563372a35a8 100644 --- a/base_multi_company/models/res_company_assignment.py +++ b/base_multi_company/models/res_company_assignment.py @@ -19,3 +19,8 @@ class ResCompanyAssignment(models.Model): _auto = False name = fields.Char() + + # This field must never be exposed into the UI. The purpose of this + # field is to be able to use the hierarchy operators ( + # child_of/parent_of) into search domains on company_id / company_ids + parent_id = fields.Many2one('res.company') diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 0177dcea01d..18a10d7af7a 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -64,6 +64,7 @@ def setUp(self): self.company_1 = Companies._company_default_get() self.company_2 = Companies.create({ 'name': 'Test Co 2', + 'account_no': '123456' }) def add_company(self, company): @@ -99,8 +100,24 @@ def test_inverse_company_id(self): def test_search_company_id(self): """ It should return correct record by searching company_id. """ + self.add_company(self.company_2) + record = self.env['multi.company.abstract.tester'].search([ + ('company_id.account_no', '=', self.company_2.account_no), + ('id', '=', self.record.id), + ]) + self.assertEqual(record, self.record) record = self.env['multi.company.abstract.tester'].search([ ('company_id', '=', self.company_1.id), ('id', '=', self.record.id), ]) self.assertEqual(record, self.record) + record = self.env['multi.company.abstract.tester'].search([ + ('company_ids', 'child_of', self.company_1.id), + ('id', '=', self.record.id), + ]) + self.assertEqual(record, self.record) + record = self.env['multi.company.abstract.tester'].search([ + ('company_ids', 'parent_of', self.company_1.id), + ('id', '=', self.record.id), + ]) + self.assertEqual(record, self.record) From 123cb62d2772f41146d5dd9249fbda50ae03b686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Wed, 10 May 2017 16:19:59 +0200 Subject: [PATCH 05/25] - Remove depends as company_id is not stored anymore - 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 --- base_multi_company/README.rst | 1 + base_multi_company/hooks.py | 18 ++++++++++-------- .../models/multi_company_abstract.py | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst index e3627f50a4b..e3096990653 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/README.rst @@ -55,6 +55,7 @@ Contributors * Dave Lasley * Pedro M. Baeza * Laurent Mignon +* Cédric Pigeon Maintainer ---------- diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index d20068c37e3..91c19f8d805 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -44,14 +44,16 @@ def post_init_hook(cr, rule_ref, model_name): }) # Copy company values model = env[model_name] - groups = model.read_group([], ['company_id'], ['company_id']) - for group in groups: - if not group['company_id']: - continue - records = model.search(group['__domain']) - records.write({ - 'company_ids': [(6, 0, [group['company_id'][0]])], - }) + + 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 + """ % (table_name, column1, column2, model._table) + env.cr.execute(SQL) def uninstall_hook(cr, rule_ref): diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 5164055dfed..36080e40882 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -32,7 +32,6 @@ def _default_company_ids(self): ] @api.multi - @api.depends('company_ids') def _compute_company_id(self): for record in self: for company in record.company_ids: @@ -43,7 +42,8 @@ def _compute_company_id(self): @api.multi def _inverse_company_id(self): for record in self: - if record.company_id.id not in record.company_ids.ids: + if record.company_id and record.company_id.id not in \ + record.company_ids.ids: record.company_ids = [(4, record.company_id.id)] @api.model From 1b854f56bd9961cbe2f978ac1351a5f63b86c941 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sat, 20 May 2017 06:22:53 +0200 Subject: [PATCH 06/25] OCA Transbot updated translations from Transifex --- base_multi_company/i18n/es.po | 69 ++++++++++++++++++++++++++++++++ base_multi_company/i18n/fr.po | 69 ++++++++++++++++++++++++++++++++ base_multi_company/i18n/hr.po | 69 ++++++++++++++++++++++++++++++++ base_multi_company/i18n/nl_NL.po | 69 ++++++++++++++++++++++++++++++++ base_multi_company/i18n/pt.po | 69 ++++++++++++++++++++++++++++++++ base_multi_company/i18n/pt_BR.po | 68 +++++++++++++++++++++++++++++++ 6 files changed, 413 insertions(+) create mode 100644 base_multi_company/i18n/es.po create mode 100644 base_multi_company/i18n/fr.po create mode 100644 base_multi_company/i18n/hr.po create mode 100644 base_multi_company/i18n/nl_NL.po create mode 100644 base_multi_company/i18n/pt.po create mode 100644 base_multi_company/i18n/pt_BR.po diff --git a/base_multi_company/i18n/es.po b/base_multi_company/i18n/es.po new file mode 100644 index 00000000000..993d9e13053 --- /dev/null +++ b/base_multi_company/i18n/es.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# OCA Transbot , 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 , 2017\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\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 id" +msgstr "" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "" diff --git a/base_multi_company/i18n/fr.po b/base_multi_company/i18n/fr.po new file mode 100644 index 00000000000..ad1d1444170 --- /dev/null +++ b/base_multi_company/i18n/fr.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# OCA Transbot , 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 , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr\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 id" +msgstr "" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "" diff --git a/base_multi_company/i18n/hr.po b/base_multi_company/i18n/hr.po new file mode 100644 index 00000000000..773cb7546cf --- /dev/null +++ b/base_multi_company/i18n/hr.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# Bole , 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 , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hr\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 +msgid "Parent id" +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" diff --git a/base_multi_company/i18n/nl_NL.po b/base_multi_company/i18n/nl_NL.po new file mode 100644 index 00000000000..38c53c2d4b2 --- /dev/null +++ b/base_multi_company/i18n/nl_NL.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# Peter Hageman , 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: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/teams/23907/nl_NL/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: nl_NL\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 "Bedrijven" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +msgid "Company" +msgstr "Bedrijf" + +#. 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 "Weergavenaam" + +#. 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 "Laatst gewijzigd op" + +#. 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 "Naam" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id +msgid "Parent id" +msgstr "Parent id" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "res.company.assignment" diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po new file mode 100644 index 00000000000..6fa35504352 --- /dev/null +++ b/base_multi_company/i18n/pt.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# Pedro Castro Silva , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-16 07:23+0000\n" +"PO-Revision-Date: 2017-12-16 07:23+0000\n" +"Last-Translator: Pedro Castro Silva , 2017\n" +"Language-Team: Portuguese (https://www.transifex.com/oca/teams/23907/pt/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt\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 "Empresas" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +msgid "Company" +msgstr "Empresa" + +#. 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 "Nome a Exibir" + +#. 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 "Última Modificação Em" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_multi_company_abstract +msgid "Multi-Company Abstract" +msgstr "Abstração Multi-Empresa" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_name +msgid "Name" +msgstr "Nome" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id +msgid "Parent id" +msgstr "Id do Ascendente" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "res.company.assignment" diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po new file mode 100644 index 00000000000..3c3d5058b2a --- /dev/null +++ b/base_multi_company/i18n/pt_BR.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +# Translators: +# falexandresilva , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-15 16:43+0000\n" +"PO-Revision-Date: 2017-06-15 16:43+0000\n" +"Last-Translator: falexandresilva , 2017\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_BR\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 +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 "Empresa" + +#. 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 "Última modificação" + +#. 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 "Nome" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id +msgid "Parent id" +msgstr "" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "" From 0787cdb0dc16de988cd9cf3b220d594ef497bc5e Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Sat, 9 Sep 2017 11:44:31 -0700 Subject: [PATCH 07/25] [IMP] base_multi_company: Improve ReadMe * Add implementation instructions to ReadMe --- base_multi_company/README.rst | 83 ++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst index e3096990653..21298fd8e6a 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/README.rst @@ -6,32 +6,85 @@ Multi Company Base ================== -This module provides an abstract model to be inherited by models that need to implement multi-company functionality. +This module provides an abstract model to be inherited by models that need +to implement multi-company functionality. -Installation -============ +No direct functionality is provided by this module. -To install this module, simply follow the standard install process. +Implementation +============== -Configuration -============= +Multi Company Abstract +---------------------- -No configuration is needed or possible. +The `multi.company.abstract` model is meant to be inherited by any model that +wants to implement multi-company functionality. The logic does not require a +pre-existing company field on the inheriting model, but will not be affected +if one does exist. -Usage -===== +When inheriting the `multi.company.abstract` model, you must take care that +it is the first model listed in the `_inherit` array -Todo +.. code-block:: python + + class ProductTemplate(models.Model): + _inherit = ["multi.company.abstract", "product.template"] + _name = "product.template" + _description = "Product Template (Multi-Company)" + +The following fields are provided by `multi.company.abstract`: + +* `company_ids` - All of the companies that this record belongs to. This is a + special `res.company.assignment` view, which allows for the circumvention of + standard cross-company security policies. These policies would normally + restrict a user from seeing another company unless it is currently operating + under that company. Be aware of apples to oranges issues when comparing the + records from this field against actual company records. +* `company_id` - Passes through a singleton company based on the current user, + and the allowed companies for the record. + +Hooks +----- + +A generic `post_init_hook` and `uninstall_hook` is provided, which will alter +a pre-existing single-company security rule to be multi-company aware. + +These hooks will unfortunately not work in every circumstance, but they cut out +significant boilerplate when relevant. + +.. code-block:: python + + import logging + + _logger = logging.getLogger(__name__) + + try: + from odoo.addons.base_multi_company import hooks + except ImportError: + _logger.info('Cannot find `base_multi_company` module in addons path.') + + + def post_init_hook(cr, registry): + hooks.post_init_hook( + cr, + 'product.product_comp_rule', + 'product.template', + ) + + + def uninstall_hook(cr, registry): + hooks.uninstall_hook( + cr, + 'product.product_comp_rule', + ) + +A module implementing these hooks would need to first identify the proper rule +for the record (`product.product_comp_rule` in the above example). .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/133/10.0 -Known Issues / Roadmap -====================== - -* Docs - Bug Tracker =========== From 1fd46885bda5d122f5a74c454a0204c26729ff85 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 15 Dec 2017 17:10:51 +0100 Subject: [PATCH 08/25] [MIG] *_multi_company: OpenUpgrade migration scripts --- base_multi_company/__manifest__.py | 2 +- base_multi_company/hooks.py | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index 9aefea737c2..86d801ffc91 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -5,7 +5,7 @@ { 'name': 'Multi Company Base', 'summary': 'Provides a base for adding multi-company support to models.', - 'version': '10.0.1.0.0', + 'version': '10.0.1.0.1', 'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", 'category': 'base', 'website': 'https://laslabs.com', diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index 91c19f8d805..3fa035091f5 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -21,6 +21,24 @@ def create_company_assignment_view(cr): """) +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)," + " ('company_id', '=', False)]" + ), + }) + + def post_init_hook(cr, rule_ref, model_name): """ Set the `domain_force` and default `company_ids` to `company_id`. @@ -33,18 +51,9 @@ def post_init_hook(cr, rule_ref, model_name): """ with api.Environment.manage(): env = api.Environment(cr, SUPERUSER_ID, {}) - # Change access rule - rule = env.ref(rule_ref) - rule.write({ - 'active': True, - 'domain_force': ( - "['|', ('company_ids', 'in', user.company_id.ids)," - " ('company_id', '=', False)]" - ), - }) + 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 From 6adcdbd7b3d009a31825799793fff82885951eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Honor=C3=A9?= Date: Tue, 27 Mar 2018 08:15:13 +0200 Subject: [PATCH 09/25] Edit unit test + fix bug [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 --- .../models/multi_company_abstract.py | 6 ++ .../tests/test_multi_company_abstract.py | 68 ++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 36080e40882..328f4266d37 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -33,7 +33,13 @@ def _default_company_ids(self): @api.multi def _compute_company_id(self): + user_company = self.env.user.company_id for record in self: + # Give the priority of the current company of the user to avoid + # access right error + if user_company.id in record.company_ids.ids: + record.company_id = user_company.id + continue for company in record.company_ids: if company.id in self.env.user.company_ids.ids: record.company_id = company.id diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 18a10d7af7a..22fc1609dbc 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -2,7 +2,7 @@ # Copyright 2017 LasLabs Inc. # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html -from odoo import fields, models +from odoo import exceptions, fields, models from odoo.tests import common @@ -121,3 +121,69 @@ def test_search_company_id(self): ('id', '=', self.record.id), ]) self.assertEqual(record, self.record) + + def test_compute_company_id2(self): + """ + Test the computation of company_id for a multi_company_abstract. + We have to ensure that the priority of the computed company_id field + is given on the current company of the current user. + And not a random company into allowed companies (company_ids of the + target model). + Because most of access rights are based on the current company of the + current user and not on allowed companies (company_ids). + :return: bool + """ + user_obj = self.env['res.users'] + company_obj = self.env['res.company'] + tester_obj = self.env['multi.company.abstract.tester'] + company1 = self.env.ref("base.main_company") + # Create companies + company2 = company_obj.create({ + 'name': 'High salaries', + }) + company3 = company_obj.create({ + 'name': 'High salaries, twice more!', + }) + company4 = company_obj.create({ + 'name': 'No salaries', + }) + companies = company1 + companies |= company2 + companies |= company3 + # Create a "normal" user (not the admin) + user = user_obj.create({ + 'name': 'Best employee', + 'login': 'best-emplyee@example.com', + 'company_id': company1.id, + 'company_ids': [(6, False, companies.ids)], + }) + tester = tester_obj.create({ + 'name': 'My tester', + 'company_ids': [(6, False, companies.ids)], + }) + tester = tester.sudo(user) + # Current company_id should be updated with current company of the user + for company in user.company_ids: + user.write({ + 'company_id': company.id, + }) + # Force recompute + tester.invalidate_cache() + # Ensure that the current user is on the right company + self.assertEqual(user.company_id.id, company.id) + self.assertEqual(tester.company_id.id, company.id) + # So can read company fields without Access error + self.assertTrue(bool(tester.company_id.name)) + # Switch to a company not in tester.company_ids + user.write({ + 'company_ids': [(4, company4.id, False)], + 'company_id': company4.id, + }) + # Force recompute + tester.invalidate_cache() + self.assertNotEqual(user.company_id.id, tester.company_ids.ids) + with self.assertRaises(exceptions.AccessError): + # The company is not allowed (because not the current company + # of the user) so we should have an exception in this case + self.assertTrue(bool(tester.company_id.name)) + return True From da5f3bf23524da0d94d5f1e418c96320fb82f13d Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Sat, 21 Apr 2018 20:36:43 +0200 Subject: [PATCH 10/25] [FIX] Insert in company_ids relation's table only ids of records that are bound to some company --- base_multi_company/__manifest__.py | 2 +- base_multi_company/hooks.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index 86d801ffc91..3870e15c98e 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -5,7 +5,7 @@ { 'name': 'Multi Company Base', 'summary': 'Provides a base for adding multi-company support to models.', - 'version': '10.0.1.0.1', + 'version': '10.0.2.0.0', 'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", 'category': 'base', 'website': 'https://laslabs.com', diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index 3fa035091f5..b81d801b01e 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -60,7 +60,7 @@ def post_init_hook(cr, rule_ref, model_name): SQL = """ INSERT INTO %s (%s, %s) - SELECT id, company_id FROM %s + SELECT id, company_id FROM %s WHERE company_id IS NOT NULL """ % (table_name, column1, column2, model._table) env.cr.execute(SQL) From 952faa297fca5315e98f22121b13fcdf2c43aeb6 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Sat, 23 Jun 2018 17:48:14 +0000 Subject: [PATCH 11/25] [UPD] Update base_multi_company.pot --- .../i18n/base_multi_company.pot | 67 +++++++++++++++++++ base_multi_company/i18n/es.po | 6 +- base_multi_company/i18n/fr.po | 6 +- base_multi_company/i18n/hr.po | 9 ++- base_multi_company/i18n/nl_NL.po | 9 ++- base_multi_company/i18n/pt.po | 6 +- base_multi_company/i18n/pt_BR.po | 10 ++- 7 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 base_multi_company/i18n/base_multi_company.pot diff --git a/base_multi_company/i18n/base_multi_company.pot b/base_multi_company/i18n/base_multi_company.pot new file mode 100644 index 00000000000..42610653240 --- /dev/null +++ b/base_multi_company/i18n/base_multi_company.pot @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids +msgid "Companies" +msgstr "" + +#. module: base_multi_company +#: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 id" +msgstr "" + +#. module: base_multi_company +#: model:ir.model,name:base_multi_company.model_res_company_assignment +msgid "res.company.assignment" +msgstr "" + diff --git a/base_multi_company/i18n/es.po b/base_multi_company/i18n/es.po index 993d9e13053..4696ffe8930 100644 --- a/base_multi_company/i18n/es.po +++ b/base_multi_company/i18n/es.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # OCA Transbot , 2017 msgid "" @@ -12,21 +12,23 @@ msgstr "" "PO-Revision-Date: 2017-12-16 02:03+0000\n" "Last-Translator: OCA Transbot , 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" -"Language: es\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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "" diff --git a/base_multi_company/i18n/fr.po b/base_multi_company/i18n/fr.po index ad1d1444170..5bee325968c 100644 --- a/base_multi_company/i18n/fr.po +++ b/base_multi_company/i18n/fr.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # OCA Transbot , 2017 msgid "" @@ -12,21 +12,23 @@ msgstr "" "PO-Revision-Date: 2017-12-16 02:03+0000\n" "Last-Translator: OCA Transbot , 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" -"Language: fr\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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "" diff --git a/base_multi_company/i18n/hr.po b/base_multi_company/i18n/hr.po index 773cb7546cf..a6014651817 100644 --- a/base_multi_company/i18n/hr.po +++ b/base_multi_company/i18n/hr.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # Bole , 2018 msgid "" @@ -12,21 +12,24 @@ msgstr "" "PO-Revision-Date: 2018-01-27 07:37+0000\n" "Last-Translator: Bole , 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" -"Language: hr\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" +"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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Tvrtka" diff --git a/base_multi_company/i18n/nl_NL.po b/base_multi_company/i18n/nl_NL.po index 38c53c2d4b2..4fe12a234c2 100644 --- a/base_multi_company/i18n/nl_NL.po +++ b/base_multi_company/i18n/nl_NL.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # Peter Hageman , 2017 msgid "" @@ -11,22 +11,25 @@ msgstr "" "POT-Creation-Date: 2017-12-16 02:03+0000\n" "PO-Revision-Date: 2017-12-16 02:03+0000\n" "Last-Translator: Peter Hageman , 2017\n" -"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/teams/23907/nl_NL/)\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: nl_NL\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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "Bedrijven" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Bedrijf" diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po index 6fa35504352..3f807f02f91 100644 --- a/base_multi_company/i18n/pt.po +++ b/base_multi_company/i18n/pt.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # Pedro Castro Silva , 2017 msgid "" @@ -12,21 +12,23 @@ msgstr "" "PO-Revision-Date: 2017-12-16 07:23+0000\n" "Last-Translator: Pedro Castro Silva , 2017\n" "Language-Team: Portuguese (https://www.transifex.com/oca/teams/23907/pt/)\n" +"Language: pt\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: pt\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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "Empresas" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Empresa" diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po index 3c3d5058b2a..16b253f199d 100644 --- a/base_multi_company/i18n/pt_BR.po +++ b/base_multi_company/i18n/pt_BR.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * base_multi_company -# +# # Translators: # falexandresilva , 2017 msgid "" @@ -11,21 +11,25 @@ msgstr "" "POT-Creation-Date: 2017-06-15 16:43+0000\n" "PO-Revision-Date: 2017-06-15 16:43+0000\n" "Last-Translator: falexandresilva , 2017\n" -"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/" +"teams/23907/pt_BR/)\n" +"Language: pt_BR\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: pt_BR\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 +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id +#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Empresa" From dbfbfd2e842c64c4b4e91470f9d7f47d72ef8e1b Mon Sep 17 00:00:00 2001 From: Pedro Castro Silva Date: Thu, 26 Jul 2018 15:38:09 +0000 Subject: [PATCH 12/25] Translated using Weblate (Portuguese) 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/ --- base_multi_company/i18n/pt.po | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po index 3f807f02f91..513c4852d71 100644 --- a/base_multi_company/i18n/pt.po +++ b/base_multi_company/i18n/pt.po @@ -9,14 +9,15 @@ msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2017-12-16 07:23+0000\n" -"PO-Revision-Date: 2017-12-16 07:23+0000\n" -"Last-Translator: Pedro Castro Silva , 2017\n" +"PO-Revision-Date: 2018-07-27 16:32+0000\n" +"Last-Translator: Pedro Castro Silva \n" "Language-Team: Portuguese (https://www.transifex.com/oca/teams/23907/pt/)\n" "Language: pt\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" +"X-Generator: Weblate 3.0.1\n" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_ids @@ -68,4 +69,4 @@ msgstr "Id do Ascendente" #. module: base_multi_company #: model:ir.model,name:base_multi_company.model_res_company_assignment msgid "res.company.assignment" -msgstr "res.company.assignment" +msgstr "" From 81f46a49956ce339cbdfee068162d7e947e07af5 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira Date: Tue, 31 Jul 2018 10:03:22 -0300 Subject: [PATCH 13/25] [MIG] base_multi_company: Migration to 11.0 --- base_multi_company/README.rst | 7 ++++--- base_multi_company/__init__.py | 1 - base_multi_company/__manifest__.py | 3 +-- base_multi_company/hooks.py | 1 - base_multi_company/i18n/pt_BR.po | 4 ++-- base_multi_company/models/__init__.py | 1 - base_multi_company/models/multi_company_abstract.py | 1 - base_multi_company/models/res_company_assignment.py | 1 - base_multi_company/tests/__init__.py | 1 - .../tests/test_multi_company_abstract.py | 10 +++++----- .../tests/test_res_company_assignment.py | 1 - 11 files changed, 12 insertions(+), 19 deletions(-) diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst index 21298fd8e6a..c582bf0f433 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/README.rst @@ -1,5 +1,5 @@ -.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.svg - :target: http://www.gnu.org/licenses/LGPL-3.0-standalone.html +.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.png + :target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 ================== @@ -83,7 +83,7 @@ for the record (`product.product_comp_rule` in the above example). .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/133/10.0 + :target: https://runbot.odoo-community.org/runbot/133/11.0 Bug Tracker =========== @@ -109,6 +109,7 @@ Contributors * Pedro M. Baeza * Laurent Mignon * Cédric Pigeon +* Rodrigo Ferreira Maintainer ---------- diff --git a/base_multi_company/__init__.py b/base_multi_company/__init__.py index 94e9bbafea3..996ef8df92f 100644 --- a/base_multi_company/__init__.py +++ b/base_multi_company/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index 3870e15c98e..b838ab1f114 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # 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': '10.0.2.0.0', + 'version': '11.0.1.0.0', 'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", 'category': 'base', 'website': 'https://laslabs.com', diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index b81d801b01e..d2fb86195ca 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2015-2016 Pedro M. Baeza # Copyright 2017 LasLabs Inc. # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po index 16b253f199d..c8ce6244aff 100644 --- a/base_multi_company/i18n/pt_BR.po +++ b/base_multi_company/i18n/pt_BR.po @@ -25,7 +25,7 @@ msgstr "" #: model:ir.model.fields,field_description:base_multi_company.field_res_partner_company_ids #: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" -msgstr "" +msgstr "Empresas" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id @@ -37,7 +37,7 @@ msgstr "Empresa" #: 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 "" +msgstr "Nome" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_id diff --git a/base_multi_company/models/__init__.py b/base_multi_company/models/__init__.py index 26a89509748..b9feeae3f04 100644 --- a/base_multi_company/models/__init__.py +++ b/base_multi_company/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 328f4266d37..76ec801bbf0 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py index 563372a35a8..ea10c8d722d 100644 --- a/base_multi_company/models/res_company_assignment.py +++ b/base_multi_company/models/res_company_assignment.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). diff --git a/base_multi_company/tests/__init__.py b/base_multi_company/tests/__init__.py index 25e360de4d0..1a81a7d20c4 100644 --- a/base_multi_company/tests/__init__.py +++ b/base_multi_company/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html from . import test_multi_company_abstract diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 22fc1609dbc..2ebb2430bce 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html @@ -15,6 +14,9 @@ class MultiCompanyAbstractTester(models.TransientModel): class TestMultiCompanyAbstract(common.SavepointCase): + post_install = True + at_install = False + @classmethod def _init_test_model(cls, model_cls): """ It builds a model from model_cls in order to test abstract models. @@ -30,12 +32,11 @@ def _init_test_model(cls, model_cls): inst = model_cls._build_model(registry, cr) model = cls.env[model_cls._name].with_context(todo=[]) model._prepare_setup() - model._setup_base(partial=False) - model._setup_fields(partial=False) + model._setup_base() + model._setup_fields() model._setup_complete() model._auto_init() model.init() - model._auto_end() cls.test_model_record = cls.env['ir.model'].search([ ('name', '=', model._name), ]) @@ -58,7 +59,6 @@ def setUp(self): self.Model = self.env['multi.company.abstract.tester'] self.record = self.Model.create({ 'name': 'test', - 'active': True, }) Companies = self.env['res.company'] self.company_1 = Companies._company_default_get() diff --git a/base_multi_company/tests/test_res_company_assignment.py b/base_multi_company/tests/test_res_company_assignment.py index 6e556c79208..e4305278d4f 100644 --- a/base_multi_company/tests/test_res_company_assignment.py +++ b/base_multi_company/tests/test_res_company_assignment.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html From 5c50b39f4c5ca4c621d84bfc3871c9a9b4f58f73 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Thu, 2 Aug 2018 16:02:52 +0000 Subject: [PATCH 14/25] [UPD] Update base_multi_company.pot --- base_multi_company/i18n/base_multi_company.pot | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/base_multi_company/i18n/base_multi_company.pot b/base_multi_company/i18n/base_multi_company.pot index 42610653240..97629e6ea84 100644 --- a/base_multi_company/i18n/base_multi_company.pot +++ b/base_multi_company/i18n/base_multi_company.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 10.0\n" +"Project-Id-Version: Odoo Server 11.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" @@ -15,15 +15,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "" @@ -57,7 +53,7 @@ msgstr "" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +msgid "Parent" msgstr "" #. module: base_multi_company From bcfee2cd27ea60572ef47d55e2b51b6a65bfb536 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 16 Nov 2018 01:22:18 +0100 Subject: [PATCH 15/25] [FIX] base_multi_company: Fix tests 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. --- .../tests/test_multi_company_abstract.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 2ebb2430bce..e0167806be0 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -135,7 +135,6 @@ def test_compute_company_id2(self): """ user_obj = self.env['res.users'] company_obj = self.env['res.company'] - tester_obj = self.env['multi.company.abstract.tester'] company1 = self.env.ref("base.main_company") # Create companies company2 = company_obj.create({ @@ -147,9 +146,7 @@ def test_compute_company_id2(self): company4 = company_obj.create({ 'name': 'No salaries', }) - companies = company1 - companies |= company2 - companies |= company3 + companies = company1 + company2 + company3 # Create a "normal" user (not the admin) user = user_obj.create({ 'name': 'Best employee', @@ -157,11 +154,11 @@ def test_compute_company_id2(self): 'company_id': company1.id, 'company_ids': [(6, False, companies.ids)], }) + tester_obj = self.env['multi.company.abstract.tester'].sudo(user) tester = tester_obj.create({ 'name': 'My tester', 'company_ids': [(6, False, companies.ids)], }) - tester = tester.sudo(user) # Current company_id should be updated with current company of the user for company in user.company_ids: user.write({ @@ -170,8 +167,8 @@ def test_compute_company_id2(self): # Force recompute tester.invalidate_cache() # Ensure that the current user is on the right company - self.assertEqual(user.company_id.id, company.id) - self.assertEqual(tester.company_id.id, company.id) + self.assertEqual(user.company_id, company) + self.assertEqual(tester.company_id, company) # So can read company fields without Access error self.assertTrue(bool(tester.company_id.name)) # Switch to a company not in tester.company_ids From 9cee705a02d8b89a6d1d54c1482be91df1a0ba02 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sun, 9 Dec 2018 12:35:10 +0000 Subject: [PATCH 16/25] Update translation files Updated by Update PO files to match POT (msgmerge) hook in Weblate. --- base_multi_company/i18n/es.po | 6 +----- base_multi_company/i18n/fr.po | 6 +----- base_multi_company/i18n/hr.po | 7 ++----- base_multi_company/i18n/nl_NL.po | 7 ++----- base_multi_company/i18n/pt.po | 7 ++----- base_multi_company/i18n/pt_BR.po | 6 +----- 6 files changed, 9 insertions(+), 30 deletions(-) diff --git a/base_multi_company/i18n/es.po b/base_multi_company/i18n/es.po index 4696ffe8930..b501f95b1ea 100644 --- a/base_multi_company/i18n/es.po +++ b/base_multi_company/i18n/es.po @@ -20,15 +20,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "" @@ -62,7 +58,7 @@ msgstr "" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +msgid "Parent" msgstr "" #. module: base_multi_company diff --git a/base_multi_company/i18n/fr.po b/base_multi_company/i18n/fr.po index 5bee325968c..a40aade437c 100644 --- a/base_multi_company/i18n/fr.po +++ b/base_multi_company/i18n/fr.po @@ -20,15 +20,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "" @@ -62,7 +58,7 @@ msgstr "" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +msgid "Parent" msgstr "" #. module: base_multi_company diff --git a/base_multi_company/i18n/hr.po b/base_multi_company/i18n/hr.po index a6014651817..59a010150a8 100644 --- a/base_multi_company/i18n/hr.po +++ b/base_multi_company/i18n/hr.po @@ -21,15 +21,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Tvrtka" @@ -63,7 +59,8 @@ msgstr "Naziv" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +#, fuzzy +msgid "Parent" msgstr "ID Nadređenog" #. module: base_multi_company diff --git a/base_multi_company/i18n/nl_NL.po b/base_multi_company/i18n/nl_NL.po index 4fe12a234c2..39ecce6ce7f 100644 --- a/base_multi_company/i18n/nl_NL.po +++ b/base_multi_company/i18n/nl_NL.po @@ -21,15 +21,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "Bedrijven" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Bedrijf" @@ -63,7 +59,8 @@ msgstr "Naam" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +#, fuzzy +msgid "Parent" msgstr "Parent id" #. module: base_multi_company diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po index 513c4852d71..f817ce620c6 100644 --- a/base_multi_company/i18n/pt.po +++ b/base_multi_company/i18n/pt.po @@ -21,15 +21,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "Empresas" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Empresa" @@ -63,7 +59,8 @@ msgstr "Nome" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +#, fuzzy +msgid "Parent" msgstr "Id do Ascendente" #. module: base_multi_company diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po index c8ce6244aff..0764d21aaba 100644 --- a/base_multi_company/i18n/pt_BR.po +++ b/base_multi_company/i18n/pt_BR.po @@ -21,15 +21,11 @@ msgstr "" #. 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 -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_ids msgid "Companies" msgstr "Empresas" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_multi_company_abstract_company_id -#: model:ir.model.fields,field_description:base_multi_company.field_sale_layout_category_company_id msgid "Company" msgstr "Empresa" @@ -63,7 +59,7 @@ msgstr "Nome" #. module: base_multi_company #: model:ir.model.fields,field_description:base_multi_company.field_res_company_assignment_parent_id -msgid "Parent id" +msgid "Parent" msgstr "" #. module: base_multi_company From 636792eb385d786612ed23bed10c90455284dd0e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 17 Jan 2019 23:16:33 +0100 Subject: [PATCH 17/25] [FIX] base_multi_company: Fix several things: * 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. --- base_multi_company/hooks.py | 2 +- .../models/multi_company_abstract.py | 28 ++++++++----------- .../tests/test_multi_company_abstract.py | 17 ++++------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index d2fb86195ca..9c7f18ab647 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -33,7 +33,7 @@ def set_security_rule(env, rule_ref): 'active': True, 'domain_force': ( "['|', ('company_ids', 'in', user.company_id.ids)," - " ('company_id', '=', False)]" + " ('company_ids', '=', False)]" ), }) diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 76ec801bbf0..623c501009a 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -19,18 +19,10 @@ class MultiCompanyAbstract(models.AbstractModel): company_ids = fields.Many2many( string='Companies', comodel_name='res.company.assignment', - default=lambda s: s._default_company_ids(), auto_join=True, ) - @api.model - def _default_company_ids(self): - Companies = self.env['res.company'] - return [ - (6, 0, Companies._company_default_get().ids), - ] - - @api.multi + @api.depends('company_ids') def _compute_company_id(self): user_company = self.env.user.company_id for record in self: @@ -38,18 +30,20 @@ def _compute_company_id(self): # access right error if user_company.id in record.company_ids.ids: record.company_id = user_company.id - continue - for company in record.company_ids: - if company.id in self.env.user.company_ids.ids: - record.company_id = company.id - break + else: + record.company_id = record.company_ids[:1].id @api.multi def _inverse_company_id(self): for record in self: - if record.company_id and record.company_id.id not in \ - record.company_ids.ids: - record.company_ids = [(4, record.company_id.id)] + # Checking id not falsy due to bad data that can put '' in id + if record.company_id.id: + if record.company_id.id not in record.company_ids.ids: + record.company_ids = [(4, record.company_id.id)] + else: + # Empty the list of allowed companies (so it means all + # companies are allowed) as it's the equivalent + record.company_ids = [(5, )] @api.model def _search_company_id(self, operator, value): diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index e0167806be0..2eff9ecb87a 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -69,7 +69,7 @@ def setUp(self): def add_company(self, company): """ Add company to the test record. """ - self.record.company_ids = [4, company.id] + self.record.company_ids = [(4, company.id)] def switch_user_company(self, user, company): """ Add a company to the user's allowed & set to current. """ @@ -78,19 +78,12 @@ def switch_user_company(self, user, company): 'company_id': company.id, }) - def test_default_company_ids(self): - """ It should set company_ids to the default company. """ - self.assertEqual( - self.record.company_ids.ids, - self.company_1.ids, - ) - def test_compute_company_id(self): """ It should set company_id to the top of the company_ids stack. """ self.add_company(self.company_2) self.assertEqual( self.record.company_id.id, - self.record.company_ids[0].id, + self.company_2.id, ) def test_inverse_company_id(self): @@ -107,17 +100,17 @@ def test_search_company_id(self): ]) self.assertEqual(record, self.record) record = self.env['multi.company.abstract.tester'].search([ - ('company_id', '=', self.company_1.id), + ('company_id', '=', self.company_2.id), ('id', '=', self.record.id), ]) self.assertEqual(record, self.record) record = self.env['multi.company.abstract.tester'].search([ - ('company_ids', 'child_of', self.company_1.id), + ('company_ids', 'child_of', self.company_2.id), ('id', '=', self.record.id), ]) self.assertEqual(record, self.record) record = self.env['multi.company.abstract.tester'].search([ - ('company_ids', 'parent_of', self.company_1.id), + ('company_ids', 'parent_of', self.company_2.id), ('id', '=', self.record.id), ]) self.assertEqual(record, self.record) From b9ba8d0d80682ead2961ce5dc25492de94260d65 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Thu, 17 Jan 2019 22:46:18 +0000 Subject: [PATCH 18/25] [UPD] Update base_multi_company.pot --- base_multi_company/i18n/base_multi_company.pot | 1 + 1 file changed, 1 insertion(+) diff --git a/base_multi_company/i18n/base_multi_company.pot b/base_multi_company/i18n/base_multi_company.pot index 97629e6ea84..60d6a35a79e 100644 --- a/base_multi_company/i18n/base_multi_company.pot +++ b/base_multi_company/i18n/base_multi_company.pot @@ -15,6 +15,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "" From 432acd18f62cfea697a832ddffcbb4118e0d45f2 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Thu, 17 Jan 2019 22:46:25 +0000 Subject: [PATCH 19/25] Update translation files Updated by Update PO files to match POT (msgmerge) hook in Weblate. --- base_multi_company/i18n/es.po | 1 + base_multi_company/i18n/fr.po | 1 + base_multi_company/i18n/hr.po | 1 + base_multi_company/i18n/nl_NL.po | 1 + base_multi_company/i18n/pt.po | 1 + base_multi_company/i18n/pt_BR.po | 1 + 6 files changed, 6 insertions(+) diff --git a/base_multi_company/i18n/es.po b/base_multi_company/i18n/es.po index b501f95b1ea..09cf4b82685 100644 --- a/base_multi_company/i18n/es.po +++ b/base_multi_company/i18n/es.po @@ -20,6 +20,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Compañías" diff --git a/base_multi_company/i18n/fr.po b/base_multi_company/i18n/fr.po index a40aade437c..16bf8835b25 100644 --- a/base_multi_company/i18n/fr.po +++ b/base_multi_company/i18n/fr.po @@ -20,6 +20,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Sociétés" diff --git a/base_multi_company/i18n/hr.po b/base_multi_company/i18n/hr.po index 59a010150a8..0657ae595dc 100644 --- a/base_multi_company/i18n/hr.po +++ b/base_multi_company/i18n/hr.po @@ -21,6 +21,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Tvrtke" diff --git a/base_multi_company/i18n/nl_NL.po b/base_multi_company/i18n/nl_NL.po index 39ecce6ce7f..408ca07f3f2 100644 --- a/base_multi_company/i18n/nl_NL.po +++ b/base_multi_company/i18n/nl_NL.po @@ -21,6 +21,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Bedrijven" diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po index f817ce620c6..fc1ebe494d9 100644 --- a/base_multi_company/i18n/pt.po +++ b/base_multi_company/i18n/pt.po @@ -21,6 +21,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Empresas" diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po index 0764d21aaba..835f5d31c8b 100644 --- a/base_multi_company/i18n/pt_BR.po +++ b/base_multi_company/i18n/pt_BR.po @@ -21,6 +21,7 @@ msgstr "" #. 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 msgid "Companies" msgstr "Empresas" From ad34fead64ec52b901b72188345f80b9b470e7ae Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 19 Jan 2019 10:51:32 +0100 Subject: [PATCH 20/25] [MIG] partner_multi_company: Finish migration to 11.0 --- base_multi_company/models/multi_company_abstract.py | 6 ++++++ base_multi_company/tests/test_multi_company_abstract.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 623c501009a..21307babc39 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -20,8 +20,14 @@ class MultiCompanyAbstract(models.AbstractModel): string='Companies', comodel_name='res.company.assignment', auto_join=True, + default=lambda self: self._default_company_ids(), ) + def _default_company_ids(self): + return self.browse( + self.env['res.company']._company_default_get(self._name).ids + ) + @api.depends('company_ids') def _compute_company_id(self): user_company = self.env.user.company_id diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 2eff9ecb87a..6593e815cae 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -81,6 +81,8 @@ def switch_user_company(self, user, company): def test_compute_company_id(self): """ It should set company_id to the top of the company_ids stack. """ self.add_company(self.company_2) + self.env.user.company_ids = [(4, self.company_2.id)] + self.env.user.company_id = self.company_2.id self.assertEqual( self.record.company_id.id, self.company_2.id, From 1f1c34cb8cc492c9a64539de1417d139c296140f Mon Sep 17 00:00:00 2001 From: oca-travis Date: Sat, 19 Jan 2019 10:59:36 +0000 Subject: [PATCH 21/25] [UPD] Update base_multi_company.pot --- base_multi_company/i18n/base_multi_company.pot | 1 + 1 file changed, 1 insertion(+) diff --git a/base_multi_company/i18n/base_multi_company.pot b/base_multi_company/i18n/base_multi_company.pot index 60d6a35a79e..eb342c79467 100644 --- a/base_multi_company/i18n/base_multi_company.pot +++ b/base_multi_company/i18n/base_multi_company.pot @@ -16,6 +16,7 @@ msgstr "" #. 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 "" From a92fac9b84e8be47b59e109fdc749ec973099d5e Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sat, 19 Jan 2019 10:59:43 +0000 Subject: [PATCH 22/25] Update translation files Updated by Update PO files to match POT (msgmerge) hook in Weblate. --- base_multi_company/i18n/es.po | 1 + base_multi_company/i18n/fr.po | 1 + base_multi_company/i18n/hr.po | 1 + base_multi_company/i18n/nl_NL.po | 1 + base_multi_company/i18n/pt.po | 1 + base_multi_company/i18n/pt_BR.po | 1 + 6 files changed, 6 insertions(+) diff --git a/base_multi_company/i18n/es.po b/base_multi_company/i18n/es.po index 09cf4b82685..82eb9356b4b 100644 --- a/base_multi_company/i18n/es.po +++ b/base_multi_company/i18n/es.po @@ -21,6 +21,7 @@ msgstr "" #. 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" diff --git a/base_multi_company/i18n/fr.po b/base_multi_company/i18n/fr.po index 16bf8835b25..24d5a1b2aaf 100644 --- a/base_multi_company/i18n/fr.po +++ b/base_multi_company/i18n/fr.po @@ -21,6 +21,7 @@ msgstr "" #. 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" diff --git a/base_multi_company/i18n/hr.po b/base_multi_company/i18n/hr.po index 0657ae595dc..cf5e88e5c65 100644 --- a/base_multi_company/i18n/hr.po +++ b/base_multi_company/i18n/hr.po @@ -22,6 +22,7 @@ msgstr "" #. 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" diff --git a/base_multi_company/i18n/nl_NL.po b/base_multi_company/i18n/nl_NL.po index 408ca07f3f2..4c94516daef 100644 --- a/base_multi_company/i18n/nl_NL.po +++ b/base_multi_company/i18n/nl_NL.po @@ -22,6 +22,7 @@ msgstr "" #. 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 "Bedrijven" diff --git a/base_multi_company/i18n/pt.po b/base_multi_company/i18n/pt.po index fc1ebe494d9..a2d2395611e 100644 --- a/base_multi_company/i18n/pt.po +++ b/base_multi_company/i18n/pt.po @@ -22,6 +22,7 @@ msgstr "" #. 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 "Empresas" diff --git a/base_multi_company/i18n/pt_BR.po b/base_multi_company/i18n/pt_BR.po index 835f5d31c8b..e07ffb8ec45 100644 --- a/base_multi_company/i18n/pt_BR.po +++ b/base_multi_company/i18n/pt_BR.po @@ -22,6 +22,7 @@ msgstr "" #. 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 "Empresas" From a9a84417c29b02ee3d715054623c51123c8176b6 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Sat, 4 May 2019 16:44:17 +0200 Subject: [PATCH 23/25] Migrate base_multi_company to v12 --- base_multi_company/README.rst | 3 ++- base_multi_company/__manifest__.py | 4 ++-- base_multi_company/tests/test_multi_company_abstract.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/base_multi_company/README.rst b/base_multi_company/README.rst index c582bf0f433..0ff27af4303 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/README.rst @@ -83,7 +83,7 @@ for the record (`product.product_comp_rule` in the above example). .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/133/11.0 + :target: https://runbot.odoo-community.org/runbot/133/12.0 Bug Tracker =========== @@ -110,6 +110,7 @@ Contributors * Laurent Mignon * Cédric Pigeon * Rodrigo Ferreira +* Florian da Costa Maintainer ---------- diff --git a/base_multi_company/__manifest__.py b/base_multi_company/__manifest__.py index b838ab1f114..90ee0e70b19 100644 --- a/base_multi_company/__manifest__.py +++ b/base_multi_company/__manifest__.py @@ -4,10 +4,10 @@ { 'name': 'Multi Company Base', 'summary': 'Provides a base for adding multi-company support to models.', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'author': "LasLabs, Tecnativa, Odoo Community Association (OCA)", 'category': 'base', - 'website': 'https://laslabs.com', + 'website': 'https://github.com/OCA/multi-company', 'license': 'LGPL-3', 'installable': True, 'application': False, diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 6593e815cae..5c7d0115e9b 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -45,7 +45,7 @@ def _init_test_model(cls, model_cls): @classmethod def setUpClass(cls): super(TestMultiCompanyAbstract, cls).setUpClass() - cls.env.registry.enter_test_mode() + cls.env.registry.enter_test_mode(cls.cr) cls._init_test_model(MultiCompanyAbstractTester) cls.test_model = cls.env[MultiCompanyAbstractTester._name] From 2be4f5aacf1f6d6c6beb2051579f2679dbd94e23 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Sat, 4 May 2019 16:44:48 +0200 Subject: [PATCH 24/25] Improve performance adding a techical field used in ir rules --- base_multi_company/hooks.py | 2 +- .../models/multi_company_abstract.py | 12 ++++ .../models/res_company_assignment.py | 1 + base_multi_company/readme/CONTRIBUTORS.rst | 6 ++ base_multi_company/readme/DESCRIPTION.rst | 4 ++ .../{README.rst => readme/USAGE.rst} | 61 +------------------ 6 files changed, 25 insertions(+), 61 deletions(-) create mode 100644 base_multi_company/readme/CONTRIBUTORS.rst create mode 100644 base_multi_company/readme/DESCRIPTION.rst rename base_multi_company/{README.rst => readme/USAGE.rst} (56%) diff --git a/base_multi_company/hooks.py b/base_multi_company/hooks.py index 9c7f18ab647..16a8cb47551 100644 --- a/base_multi_company/hooks.py +++ b/base_multi_company/hooks.py @@ -33,7 +33,7 @@ def set_security_rule(env, rule_ref): 'active': True, 'domain_force': ( "['|', ('company_ids', 'in', user.company_id.ids)," - " ('company_ids', '=', False)]" + " ('visible_for_all_companies', '=', True)]" ), }) diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 21307babc39..60b3ee01669 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -22,6 +22,18 @@ class MultiCompanyAbstract(models.AbstractModel): auto_join=True, default=lambda self: self._default_company_ids(), ) + visible_for_all_companies = fields.Boolean( + compute='_get_visible_for_all_companies', + store=True, + index=True, + default=True) + + @api.depends('company_ids') + @api.multi + def _get_visible_for_all_companies(self): + for rec in self: + if not rec.company_ids: + rec.visible_for_all_companies = True def _default_company_ids(self): return self.browse( diff --git a/base_multi_company/models/res_company_assignment.py b/base_multi_company/models/res_company_assignment.py index ea10c8d722d..596275943aa 100644 --- a/base_multi_company/models/res_company_assignment.py +++ b/base_multi_company/models/res_company_assignment.py @@ -16,6 +16,7 @@ class ResCompanyAssignment(models.Model): _name = 'res.company.assignment' _auto = False + _description = "Res Company Assignment" name = fields.Char() diff --git a/base_multi_company/readme/CONTRIBUTORS.rst b/base_multi_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..fc09b6dd829 --- /dev/null +++ b/base_multi_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Dave Lasley +* Pedro M. Baeza +* Laurent Mignon +* Cédric Pigeon +* Rodrigo Ferreira +* Florian da Costa diff --git a/base_multi_company/readme/DESCRIPTION.rst b/base_multi_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f684e9dd8b2 --- /dev/null +++ b/base_multi_company/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module provides an abstract model to be inherited by models that need +to implement multi-company functionality. + +No direct functionality is provided by this module. diff --git a/base_multi_company/README.rst b/base_multi_company/readme/USAGE.rst similarity index 56% rename from base_multi_company/README.rst rename to base_multi_company/readme/USAGE.rst index 0ff27af4303..25052dc9bfe 100644 --- a/base_multi_company/README.rst +++ b/base_multi_company/readme/USAGE.rst @@ -1,18 +1,5 @@ -.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.png - :target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html - :alt: License: LGPL-3 - -================== -Multi Company Base -================== - -This module provides an abstract model to be inherited by models that need -to implement multi-company functionality. - -No direct functionality is provided by this module. - Implementation -============== +~~~~~~~~~~~~~~ Multi Company Abstract ---------------------- @@ -80,49 +67,3 @@ significant boilerplate when relevant. A module implementing these hooks would need to first identify the proper rule for the record (`product.product_comp_rule` in the above example). - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/133/12.0 - -Bug Tracker -=========== - -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smash it by providing detailed and welcomed -feedback. - -Credits -======= - -Images ------- - -* Odoo Community Association: - `Icon `_. - -Contributors ------------- - -* Dave Lasley -* Pedro M. Baeza -* Laurent Mignon -* Cédric Pigeon -* Rodrigo Ferreira -* Florian da Costa - -Maintainer ----------- - -.. image:: https://odoo-community.org/logo.png - :alt: Odoo Community Association - :target: https://odoo-community.org - -This module is maintained by the OCA. - -OCA, or the Odoo Community Association, is a nonprofit organization whose -mission is to support the collaborative development of Odoo features and -promote its widespread use. - -To contribute to this module, please visit http://odoo-community.org. From a4747217565124dff8ea74e868371921ce8e214d Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Sat, 6 Jul 2019 15:59:29 +0200 Subject: [PATCH 25/25] fixup! Migrate base_multi_company to v12 --- base_multi_company/tests/test_multi_company_abstract.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 5c7d0115e9b..12c3b24eb4e 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -12,11 +12,9 @@ class MultiCompanyAbstractTester(models.TransientModel): name = fields.Char() +@common.tagged('post_install', '-at_install') class TestMultiCompanyAbstract(common.SavepointCase): - post_install = True - at_install = False - @classmethod def _init_test_model(cls, model_cls): """ It builds a model from model_cls in order to test abstract models.