forked from OCA/operating-unit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
<https://github.com/OCA/operating-unit/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jordi Ballester Alomar <jordi.ballester@eficent.com> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L. | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
<odoo> | ||
<data noupdate="0"> | ||
|
||
<record id="ir_rule_crm_team_allowed_operating_units" | ||
model="ir.rule"> | ||
<field name="model_id" ref="sales_team.model_crm_team"/> | ||
<field name="domain_force">['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field> | ||
<field name="name">Sales Teams from allowed operating units</field> | ||
<field name="global" eval="True"/> | ||
<field eval="0" name="perm_unlink"/> | ||
<field eval="0" name="perm_write"/> | ||
<field eval="1" name="perm_read"/> | ||
<field eval="0" name="perm_create"/> | ||
</record> | ||
|
||
</data> | ||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
69 changes: 69 additions & 0 deletions
69
sales_team_operating_unit/tests/test_crm_team_operating_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0"?> | ||
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L. | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
<openerp> | ||
<data> | ||
|
||
<record id="crm_team_salesteams_search" model="ir.ui.view"> | ||
<field name="name">Case Teams - Search</field> | ||
<field name="model">crm.team</field> | ||
<field name="inherit_id" | ||
ref="sales_team.crm_team_salesteams_search"/> | ||
<field name="arch" type="xml"> | ||
<field name="code" position="after"> | ||
<field name="operating_unit_id" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="crm_team_view_form" model="ir.ui.view"> | ||
<field name="name">crm.team.form</field> | ||
<field name="model">crm.team</field> | ||
<field name="inherit_id" ref="sales_team.crm_team_view_form"/> | ||
<field name="arch" type="xml"> | ||
<page name="more_info" position="inside"> | ||
<group string="Operating Unit" name="group_operating_unit" | ||
groups="operating_unit.group_multi_operating_unit"> | ||
<field name="operating_unit_id" domain = "[('company_id','=', company_id)]" options="{'no_create': True}"/> | ||
</group> | ||
</page> | ||
</field> | ||
</record> | ||
|
||
<record id="crm_team_view_tree" model="ir.ui.view"> | ||
<field name="name">crm.team.tree</field> | ||
<field name="model">crm.team</field> | ||
<field name="inherit_id" | ||
ref="sales_team.crm_team_view_tree"/> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="after"> | ||
<field name="operating_unit_id" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |