Skip to content

Commit 5553c6f

Browse files
committed
[18.0][MIG] pos_operating_unit: migrate to 18.0
1 parent 246ac16 commit 5553c6f

File tree

8 files changed

+297
-75
lines changed

8 files changed

+297
-75
lines changed

pos_operating_unit/README.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ POS with Operating Units
1717
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1818
:alt: License: LGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
20-
:target: https://github.com/OCA/operating-unit/tree/17.0/pos_operating_unit
20+
:target: https://github.com/OCA/operating-unit/tree/18.0/pos_operating_unit
2121
:alt: OCA/operating-unit
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-pos_operating_unit
23+
:target: https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-pos_operating_unit
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -58,7 +58,7 @@ Bug Tracker
5858
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
5959
In case of trouble, please check there if your issue has already been reported.
6060
If you spotted it first, help us to smash it by providing a detailed and welcomed
61-
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20pos_operating_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
61+
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20pos_operating_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
6262

6363
Do not contact contributors directly about support or help with technical issues.
6464

@@ -74,9 +74,13 @@ Authors
7474
Contributors
7575
------------
7676

77-
- Ooops404 <https://ooops404.com>
77+
- Ooops404 https://ooops404.com
7878

79-
- Ilyas <irazor147@gmail.com>
79+
- Ilyas irazor147@gmail.com
80+
81+
- Nybble Group https://www.nybblegroup.com
82+
83+
- Cristiam Carreño cristiamcarreno@gmail.com
8084

8185
Maintainers
8286
-----------
@@ -91,6 +95,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
9195
mission is to support the collaborative development of Odoo features and
9296
promote its widespread use.
9397

94-
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/17.0/pos_operating_unit>`_ project on GitHub.
98+
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/18.0/pos_operating_unit>`_ project on GitHub.
9599

96100
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

pos_operating_unit/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "POS with Operating Units",
3-
"version": "17.0.1.0.0",
3+
"version": "18.0.1.0.0",
44
"author": "Ilyas, Ooops404, Odoo Community Association (OCA)",
55
"website": "https://github.com/OCA/operating-unit",
66
"category": "Point of sale",
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
- Ooops404 \<<https://ooops404.com>\>
2-
- Ilyas \<<irazor147@gmail.com>\>
1+
- Ooops404 <https://ooops404.com>
2+
- Ilyas <irazor147@gmail.com>
3+
4+
- Nybble Group <https://www.nybblegroup.com>
5+
- Cristiam Carreño <cristiamcarreno@gmail.com>

pos_operating_unit/static/description/index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">POS with Operating Units</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:ff2417b3a2178379e4a963b4b7fed6282bfb952b07931806cec94e7806d49d61
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/17.0/pos_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-pos_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/18.0/pos_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-pos_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module adds a field “operating unit” in POS with the only goal of
374374
restricting visibility (therefore access) to users with same OU allowed.</p>
375375
<p>This also applies to sessions, orders and payments in POS.</p>
@@ -403,7 +403,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
403403
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
404404
In case of trouble, please check there if your issue has already been reported.
405405
If you spotted it first, help us to smash it by providing a detailed and welcomed
406-
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20pos_operating_unit%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
406+
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20pos_operating_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
407407
<p>Do not contact contributors directly about support or help with technical issues.</p>
408408
</div>
409409
<div class="section" id="credits">
@@ -418,8 +418,12 @@ <h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
418418
<div class="section" id="contributors">
419419
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
420420
<ul class="simple">
421-
<li>Ooops404 &lt;<a class="reference external" href="https://ooops404.com">https://ooops404.com</a>&gt;<ul>
422-
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
421+
<li>Ooops404 <a class="reference external" href="https://ooops404.com">https://ooops404.com</a><ul>
422+
<li>Ilyas <a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a></li>
423+
</ul>
424+
</li>
425+
<li>Nybble Group <a class="reference external" href="https://www.nybblegroup.com">https://www.nybblegroup.com</a><ul>
426+
<li>Cristiam Carreño <a class="reference external" href="mailto:cristiamcarreno&#64;gmail.com">cristiamcarreno&#64;gmail.com</a></li>
423427
</ul>
424428
</li>
425429
</ul>
@@ -433,7 +437,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
433437
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
434438
mission is to support the collaborative development of Odoo features and
435439
promote its widespread use.</p>
436-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/17.0/pos_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
440+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/18.0/pos_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
437441
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
438442
</div>
439443
</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from . import test_pos_operating_unit_basic
2+
from . import test_pos_operating_unit_rules
13
from . import test_pos_operating_unit
Lines changed: 117 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
1+
# Copyright 2024 ForgeFlow, S.L.
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
3+
14
from odoo import fields
25
from odoo.exceptions import AccessError
3-
from odoo.models import Command
6+
from odoo.fields import Command
7+
from odoo.tests import tagged
48

