Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
235 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,2 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.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,29 @@ | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": 'Project with Operating Units', | ||
"summary": """ | ||
This module adds operating unit information to projects and tasks.""", | ||
"version": "12.0.1.0.0", | ||
"author": "Open Source Integrators, " | ||
"Serpent Consulting Services Pvt. Ltd.," | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/operating-unit", | ||
"category": "Project", | ||
"depends": [ | ||
'operating_unit', | ||
'project' | ||
], | ||
"license": "AGPL-3", | ||
"data": [ | ||
'security/project_security.xml', | ||
'views/project_project.xml', | ||
'views/project_task.xml', | ||
], | ||
'installable': True, | ||
'development_status': 'Beta', | ||
'maintainers': [ | ||
'max3903', | ||
], | ||
} |
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,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from . import project_project | ||
from . import project_task |
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 @@ | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProjectProject(models.Model): | ||
_inherit = 'project.project' | ||
|
||
operating_unit_id = fields.Many2one( | ||
comodel_name='operating.unit', | ||
string='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,16 @@ | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProjectTask(models.Model): | ||
_inherit = 'project.task' | ||
|
||
operating_unit_id = fields.Many2one( | ||
comodel_name='operating.unit', | ||
related="project_id.operating_unit_id", | ||
string='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,2 @@ | ||
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com> | ||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com> |
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,2 @@ | ||
* Open Source Integrators | ||
* Serpent Consulting Services Pvt. Ltd. |
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 @@ | ||
This module adds operating unit information to projects and tasks. |
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,4 @@ | ||
* Go to Project | ||
* You only see the projects and tasks of your operating units | ||
* Create a new project. It is assigned to your default operating unit. | ||
* Create a task within a project. It inherits the operating unit of the project. |
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,31 @@ | ||
<odoo> | ||
|
||
<!-- Copyright (C) 2019 Open Source Integrators | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
|
||
<record id="ir_rule_project_project_operating_unit" model="ir.rule"> | ||
<field name="model_id" ref="project.model_project_project"/> | ||
<field name="domain_force">['|', ('operating_unit_id','=',False), ('operating_unit_id','in',user.operating_unit_ids.ids)] | ||
</field> | ||
<field name="name">Project Operating Unit</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> | ||
|
||
<record id="ir_rule_project_task_operating_unit" model="ir.rule"> | ||
<field name="model_id" ref="project.model_project_task"/> | ||
<field name="domain_force">['|', ('operating_unit_id','=',False), ('operating_unit_id','in',user.operating_unit_ids.ids)] | ||
</field> | ||
<field name="name">Project Task Operating Unit</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> | ||
|
||
</odoo> |
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,2 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from . import test_project_operating_unit |
94 changes: 94 additions & 0 deletions
94
project_operating_unit/tests/test_project_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,94 @@ | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo.tests import common | ||
|
||
|
||
class TestProject(common.TransactionCase): | ||
|
||
def setUp(self): | ||
super(TestProject, self).setUp() | ||
self.project_obj = self.env['project.project'] | ||
self.task_obj = self.env['project.task'] | ||
self.res_users_model = self.env['res.users'] | ||
|
||
self.partner_1 = self.env['res.partner'].create({ | ||
'name': 'SERPENTCS ', | ||
'email': 'serpentcs@gmail.com'}) | ||
|
||
# Groups | ||
self.grp_mngr =\ | ||
self.env.ref('project.group_project_manager') | ||
self.grp_user = self.env.ref('project.group_project_user') | ||
# Company | ||
self.company = self.env.ref('base.main_company') | ||
# Main Operating Unit | ||
self.main_OU = self.env.ref('operating_unit.main_operating_unit') | ||
# B2C Operating Unit | ||
self.b2c_OU = self.env.ref('operating_unit.b2c_operating_unit') | ||
# Create User 1 with Main OU | ||
self.user1 = self._create_user('user_1', [self.grp_mngr, | ||
self.grp_user], | ||
self.company, [self.main_OU]) | ||
# Create User 2 with B2C OU | ||
self.user2 = self._create_user('user_2', [self.grp_mngr, | ||
self.grp_user], | ||
self.company, [self.b2c_OU]) | ||
|
||
self.project1 = self._create_project(self.user1, self.main_OU) | ||
self.project2 = self._create_project(self.user2, self.b2c_OU) | ||
self.task1 = self._create_task(self.user1, self.project1) | ||
self.task2 = self._create_task(self.user2, self.project2) | ||
|
||
def _create_user(self, login, groups, company, operating_units): | ||
""" Create a user. """ | ||
group_ids = [group.id for group in groups] | ||
user = self.res_users_model.create({ | ||
'name': login, | ||
'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_project(self, uid, operating_unit): | ||
project = self.project_obj.sudo(uid).create({ | ||
'name': 'Test Project', | ||
'operating_unit_id': operating_unit.id, | ||
'privacy_visibility': 'employees', | ||
'partner_id': self.partner_1.id | ||
}) | ||
return project | ||
|
||
def _create_task(self, uid, project): | ||
task = self.task_obj.sudo(uid).create({ | ||
'name': 'Test Task', | ||
'user_id': uid.id, | ||
'project_id': project.id | ||
}) | ||
return task | ||
|
||
def test_project(self): | ||
# User 2 is only assigned to B2C Operating Unit, and cannot | ||
# access Project for Main Operating Unit. | ||
projects = self.project_obj.sudo(self.user2.id).search( | ||
[('id', '=', self.project2.id), | ||
('operating_unit_id', '=', self.main_OU.id)]) | ||
self.assertEqual(projects.ids, [], 'User 2 should not have access to ' | ||
'%s' % self.main_OU.name) | ||
self.assertEqual(self.project1.operating_unit_id.id, self.main_OU.id) | ||
|
||
def test_project_task(self): | ||
# User 2 is only assigned to B2C Operating Unit, and cannot | ||
# access Task for Main Operating Unit. | ||
tasks = self.task_obj.sudo(self.user2.id).search( | ||
[('id', '=', self.task2.id), | ||
('operating_unit_id', '=', self.main_OU.id)]) | ||
self.assertEqual(tasks.ids, [], 'User 2 should not have access to ' | ||
'%s' % self.main_OU.name) | ||
self.assertEqual(self.task1.operating_unit_id.id, | ||
self.project1.operating_unit_id.id) |
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,17 @@ | ||
<odoo> | ||
<!-- Copyright (C) 2019 Open Source Integrators | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
|
||
<record id="view_edit_project_form_inherit" model="ir.ui.view"> | ||
<field name="name">project.project.form</field> | ||
<field name="model">project.project</field> | ||
<field name="inherit_id" ref="project.edit_project"/> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="after"> | ||
<field name="operating_unit_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
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,17 @@ | ||
<odoo> | ||
<!-- Copyright (C) 2019 Open Source Integrators | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
|
||
<record id="view_view_task_form2_inherit" model="ir.ui.view"> | ||
<field name="name">project.task.form</field> | ||
<field name="model">project.task</field> | ||
<field name="inherit_id" ref="project.view_task_form2"/> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="after"> | ||
<field name="operating_unit_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |