Skip to content

Commit 00f53cc

Browse files
committed
[19.0][MIG] sale_operating_unit: Migration to 19.0
1 parent 1c00390 commit 00f53cc

File tree

7 files changed

+74
-20
lines changed

7 files changed

+74
-20
lines changed

sale_operating_unit/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ Contributors
9494

9595
- Bhavesh Heliconia
9696

97+
- `Camptocamp <https://www.camptocamp.com>`__:
98+
99+
- Maksym Yankin <maksym.yankin@camptocamp.com>
100+
97101
Maintainers
98102
-----------
99103

sale_operating_unit/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
55
{
66
"name": "Operating Unit in Sales",
7-
"version": "18.0.1.0.0",
7+
"version": "19.0.1.0.0",
88
"summary": "An operating unit (OU) is an organizational entity part of a company",
99
"author": "ForgeFlow, "
1010
"Serpent Consulting Services Pvt. Ltd.,"

sale_operating_unit/models/crm_team.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
55
from odoo import SUPERUSER_ID, api, models
66
from odoo.exceptions import ValidationError
7+
from odoo.fields import Domain
78

89

910
class CrmTeam(models.Model):
@@ -16,10 +17,12 @@ def _check_sales_order_operating_unit(self):
1617
self.with_user(SUPERUSER_ID)
1718
.env["sale.order"]
1819
.search(
19-
[
20-
("team_id", "=", rec.id),
21-
("operating_unit_id", "!=", rec.operating_unit_id.id),
22-
]
20+
Domain.AND(
21+
[
22+
Domain("team_id", "=", rec.id),
23+
Domain("operating_unit_id", "!=", rec.operating_unit_id.id),
24+
]
25+
)
2326
)
2427
)
2528
if orders:

sale_operating_unit/models/sale_order.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
55
from odoo import api, fields, models
66
from odoo.exceptions import ValidationError
7+
from odoo.fields import Domain
78

89

910
class SaleOrder(models.Model):
@@ -48,15 +49,35 @@ def _compute_journal_id(self):
4849
sale.journal_id = (
4950
self.env["account.journal"]
5051
.search(
51-
[
52-
"|",
53-
("operating_unit_id", "=", sale.operating_unit_id.id),
54-
("operating_unit_id", "=", False),
55-
"|",
56-
("company_id", "=", sale.company_id.id),
57-
("company_id", "=", False),
58-
("type", "=", "sale"),
59-
],
52+
Domain.AND(
53+
[
54+
Domain.AND(
55+
[
56+
Domain.OR(
57+
[
58+
Domain(
59+
"operating_unit_id",
60+
"=",
61+
sale.operating_unit_id.id,
62+
),
63+
Domain("operating_unit_id", "=", False),
64+
]
65+
),
66+
Domain.OR(
67+
[
68+
Domain(
69+
"company_id",
70+
"=",
71+
sale.company_id.id,
72+
),
73+
Domain("company_id", "=", False),
74+
]
75+
),
76+
]
77+
),
78+
Domain("type", "=", "sale"),
79+
]
80+
),
6081
limit=1,
6182
)
6283
.id

sale_operating_unit/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- Alejandro Padrón \<<alejandro.padron@bt-group.com>\>
1010
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
1111
- Bhavesh Heliconia
12+
- [Camptocamp](https://www.camptocamp.com):
13+
- Maksym Yankin \<maksym.yankin@camptocamp.com\>

sale_operating_unit/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
442442
<li>Bhavesh Heliconia</li>
443443
</ul>
444444
</li>
445+
<li><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a>:<ul>
446+
<li>Maksym Yankin &lt;<a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a>&gt;</li>
447+
</ul>
448+
</li>
445449
</ul>
446450
</div>
447451
<div class="section" id="maintainers">

sale_operating_unit/tests/test_sale_operating_unit.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
55

66
from odoo.exceptions import ValidationError
7-
from odoo.models import Command
7+
from odoo.fields import Command, Domain
88

99
from odoo.addons.operating_unit.tests.common import OperatingUnitCommon
1010

@@ -27,7 +27,7 @@ def setUpClass(cls):
2727
# Customer
2828
cls.customer = cls.env.ref("base.res_partner_2")
2929
# Price list
30-
cls.pricelist = cls.env["product.pricelist"].search([], limit=1)
30+
cls.pricelist = cls.env["product.pricelist"].search(Domain.TRUE, limit=1)
3131
# Products
3232
cls.product1 = cls.env.ref("product.product_product_2")
3333
cls.product1.write({"invoice_policy": "order"})
@@ -138,7 +138,12 @@ def test_security(self):
138138
# User 2 is only assigned to Operating Unit B2C, and cannot
139139
# Access Sales order from Main Operating Unit.
140140
sale = self.sale_model.with_user(self.user2.id).search(
141-
[("id", "=", self.sale1.id), ("operating_unit_id", "=", self.ou1.id)]
141+
Domain.AND(
142+
[
143+
Domain("id", "=", self.sale1.id),
144+
Domain("operating_unit_id", "=", self.ou1.id),
145+
]
146+
)
142147
)
143148
self.assertEqual(
144149
sale.ids, [], f"User 2 should not have access to OU {self.ou1.name}"
@@ -149,7 +154,12 @@ def test_security(self):
149154
b2c_invoice_id = self._confirm_sale(self.sale2)
150155
# Checks that invoice has OU b2c
151156
b2c = self.acc_move_model.with_user(self.user2.id).search(
152-
[("id", "=", b2c_invoice_id), ("operating_unit_id", "=", self.b2c.id)]
157+
Domain.AND(
158+
[
159+
Domain("id", "=", b2c_invoice_id),
160+
Domain("operating_unit_id", "=", self.b2c.id),
161+
]
162+
)
153163
)
154164
self.assertNotEqual(b2c.ids, [], "Invoice should have b2c OU")
155165

@@ -158,14 +168,24 @@ def test_security_2(self):
158168
# User 2 is only assigned to Operating Unit B2C, and cannot
159169
# Access Sales order from Main Operating Unit.
160170
sale = self.sale_model.with_user(self.user2.id).search(
161-
[("id", "=", self.sale1.id), ("operating_unit_id", "=", self.ou1.id)]
171+
Domain.AND(
172+
[
173+
Domain("id", "=", self.sale1.id),
174+
Domain("operating_unit_id", "=", self.ou1.id),
175+
]
176+
)
162177
)
163178
self.assertEqual(
164179
sale.ids, [], f"User 2 should not have access to OU {self.ou1.name}"
165180
)
166181

167182
sale = self.sale_model.with_user(self.user2.id).search(
168-
[("id", "=", self.sale2.id), ("operating_unit_id", "=", self.b2c.id)]
183+
Domain.AND(
184+
[
185+
Domain("id", "=", self.sale2.id),
186+
Domain("operating_unit_id", "=", self.b2c.id),
187+
]
188+
)
169189
)
170190

171191
self.assertEqual(

0 commit comments

Comments
 (0)