59
from odoo.addons.operating_unit.tests.common import OperatingUnitCommon
610

711

12+
@tagged("post_install", "-at_install")
813
class TestPOSOperatingUnit(OperatingUnitCommon):
14+
"""Test Point of Sale Operating Unit access controls and functionality."""
15+
916
@classmethod
1017
def setUpClass(cls):
1118
super().setUpClass()
19+
20+
# Setup models
1221
cls.PosOrder = cls.env["pos.order"]
13-
cls.pos_product = cls.env.ref("point_of_sale.whiteboard_pen")
14-
cls.pricelist = cls.env["product.pricelist"].search([], limit=1)
22+
cls.PosConfig = cls.env["pos.config"]
23+
cls.PosSession = cls.env["pos.session"]
24+
25+
# Setup product for testing
26+
cls.pos_product = cls.env["product.product"].create(
27+
{
28+
"name": "Test POS Product",
29+
"available_in_pos": True,
30+
"list_price": 1000.0,
31+
}
32+
)
1533

16-
# Create a new pos config and open it
17-
cls.pos_config = cls.env.ref("point_of_sale.pos_config_main").copy()
34+
# Setup pricelist
35+
cls.pricelist = cls.env["product.pricelist"].create(
36+
{
37+
"name": "Test POS Pricelist",
38+
"currency_id": cls.env.company.currency_id.id,
39+
}
40+
)
41+
42+
# Setup groups
1843
cls.group_pos_manager = cls.env.ref("point_of_sale.group_pos_manager")
1944
cls.group_account_invoice = cls.env.ref("account.group_account_invoice")
2045

21-
cls.pos_config.operating_unit_ids = [Command.set([cls.ou1.id])]
46+
# Create POS config with operating unit
47+
cls.pos_config = cls.env["pos.config"].create(
48+
{
49+
"name": "Test POS Config",
50+
"operating_unit_ids": [Command.set([cls.ou1.id])],
51+
"available_pricelist_ids": [Command.set([cls.pricelist.id])],
52+
"pricelist_id": cls.pricelist.id,
53+
}
54+
)
55+
56+
# Open session
2257
cls.pos_config.open_ui()
2358

59+
# Configure users with proper groups and operating units
2460
cls.user1.write(
2561
{
2662
"groups_id": [
2763
Command.link(cls.group_pos_manager.id),
2864
Command.link(cls.group_account_invoice.id),
2965
],
30-
"operating_unit_ids": [Command.link(cls.b2b.id)],
66+
"operating_unit_ids": [Command.link(cls.ou1.id)],
3167
}
3268
)
3369
cls.user2.write(
@@ -41,80 +77,101 @@ def setUpClass(cls):
4177
)
4278

4379
def test_operating_unit_access_config(self):
44-
config1_ids = self.env["pos.config"].with_user(self.user1).search([])
80+
"""Test that users can only access POS configs for their operating units."""
81+
# User1 has access to ou1 (same as pos_config)
82+
config1_ids = self.PosConfig.with_user(self.user1).search([])
4583
self.assertIn(self.pos_config, config1_ids)
46-
config2_ids = self.env["pos.config"].with_user(self.user2).search([])
84+
85+
# User2 has access to b2b (different from pos_config)
86+
config2_ids = self.PosConfig.with_user(self.user2).search([])
4787
self.assertNotIn(self.pos_config, config2_ids)
4888

4989
def test_operating_unit_access_session(self):
90+
"""Test that users can only access sessions for their operating units."""
91+
# User1 should be able to read the session
5092
self.pos_config.current_session_id.with_user(self.user1).read()
93+
94+
# User2 should not have access
5195
with self.assertRaises(AccessError):
5296
self.pos_config.current_session_id.with_user(self.user2).read()
5397

