-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] new module project_customer_access
- Loading branch information
Clément Mombereau
committed
Dec 20, 2024
1 parent
a1c0eb3
commit a36b806
Showing
13 changed files
with
489 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,32 @@ | ||
======================= | ||
Project Customer Access | ||
======================= | ||
|
||
Project menu and views for customers in your own ERP | ||
|
||
Purpose | ||
======= | ||
|
||
This module does this and that... | ||
|
||
Explain the use case. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
#. Go to ... | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Go to ... | ||
|
||
|
||
How to test | ||
=========== | ||
|
||
... |
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 @@ | ||
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,23 @@ | ||
# Copyright 2024 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Project Customer Access", | ||
"summary": """Project menu and views for customers in your own ERP""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Akretion", | ||
"website": "http://akretion.com", | ||
"depends": [ | ||
"project", | ||
# https://github.com/OCA/server-backend | ||
"base_group_backend", | ||
], | ||
"data": [ | ||
"data/res_groups.xml", | ||
"security/ir.model.access.csv", | ||
"security/project_customer_access_security.xml", | ||
"views/project_task_views.xml", | ||
], | ||
"demo": [], | ||
} |
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,18 @@ | ||
<odoo> | ||
|
||
<record id="project_access_category" model="ir.module.category"> | ||
<field name="name">Project Access</field> | ||
<field name="sequence">90</field> | ||
</record> | ||
<record id="group_customer" model="res.groups"> | ||
<field name="name">Customer</field> | ||
<field name="category_id" ref="project_customer_access.project_access_category"/> | ||
<field name="implied_ids" eval="[(4, ref('base_group_backend.group_backend_ui_users'))]"/> | ||
</record> | ||
<record id="group_manager" model="res.groups"> | ||
<field name="name">Manager</field> | ||
<field name="category_id" ref="project_customer_access.project_access_category"/> | ||
<field name="implied_ids" eval="[(4, ref('project_customer_access.group_customer'))]"/> | ||
</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 @@ | ||
from . import project | ||
from . import res_users |
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 2024 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
|
||
|
||
class ProjectProject(models.Model): | ||
_inherit = "project.project" | ||
|
||
authorized_user_ids = fields.Many2many( | ||
"res.users", "project_authorized_user_rel", "project_id", "user_id" | ||
) | ||
|
||
|
||
class ProjectTask(models.Model): | ||
_inherit = "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,17 @@ | ||
# Copyright 2024 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = "res.users" | ||
|
||
project_ids = fields.Many2many("project.project", compute="_compute_project_ids") | ||
|
||
def _compute_project_ids(self): | ||
for rec in self: | ||
project_ids = self.env["project.project"].search([]) | ||
rec.project_ids = project_ids.filtered( | ||
lambda p: rec in p.authorized_user_ids | ||
) |
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 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_customer_project,access_customer_project,project.model_project_project,project_customer_access.group_customer,1,0,0,0 | ||
access_customer_task,access_customer_task,project.model_project_task,project_customer_access.group_customer,1,0,0,0 | ||
access_customer_task_type,access_customer_task_type,project.model_project_task_type,project_customer_access.group_customer,1,0,0,0 | ||
access_project_customer_manager,access_project_customer_manager,project.model_project_task,project_customer_access.group_manager,1,1,1,1 |
28 changes: 28 additions & 0 deletions
28
project_customer_access/security/project_customer_access_security.xml
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,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data noupdate="1"> | ||
|
||
<!-- <record id="rule_project_access_customer" model="ir.rule"> | ||
<field name="name">Project Access: Customer</field> | ||
<field name="model_id" ref="project.model_project_project"/> | ||
<field name="domain_force">[('user_id','=',user.id)]</field> | ||
<field name="groups" eval="[(4,ref('project_customer_access.group_customer'))]"/> | ||
</record> --> | ||
|
||
<!-- <record id="rule_project_access_task_customer" model="ir.rule"> | ||
<field name="name">Project Access Tasks: Customer</field> | ||
<field name="model_id" ref="project.model_project_task"/> | ||
==>> Inverted domain DON'T WORK | ||
<field name="domain_force">[(user.partner_id.id,'in', 'project_id.message_partner_ids')]</field> | ||
<field name="groups" eval="[(4,ref('project_customer_access.group_customer'))]"/> | ||
</record> --> | ||
|
||
<record id="rule_project_access_task_customer" model="ir.rule"> | ||
<field name="name">Project Access Tasks: Customer</field> | ||
<field name="model_id" ref="project.model_project_task"/> | ||
<field name="domain_force">[('project_id','in', user.project_ids.ids)]</field> | ||
<field name="groups" eval="[(4,ref('project_customer_access.group_customer'))]"/> | ||
</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 @@ | ||
from . import test_project_customer_access |
35 changes: 35 additions & 0 deletions
35
project_customer_access/tests/test_project_customer_access.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,35 @@ | ||
# Copyright 2024 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import Command | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProjectCustomerAccess(TransactionCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.group_customer = self.env.ref("project_customer_access.group_customer") | ||
self.group_manager = self.env.ref("project_customer_access.group_manager") | ||
self.customer = self.env["res.users"].create( | ||
{ | ||
"name": "Customer", | ||
"login": "test_customer", | ||
"groups_id": [Command.set(self.group_customer.ids)], | ||
} | ||
) | ||
self.manager = self.env["res.users"].create( | ||
{ | ||
"name": "Manager", | ||
"login": "test_manager", | ||
"groups_id": [Command.set(self.group_manager.ids)], | ||
} | ||
) | ||
self.project = self.env.ref("project.project_project_1") | ||
|
||
def test_user_project_ids(self): | ||
print(self.project.authorized_user_ids) | ||
self.project.write({"authorized_user_ids": [Command.link(self.customer.id)]}) | ||
# self.project.write({"authorized_user_ids": [(4, self.customer)]}) | ||
# [(4, self.env.uid)] | ||
self.assertIn(self.project, self.customer.project_ids) |
Oops, something went wrong.