Skip to content

Commit

Permalink
[ADD] new module project_customer_access
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément Mombereau committed Dec 20, 2024
1 parent a1c0eb3 commit a36b806
Show file tree
Hide file tree
Showing 13 changed files with 489 additions and 0 deletions.
32 changes: 32 additions & 0 deletions project_customer_access/README.rst
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
===========

...
1 change: 1 addition & 0 deletions project_customer_access/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions project_customer_access/__manifest__.py
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": [],
}
18 changes: 18 additions & 0 deletions project_customer_access/data/res_groups.xml
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>
2 changes: 2 additions & 0 deletions project_customer_access/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import project
from . import res_users
16 changes: 16 additions & 0 deletions project_customer_access/models/project.py
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"
17 changes: 17 additions & 0 deletions project_customer_access/models/res_users.py
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
)
5 changes: 5 additions & 0 deletions project_customer_access/security/ir.model.access.csv
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
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>
1 change: 1 addition & 0 deletions project_customer_access/static/description/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions project_customer_access/tests/__init__.py
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 project_customer_access/tests/test_project_customer_access.py
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)
Loading

0 comments on commit a36b806

Please sign in to comment.