5498
def test_operating_unit_access_order_and_line_and_payment(self):
99+
"""Test that users can only access orders for their operating units."""
55100
order = self._create_order()
101+
102+
# User1 should have access to order and related records
56103
order.with_user(self.user1).read()
57104
order.lines.with_user(self.user1).read()
105+
order.payment_ids.with_user(self.user1).read()
106+
107+
# User2 should not have access
58108
with self.assertRaises(AccessError):
59109
order.with_user(self.user2).read()
60110
with self.assertRaises(AccessError):
61111
order.lines.with_user(self.user2).read()
62-
order.payment_ids.with_user(self.user1).read()
63112
with self.assertRaises(AccessError):
64113
order.payment_ids.with_user(self.user2).read()
65114

66115
def _create_order(self):
67-
# Create order
68-
account_id = self.env.user.partner_id.property_account_receivable_id.id
116+
"""Create a test POS order using the modern Odoo 18 approach."""
117+
# Create order using sync_from_ui method
69118
order_data = {
70119
"id": "0006-001-0010",
71120
"to_invoice": False,
72-
"data": {
73-
"date_order": fields.Datetime.to_string(fields.Datetime.now()),
74-
"pricelist_id": self.pricelist.id,
75-
"user_id": 1,
76-
"name": "Order 0006-001-0010",
77-
"partner_id": False,
78-
"amount_paid": 1000,
79-
"pos_session_id": self.pos_config.current_session_id.id,
80-
"lines": [
81-
[
82-
0,
83-
0,
84-
{
85-
"product_id": self.pos_product.id,
86-
"qty": 1,
87-
"price_unit": 1000,
88-
"price_subtotal": 1000,
89-
"price_subtotal_incl": 1000,
90-
},
91-
]
92-
],
93-
"statement_ids": [
94-
[
95-
0,
96-
0,
97-
{
98-
"payment_method_id": self.pos_config.payment_method_ids[
99-
0
100-
].id,
101-
"amount": 1000,
102-
"name": fields.Datetime.now(),
103-
"account_id": account_id,
104-
"session_id": self.pos_config.current_session_id.id,
105-
},
106-
]
107-
],
108-
"creation_date": "2022-11-27 15:51:03",
109-
"amount_tax": 0,
110-
"fiscal_position_id": False,
111-
"uid": "00001-001-0001",
112-
"amount_return": 0,
113-
"sequence_number": 1,
114-
"amount_total": 1000.0,
115-
"session_id": self.pos_config.current_session_id.id,
116-
},
121+
"session_id": self.pos_config.current_session_id.id,
122+
"date_order": fields.Datetime.to_string(fields.Datetime.now()),
123+
"pricelist_id": self.pricelist.id,
124+
"user_id": self.env.user.id,
125+
"name": "Order 0006-001-0010",
126+
"partner_id": False,
127+
"amount_paid": 1000.0,
128+
"amount_total": 1000.0,
129+
"amount_tax": 0.0,
130+
"amount_return": 0.0,
131+
"fiscal_position_id": False,
132+
"sequence_number": 1,
133+
"uuid": "00001-001-0001",
134+
"lines": [
135+
[
136+
0,
137+
0,
138+
{
139+
"product_id": self.pos_product.id,
140+
"qty": 1.0,
141+
"price_unit": 1000.0,
142+
"price_subtotal": 1000.0,
143+
"price_subtotal_incl": 1000.0,
144+
"discount": 0.0,
145+
},
146+
]
147+
],
148+
"payment_ids": [
149+
[
150+
0,
151+
0,
152+
{
153+
"payment_method_id": self.pos_config.payment_method_ids[0].id,
154+
"amount": 1000.0,
155+
},
156+
]
157+
],
117158
}
118-
result = self.PosOrder.create_from_ui([order_data])
119-
order = self.PosOrder.browse(result[0].get("id"))
120-
return order
159+
160+
# Create the order
161+
result = self.PosOrder.sync_from_ui([order_data])
162+
if not result or "pos.order" not in result:
163+
raise ValueError("Failed to create POS order")
164+
165+
# Get order data from result
166+
pos_orders = result["pos.order"]
167+
if not pos_orders:
168+
raise ValueError("No order data in result")
169+
170+
# Extract order ID from the first order data
171+
order_data_dict = pos_orders[0] if pos_orders else {}
172+
order_id = order_data_dict.get("id")
173+
174+
if not order_id:
175+
raise ValueError("Failed to get order ID from result")
176+
177+
return self.PosOrder.browse(order_id)

0 commit comments

Comments
 (0)