Skip to content

Commit

Permalink
[MIG] sales_team_security: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cesar-tecnativa committed Jun 28, 2022
1 parent 11a12f6 commit c9a5532
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 15 deletions.
9 changes: 6 additions & 3 deletions sales_team_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
{
"name": "Sales documents permissions by channels (teams)",
"summary": "New group for seeing only sales channel's documents",
"version": "14.0.2.0.0",
"version": "15.0.1.0.0",
"category": "Sales",
"website": "https:/OCA/sale-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["pedrobaeza", "ivantodorovich"],
"depends": ["sales_team"],
"data": ["security/sales_team_security.xml", "views/res_partner_view.xml"],
"depends": ["sales_team", "sale", "crm"],
"data": [
"security/sales_team_security.xml",
"views/res_partner_view.xml",
],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
81 changes: 81 additions & 0 deletions sales_team_security/models/ir_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,85 @@ def _compute_domain(self, model_name, mode="read"):
]
extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])
if model_name == "sale.order" and not self.env.su:
if user.has_group(group2):
extra_domain = [
"|",
"|",
("user_id", "=", user.id),
("user_id", "=", False),
"|",
("team_id", "=", user.sale_team_id.id),
("team_id", "=", False),
]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])

if model_name == "sale.report" and not self.env.su:
if user.has_group(group2):
extra_domain = [
"|",
"|",
("user_id", "=", user.id),
("user_id", "=", False),
"|",
("team_id", "=", user.sale_team_id.id),
("team_id", "=", False),
]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])

if model_name == "sale.order.line" and not self.env.su:
if user.has_group(group2):
extra_domain = [
"|",
"|",
("salesman_id", "=", user.id),
("salesman_id", "=", False),
"|",
("order_id.team_id", "=", user.sale_team_id.id),
("order_id.team_id", "=", False),
]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])

if model_name == "crm.lead" and not self.env.su:
if user.has_group(group2):
extra_domain = [
"|",
"|",
("user_id", "=", user.id),
("user_id", "=", False),
"|",
("team_id", "=", user.sale_team_id.id),
("team_id", "=", False),
]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])

if model_name == "crm.activity.report" and not self.env.su:
if user.has_group(group2):
extra_domain = [
"|",
"|",
("user_id", "=", user.id),
("user_id", "=", False),
"|",
("team_id", "=", user.sale_team_id.id),
("team_id", "=", False),
]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])
if model_name == "crm.team" and not self.env.su:
if user.has_group(group1):
extra_domain = [("id", "=", user.sale_team_id.id)]

extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])

return res
1 change: 1 addition & 0 deletions sales_team_security/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Pedro M. Baeza
* Víctor Martínez
* César A. Sánchez

* `Guadaltech <https://www.guadaltech.es>`__:

Expand Down
4 changes: 3 additions & 1 deletion sales_team_security/security/sales_team_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<field name="name">User: Team Documents Only</field>
<field
name="comment"
>The user will have an access to the documents of the sales teams he/she belongs to.</field>
>The user will have an access to the documents of the sales teams he/she belongs to.
</field>
<field name="category_id" ref="base.module_category_sales_sales" />
<field name="implied_ids" eval="[(4, ref('sales_team.group_sale_salesman'))]" />
</record>
Expand All @@ -14,4 +15,5 @@
<field name="implied_ids" eval="[(6, 0, [ref('group_sale_team_manager')])]" />
</record>


</odoo>
37 changes: 26 additions & 11 deletions sales_team_security/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ class TestCommon(common.SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.team = cls.env.ref("sales_team.team_sales_department")
cls.team2 = cls.env.ref("sales_team.crm_team_1")

cls.team = cls.env["crm.team"].create({"name": "Test channel"})
cls.team2 = cls.env["crm.team"].create({"name": "Test channel 2"})

cls.user = cls.env["res.users"].create(
{
"login": "sales_team_security",
"name": "Test sales_team_security user",
"groups_id": [(4, cls.env.ref("sales_team.group_sale_salesman").id)],
}
)

cls.crm_team_member = cls.env["crm.team.member"].create(
{
"user_id": cls.user.id,
"crm_team_id": cls.team.id,
}
)

cls.partner = cls.env["res.partner"].create(
{"name": "Test partner", "team_id": cls.team.id}
)
Expand All @@ -20,22 +37,20 @@ def setUpClass(cls):
cls.partner_child_2 = cls.env["res.partner"].create(
{"name": "Child 2", "parent_id": cls.partner.id, "type": "invoice"}
)
cls.user = cls.env["res.users"].create(
{
"login": "sales_team_security",
"name": "Test sales_team_security user",
"groups_id": [(4, cls.env.ref("sales_team.group_sale_salesman").id)],
"sale_team_id": cls.team.id,
}
)
cls.user2 = cls.env["res.users"].create(
{
"login": "sales_team_security2",
"name": "Test sales_team_security user 2",
"groups_id": [(4, cls.env.ref("sales_team.group_sale_salesman").id)],
"sale_team_id": cls.team.id,
}
)
cls.crm_team_member2 = cls.env["crm.team.member"].create(
{
"user_id": cls.user2.id,
"crm_team_id": cls.team.id,
}
)

cls.check_permission_subscribe = False

def _check_permission(self, salesman, team, expected):
Expand Down

0 comments on commit c9a5532

Please sign in to comment.