Skip to content

Commit c514755

Browse files
committed
[MIG] res_partner_operating_unit: Migration to 18.0
1 parent 5ba08cc commit c514755

File tree

8 files changed

+64
-45
lines changed

8 files changed

+64
-45
lines changed

res_partner_operating_unit/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Contributors
7373
- Edi Santoso <[email protected]>
7474
- Maxime Chambreuil <[email protected]>
7575
- Hiren Dangar <[email protected]>
76+
`Komit <https://komit-consulting.com>`__:
77+
- Cai Hoang Huynh
7678

7779
Other credits
7880
-------------

res_partner_operating_unit/__manifest__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
{
44
"name": "Partner with Operating Unit",
55
"summary": "Introduces Operating Unit fields in Partner",
6-
"version": "12.0.1.1.1",
6+
"version": "18.0.1.1.1",
77
"author": "Edi Santoso, " "Niaga Solution, " "Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/operating-unit",
99
"category": "Generic",
1010
"depends": ["operating_unit"],
1111
"license": "LGPL-3",
12-
"data": [
13-
"views/res_partner_view.xml",
14-
],
12+
"data": ["security/res_partner_security.xml", "views/res_partner_view.xml"],
1513
"installable": True,
14+
"pre_init_hook": "pre_init_hook",
1615
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# See LICENSE and COPYRIGHT files for full licensing and copyright details.
2+
# Copyright (C) 2020 Open Source Integrators
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
6+
def pre_init_hook(env):
7+
# Add new table and columns to hold values
8+
env.cr.execute("""
9+
CREATE TABLE operating_unit_partner_rel (
10+
partner_id INTEGER NOT NULL
11+
REFERENCES res_partner(id) ON DELETE CASCADE,
12+
operating_unit_id INTEGER NOT NULL
13+
REFERENCES operating_unit(id) ON DELETE CASCADE);
14+
""")
15+
# Add the values
16+
env.cr.execute("""
17+
INSERT INTO operating_unit_partner_rel
18+
(partner_id, operating_unit_id)
19+
SELECT id, 1 FROM res_partner;
20+
""")

res_partner_operating_unit/models/res_partner.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,6 @@ def _default_operating_units(self):
2828
"partner_id",
2929
"operating_unit_id",
3030
"Operating Units",
31+
required=True,
3132
default=lambda self: self._default_operating_units(),
3233
)
33-
34-
# Extending methods to replace a record rule.
35-
# Ref: https://github.com/OCA/operating-unit/issues/258
36-
@api.model
37-
def search(self, args, offset=0, limit=None, order=None, count=False):
38-
# Get the OUs of the user
39-
ou_ids = self.env.user.operating_unit_ids.ids
40-
domain = [
41-
"|",
42-
("operating_unit_ids", "in", ou_ids),
43-
("operating_unit_ids", "=", False),
44-
]
45-
return super().search(
46-
domain + args, offset=offset, limit=limit, order=order, count=count
47-
)
48-
49-
@api.model
50-
def search_count(self, args):
51-
# Get the OUs of the user
52-
ou_ids = self.env.user.operating_unit_ids.ids
53-
domain = [
54-
"|",
55-
("operating_unit_ids", "in", ou_ids),
56-
("operating_unit_ids", "=", False),
57-
]
58-
return super().search_count(domain + args)

res_partner_operating_unit/models/res_users.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22
# Copyright (C) 2019 Serpent Consulting Services
33
# Copyright (C) 2019 Open Source Integrators
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
5-
from odoo import _, api, models
5+
from odoo import api, models
66
from odoo.exceptions import UserError
77

88

99
class ResUsers(models.Model):
1010
_inherit = "res.users"
1111

12-
@api.model
13-
def create(self, vals):
14-
res = super().create(vals)
12+
@api.model_create_multi
13+
def create(self, vals_list):
14+
res = super().create(vals_list)
1515
res.partner_id.operating_unit_ids = [(4, res.default_operating_unit_id.id)]
16+
res.check_partner_operating_unit()
1617
return res
1718

18-
@api.multi
1919
def write(self, vals):
20-
res = super().write(vals)
21-
if vals.get("default_operating_unit_id"):
22-
# Add the new OU
23-
self.partner_id.operating_unit_ids = [
24-
(4, vals["default_operating_unit_id"])
25-
]
26-
return res
20+
for user in self:
21+
res = super().write(vals)
22+
if vals.get("default_operating_unit_id"):
23+
# Add the new OU
24+
user.partner_id.operating_unit_ids = [
25+
(4, user.default_operating_unit_id.id)
26+
]
27+
user.check_partner_operating_unit()
28+
return res
2729

28-
@api.constrains("partner_id.operating_unit_ids", "default_operating_unit_id")
2930
def check_partner_operating_unit(self):
3031
if (
3132
self.partner_id.operating_unit_ids
3233
and self.default_operating_unit_id.id
3334
not in self.partner_id.operating_unit_ids.ids
3435
):
3536
raise UserError(
36-
_(
37+
self.env._(
3738
"The operating units of the partner must include the default "
3839
"one of the user."
3940
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
- Edi Santoso \<[email protected]\>
22
- Maxime Chambreuil \<[email protected]\>
33
- Hiren Dangar \<[email protected]\>
4+
[Komit](https://komit-consulting.com):
5+
- Cai Hoang Huynh
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<odoo noupdate="1">
2+
<!-- Copyright 2017 Niaga Solution - Edi Santoso <[email protected]>
3+
Copyright (C) 2019 Serpent Consulting Services
4+
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
5+
6+
<record id="ir_rule_res_partner_allowed_operating_units" model="ir.rule">
7+
<field name="model_id" ref="base.model_res_partner" />
8+
<field
9+
name="domain_force"
10+
>[('operating_unit_ids', 'in', user.operating_unit_ids.ids)]</field>
11+
<field name="name">Partner from allowed operating units</field>
12+
<field name="global" eval="True" />
13+
<field eval="0" name="perm_unlink" />
14+
<field eval="0" name="perm_write" />
15+
<field eval="1" name="perm_read" />
16+
<field eval="0" name="perm_create" />
17+
</record>
18+
</odoo>

res_partner_operating_unit/static/description/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
422422
<ul class="simple">
423423
<li>Edi Santoso &lt;<a class="reference external" href="mailto:repodevs&#64;gmail.com">repodevs&#64;gmail.com</a>&gt;</li>
424424
<li>Maxime Chambreuil &lt;<a class="reference external" href="mailto:mchambreuil&#64;opensourceintegrators.com">mchambreuil&#64;opensourceintegrators.com</a>&gt;</li>
425-
<li>Hiren Dangar &lt;<a class="reference external" href="mailto:hiren.dangar.serpentcs&#64;gmail.com">hiren.dangar.serpentcs&#64;gmail.com</a>&gt;</li>
425+
<li>Hiren Dangar &lt;<a class="reference external" href="mailto:hiren.dangar.serpentcs&#64;gmail.com">hiren.dangar.serpentcs&#64;gmail.com</a>&gt;
426+
<a class="reference external" href="https://komit-consulting.com">Komit</a>:</li>
427+
<li>Cai Hoang Huynh</li>
426428
</ul>
427429
</div>
428430
<div class="section" id="other-credits">

0 commit comments

Comments
 (0)