-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
hooks.py
46 lines (41 loc) · 1.54 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2018-2016 Tecnativa - Pedro M. Baeza
# Copyright 2020 - Iván Todorovich
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
"""At installation time, propagate the parent sales team to the children
contacts that have this field empty, as it's supposed that the intention
is to have the same.
"""
cr.execute(
"""UPDATE res_partner
SET team_id=parent.team_id
FROM res_partner AS parent
WHERE parent.team_id IS NOT NULL
AND res_partner.parent_id = parent.id
AND res_partner.team_id IS NULL"""
)
def uninstall_hook(cr, registry): # pragma: no cover
"""At uninstall, revert changes made to record rules"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
env.ref("sales_team.group_sale_salesman_all_leads").write(
{
"implied_ids": [
(6, 0, [env.ref("sales_team.group_sale_salesman").id]),
],
}
)
# At installation time, we need to sync followers
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
partners = env["res.partner"].search(
[
("parent_id", "=", False),
("is_company", "=", True),
"|",
("user_id", "!=", False),
("child_ids.user_id", "!=", False),
]
)
partners._add_followers_from_salesmans()