Skip to content

Commit 0c6551c

Browse files
committed
[DEL] #696 replace complex department domain with filter for same OU
1 parent a051796 commit 0c6551c

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

ps_crm/models/crm_lead.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2018 - 2023 The Open Source Company ((www.tosc.nl).)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
import json
54
from datetime import timedelta
65

76
from dateutil.relativedelta import relativedelta
@@ -39,11 +38,6 @@ class Lead(models.Model):
3938
"lead_id",
4039
string="Revenue split",
4140
)
42-
dept_ou_domain = fields.Char(
43-
compute="_compute_dept_ou_domain",
44-
readonly=True,
45-
store=False,
46-
)
4741

4842
@api.depends("monthly_revenue_ids.date")
4943
def _compute_latest_revenue_date(self):
@@ -66,42 +60,6 @@ def _compute_show_recalculate_total_button(self):
6660
this.expected_revenue != this.sum_monthly_revenue
6761
)
6862

69-
@api.depends("operating_unit_id")
70-
def _compute_dept_ou_domain(self):
71-
"""
72-
Compute the domain for the department domain.
73-
"""
74-
department_ids = []
75-
if self.operating_unit_id:
76-
self.env.cr.execute(
77-
"""
78-
SELECT id
79-
FROM hr_department
80-
WHERE operating_unit_id = %s
81-
AND parent_id IS NULL
82-
""",
83-
(self.operating_unit_id.id,),
84-
)
85-
86-
result = self.env.cr.fetchall()
87-
for res in result:
88-
department_id = res[0]
89-
self.env.cr.execute(
90-
"""
91-
WITH RECURSIVE
92-
subordinates AS(
93-
SELECT id, parent_id FROM hr_department WHERE id = %s
94-
UNION
95-
SELECT h.id, h.parent_id FROM hr_department h
96-
INNER JOIN subordinates s ON s.id = h.parent_id)
97-
SELECT * FROM subordinates""",
98-
(department_id,),
99-
)
100-
result2 = self.env.cr.fetchall()
101-
for res2 in result2:
102-
department_ids.append(res2[0])
103-
self.dept_ou_domain = json.dumps([("id", "in", department_ids)])
104-
10563
@api.model
10664
def default_get(self, fields):
10765
res = super().default_get(fields)

ps_crm/views/crm_lead.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@
7373
<attribute name="invisible">True</attribute>
7474
</field>
7575
<xpath expr="//field[@name='team_id']" position="after">
76-
<field name="dept_ou_domain" invisible="1" />
77-
<field name="department_id" domain="dept_ou_domain" />
76+
<field
77+
name="department_id"
78+
domain="[('operating_unit_id', '=', operating_unit_id)]"
79+
/>
7880
</xpath>
7981
<xpath expr="//field[@name='team_id']" position="attributes">
8082
<attribute name="invisible">1</attribute>

0 commit comments

Comments
 (0)