diff --git a/sales_team_operating_unit/README.rst b/sales_team_operating_unit/README.rst new file mode 100644 index 000000000..7510a26cf --- /dev/null +++ b/sales_team_operating_unit/README.rst @@ -0,0 +1,61 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +========================= +Sales Team Operating Unit +========================= + +This module introduces the following features: + +* Adds the Operating Unit (OU) to the Sales Team. + +* The user's default Operating Unit (OU) is proposed at the time of creating + the Sales Team. + +* Security rules are defined to ensure that users can only see the Sales Team + of that Operating Units in which they are allowed access to. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.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 smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar + +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 https://odoo-community.org. diff --git a/sales_team_operating_unit/__init__.py b/sales_team_operating_unit/__init__.py new file mode 100644 index 000000000..b6f6916a4 --- /dev/null +++ b/sales_team_operating_unit/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models diff --git a/sales_team_operating_unit/__openerp__.py b/sales_team_operating_unit/__openerp__.py new file mode 100644 index 000000000..7750bffec --- /dev/null +++ b/sales_team_operating_unit/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Sales Team Operating Unit", + "version": "9.0.1.0.0", + "author": "Eficent, " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Sales", + "depends": ["sales_team", "operating_unit"], + "data": [ + "views/crm_team_view.xml", + "security/crm_security.xml", + ], + 'installable': True, +} diff --git a/sales_team_operating_unit/models/__init__.py b/sales_team_operating_unit/models/__init__.py new file mode 100644 index 000000000..57b490601 --- /dev/null +++ b/sales_team_operating_unit/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import crm_team diff --git a/sales_team_operating_unit/models/crm_team.py b/sales_team_operating_unit/models/crm_team.py new file mode 100644 index 000000000..bbb5300c7 --- /dev/null +++ b/sales_team_operating_unit/models/crm_team.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp import fields, models + + +class CRMTeam(models.Model): + + _inherit = 'crm.team' + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid)) diff --git a/sales_team_operating_unit/security/crm_security.xml b/sales_team_operating_unit/security/crm_security.xml new file mode 100644 index 000000000..54a11eb6d --- /dev/null +++ b/sales_team_operating_unit/security/crm_security.xml @@ -0,0 +1,20 @@ + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Sales Teams from allowed operating units + + + + + + + + + diff --git a/sales_team_operating_unit/static/description/icon.png b/sales_team_operating_unit/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sales_team_operating_unit/static/description/icon.png differ diff --git a/sales_team_operating_unit/tests/__init__.py b/sales_team_operating_unit/tests/__init__.py new file mode 100644 index 000000000..4254efc93 --- /dev/null +++ b/sales_team_operating_unit/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_crm_team_operating_unit diff --git a/sales_team_operating_unit/tests/test_crm_team_operating_unit.py b/sales_team_operating_unit/tests/test_crm_team_operating_unit.py new file mode 100644 index 000000000..aaec15871 --- /dev/null +++ b/sales_team_operating_unit/tests/test_crm_team_operating_unit.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp.tests import common + + +class TestSaleTeamOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestSaleTeamOperatingUnit, self).setUp() + self.res_users_model = self.env['res.users'] + self.crm_team_model = self.registry('crm.team') + # Groups + self.grp_sale_mngr = self.env.ref('base.group_sale_manager') + self.grp_user = self.env.ref('base.group_user') + # Company + self.company = self.env.ref('base.main_company') + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + # Create User 1 with Main OU + self.user1 = self._create_user('user_1', [self.grp_sale_mngr, + self.grp_user], self.company, + [self.ou1]) + # Create User 2 with B2C OU + self.user2 = self._create_user('user_2', [self.grp_sale_mngr, + self.grp_user], self.company, + [self.b2c]) + # Create CRM teams + self.team1 = self._create_crm_team(self.user1.id, self.ou1) + self.team2 = self._create_crm_team(self.user2.id, self.b2c) + + def _create_user(self, login, groups, company, operating_units, + context=None): + """ Create a user. """ + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': 'Test User', + 'login': login, + 'password': 'demo', + 'email': 'test@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'operating_unit_ids': [(4, ou.id) for ou in operating_units], + 'groups_id': [(6, 0, group_ids)] + }) + return user + + def _create_crm_team(self, uid, operating_unit): + """Create a sale order.""" + context = {'mail_create_nosubscribe': True} + crm = self.crm_team_model.create(self.cr, uid, + {'name': 'CRM team', + 'operating_unit_id': + operating_unit.id}, + context=context) + return crm + + def test_crm_team(self): + # User 2 is only assigned to B2C Operating Unit, and cannot + # access CRM teams for Main Operating Unit. + + team = self.crm_team_model.search( + self.cr, self.user2.id, [('id', '=', self.team1), + ('operating_unit_id', '=', self.ou1.id)]) + self.assertEqual(team, [], 'User 2 should not have access to ' + '%s' % self.ou1.name) diff --git a/sales_team_operating_unit/views/crm_team_view.xml b/sales_team_operating_unit/views/crm_team_view.xml new file mode 100644 index 000000000..fda6cd523 --- /dev/null +++ b/sales_team_operating_unit/views/crm_team_view.xml @@ -0,0 +1,46 @@ + + + + + + + Case Teams - Search + crm.team + + + + + + + + + + crm.team.form + crm.team + + + + + + + + + + + + crm.team.tree + crm.team + + + + + + + + + +