diff --git a/crm_stage_multi_company/README.rst b/crm_stage_multi_company/README.rst new file mode 100644 index 00000000000..7a6a71e975a --- /dev/null +++ b/crm_stage_multi_company/README.rst @@ -0,0 +1,89 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +Crm Stage Multi Company +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3913be899b0dac056dafd3c26a50291b10216123ef328ad4a854f1602e4a9d5b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/19.0/crm_stage_multi_company + :alt: OCA/multi-company +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/multi-company-19-0/multi-company-19-0-crm_stage_multi_company + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/multi-company&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds support for multi company on crm stage. + +The new multi company rule prevents any user without access to all +stages to open the CRM application. This behaviour comes from the kanban +view and especially from he read_group (\_read_group_fill_results) which +tries to retrieve fold information from the stages even those without +any lead. So to only do this on accessible stages a search is made by +the current user over the stage ids returned by the group_expand method +which is initially launched through a sudo. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACS0NE SA/NV + +Contributors +------------ + +- Quentin Groulard + (`ACSONE `__) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/multi-company `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/crm_stage_multi_company/__init__.py b/crm_stage_multi_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/crm_stage_multi_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/crm_stage_multi_company/__manifest__.py b/crm_stage_multi_company/__manifest__.py new file mode 100644 index 00000000000..f3307cfd409 --- /dev/null +++ b/crm_stage_multi_company/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2019 ACS0NE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Crm Stage Multi Company", + "summary": """ + This module adds support for multi company on crm stage.""", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ACS0NE SA/NV, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/multi-company", + "application": False, + "installable": True, + "depends": ["crm"], + "data": ["views/crm_stage.xml", "security/crm_security.xml"], + "demo": [], +} diff --git a/crm_stage_multi_company/i18n/crm_stage_multi_company.pot b/crm_stage_multi_company/i18n/crm_stage_multi_company.pot new file mode 100644 index 00000000000..ad5ade8dea7 --- /dev/null +++ b/crm_stage_multi_company/i18n/crm_stage_multi_company.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_stage_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: crm_stage_multi_company +#: model:ir.model,name:crm_stage_multi_company.model_crm_stage +msgid "CRM Stages" +msgstr "" + +#. module: crm_stage_multi_company +#: model:ir.model.fields,field_description:crm_stage_multi_company.field_crm_stage__company_id +msgid "Company" +msgstr "" + +#. module: crm_stage_multi_company +#: model:ir.model,name:crm_stage_multi_company.model_crm_lead +msgid "Lead/Opportunity" +msgstr "" + +#. module: crm_stage_multi_company +#: model:ir.model.fields,help:crm_stage_multi_company.field_crm_stage__company_id +msgid "" +"Specific company that uses this stage. Other companies will not be able to " +"see or use this stage." +msgstr "" + +#. module: crm_stage_multi_company +#: model:ir.model.fields,field_description:crm_stage_multi_company.field_crm_lead__stage_id +msgid "Stage" +msgstr "" diff --git a/crm_stage_multi_company/i18n/it.po b/crm_stage_multi_company/i18n/it.po new file mode 100644 index 00000000000..ad82226347c --- /dev/null +++ b/crm_stage_multi_company/i18n/it.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_stage_multi_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-02-24 15:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\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 5.6.2\n" + +#. module: crm_stage_multi_company +#: model:ir.model,name:crm_stage_multi_company.model_crm_stage +msgid "CRM Stages" +msgstr "Fasi CRM" + +#. module: crm_stage_multi_company +#: model:ir.model.fields,field_description:crm_stage_multi_company.field_crm_stage__company_id +msgid "Company" +msgstr "Azienda" + +#. module: crm_stage_multi_company +#: model:ir.model,name:crm_stage_multi_company.model_crm_lead +msgid "Lead/Opportunity" +msgstr "Contatto/Opportunità" + +#. module: crm_stage_multi_company +#: model:ir.model.fields,help:crm_stage_multi_company.field_crm_stage__company_id +msgid "" +"Specific company that uses this stage. Other companies will not be able to " +"see or use this stage." +msgstr "" +"Azienda specifica che utilizza questa fase. Altre aziende non saranno in " +"grado di vedere o utilizzare questa fase." + +#. module: crm_stage_multi_company +#: model:ir.model.fields,field_description:crm_stage_multi_company.field_crm_lead__stage_id +msgid "Stage" +msgstr "Fase" diff --git a/crm_stage_multi_company/models/__init__.py b/crm_stage_multi_company/models/__init__.py new file mode 100644 index 00000000000..bad3e0d449a --- /dev/null +++ b/crm_stage_multi_company/models/__init__.py @@ -0,0 +1,2 @@ +from . import crm_stage +from . import crm_lead diff --git a/crm_stage_multi_company/models/crm_lead.py b/crm_stage_multi_company/models/crm_lead.py new file mode 100644 index 00000000000..0e0acd7fe28 --- /dev/null +++ b/crm_stage_multi_company/models/crm_lead.py @@ -0,0 +1,18 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# Copyright 2025 ACSONE SA/NV (https://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class CrmLead(models.Model): + _inherit = "crm.lead" + + stage_id = fields.Many2one(check_company=True) + + @api.model + def _read_group_stage_ids(self, stages, domain): + # Only return the stages the user has access to due to the new + # multi company rule + res = super()._read_group_stage_ids(stages, domain) + return stages.search([("id", "in", res.ids)]) diff --git a/crm_stage_multi_company/models/crm_stage.py b/crm_stage_multi_company/models/crm_stage.py new file mode 100644 index 00000000000..da0e2ababb9 --- /dev/null +++ b/crm_stage_multi_company/models/crm_stage.py @@ -0,0 +1,18 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class CrmStage(models.Model): + _inherit = "crm.stage" + _check_company_auto = True + + company_id = fields.Many2one( + "res.company", + string="Company", + index=True, + help="Specific company that uses this stage. " + "Other companies will not be able to see or use this stage.", + default=lambda self: self.env.company, + ) diff --git a/crm_stage_multi_company/pyproject.toml b/crm_stage_multi_company/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/crm_stage_multi_company/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/crm_stage_multi_company/readme/CONTRIBUTORS.md b/crm_stage_multi_company/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..85865b1773c --- /dev/null +++ b/crm_stage_multi_company/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Quentin Groulard \ + ([ACSONE](https://acsone.eu/)) diff --git a/crm_stage_multi_company/readme/DESCRIPTION.md b/crm_stage_multi_company/readme/DESCRIPTION.md new file mode 100644 index 00000000000..0216b6920f0 --- /dev/null +++ b/crm_stage_multi_company/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module adds support for multi company on crm stage. + +The new multi company rule prevents any user without access to all stages to open +the CRM application. This behaviour comes from the kanban view and especially from +he read_group (_read_group_fill_results) which tries to retrieve fold information +from the stages even those without any lead. So to only do this on accessible +stages a search is made by the current user over the stage ids returned by the +group_expand method which is initially launched through a sudo. diff --git a/crm_stage_multi_company/security/crm_security.xml b/crm_stage_multi_company/security/crm_security.xml new file mode 100644 index 00000000000..175ca232e7a --- /dev/null +++ b/crm_stage_multi_company/security/crm_security.xml @@ -0,0 +1,8 @@ + + + + CRM Stage Multi-Company + + [('company_id', 'in', company_ids + [False])] + + diff --git a/crm_stage_multi_company/static/description/icon.png b/crm_stage_multi_company/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/crm_stage_multi_company/static/description/icon.png differ diff --git a/crm_stage_multi_company/static/description/index.html b/crm_stage_multi_company/static/description/index.html new file mode 100644 index 00000000000..80e21d40815 --- /dev/null +++ b/crm_stage_multi_company/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Crm Stage Multi Company

+ +

Beta License: AGPL-3 OCA/multi-company Translate me on Weblate Try me on Runboat

+

This module adds support for multi company on crm stage.

+

The new multi company rule prevents any user without access to all +stages to open the CRM application. This behaviour comes from the kanban +view and especially from he read_group (_read_group_fill_results) which +tries to retrieve fold information from the stages even those without +any lead. So to only do this on accessible stages a search is made by +the current user over the stage ids returned by the group_expand method +which is initially launched through a sudo.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACS0NE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/multi-company project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/crm_stage_multi_company/tests/__init__.py b/crm_stage_multi_company/tests/__init__.py new file mode 100644 index 00000000000..102623bad6d --- /dev/null +++ b/crm_stage_multi_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_crm_stage_multi_company diff --git a/crm_stage_multi_company/tests/test_crm_stage_multi_company.py b/crm_stage_multi_company/tests/test_crm_stage_multi_company.py new file mode 100644 index 00000000000..97c6872df00 --- /dev/null +++ b/crm_stage_multi_company/tests/test_crm_stage_multi_company.py @@ -0,0 +1,47 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import AccessError +from odoo.tests.common import TransactionCase + + +class TestCrmStageMultiCompany(TransactionCase): + def setUp(self): + super().setUp() + self.company = self.env["res.company"].create({"name": "Company"}) + self.stage_1 = self.env["crm.stage"].create( + {"name": "Stage 1", "company_id": self.company.id} + ) + self.stage_2 = self.env["crm.stage"].create( + {"name": "Stage 2", "company_id": self.company.id} + ) + self.stage_3 = self.env["crm.stage"].create( + {"name": "Stage 3", "company_id": self.company.id} + ) + self.user = self.env["res.users"].create( + { + "name": "test user", + "login": "test", + "company_id": self.company.id, + "company_ids": [(6, 0, [self.company.id])], + } + ) + + def test_get_stages(self): + stages = self.env["crm.stage"].with_user(self.user).search([]) + stages_2 = self.env["crm.stage"].search([("company_id", "=", self.company.id)]) + self.assertEqual(set(stages), set(stages_2)) + + def test_create_company_stage(self): + with self.assertRaises(AccessError): + self.env["crm.stage"].with_user(self.user).create( + {"name": "Stage 4", "company_id": self.env.user.company_id.id} + ) + + def test_write_other_company_stage(self): + with self.assertRaises(AccessError): + self.env.ref("crm.stage_lead1").with_user(self.user).write({"name": "test"}) + + def test_unlink_other_company_stage(self): + with self.assertRaises(AccessError): + self.env.ref("crm.stage_lead1").with_user(self.user).unlink() diff --git a/crm_stage_multi_company/views/crm_stage.xml b/crm_stage_multi_company/views/crm_stage.xml new file mode 100644 index 00000000000..5bdc3ae9cb9 --- /dev/null +++ b/crm_stage_multi_company/views/crm_stage.xml @@ -0,0 +1,48 @@ + + + + + crm.stage.form (in crm_stage_multi_company) + crm.stage + + + + + + + + + + + crm.stage.tree (in crm_stage_multi_company) + crm.stage + + + + + + + + + + + Stage - Search (in crm_stage_multi_company) + crm.stage + + + + + + + + +