Skip to content

Commit 3027a3b

Browse files
committed
[FIX] pos_hr: removed the isUserLoggedIn check from isAdmin in pos_store
Steps to reproduce the bug: - Install point of sales app, employees app - Make a shop and enable multiple employees per session option - Add another user as a basic right user for any shop - Open a shop session (the one rights are set up for) - Log out of the current user and log in with the other user account - Open the session - The current logged-in user can close the session despite having basic rights Problem: The close session in the XML was having a condition of pos.employeeIsAdmin, and the employeeIsAdmin flag was checking if the user is having advanced rights on the shop or it is the logged-in Odoo user. So if you are the logged-in user, you will always have the close register option regardless of the access rights you have for a specific shop. opw-4575692 closes odoo#198613 Signed-off-by: Joseph Caburnay (jcb) <[email protected]>
1 parent 304e5cc commit 3027a3b

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

addons/pos_hr/static/src/overrides/models/pos_store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ patch(PosStore.prototype, {
2323
},
2424
get employeeIsAdmin() {
2525
const cashier = this.get_cashier();
26-
return cashier._role === "manager" || cashier.user_id?.id === this.user.id;
26+
return cashier._role === "manager";
2727
},
2828
checkPreviousLoggedCashier() {
2929
if (this.config.module_pos_hr) {

addons/pos_hr/static/tests/tours/pos_hr_tour.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ registry.category("web_tour.tours").add("CashierCannotClose", {
132132
Dialog.confirm("Open Register"),
133133
Chrome.clickMenuButton(),
134134
{
135-
trigger: negate(".close-button"),
135+
trigger: negate(`span.dropdown-item:contains("Close Register")`),
136136
},
137137
PosHr.cashierNameIs("Test Employee 3"),
138+
PosHr.clickCashierName(),
139+
SelectionPopup.has("Mitchell Admin", { run: "click" }),
140+
Chrome.clickMenuButton(),
141+
{
142+
trigger: negate(`span.dropdown-item:contains("Close Register")`),
143+
},
138144
].flat(),
139145
});

addons/pos_hr/tests/test_frontend.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def setUpClass(cls):
1616
cls.main_pos_config.write({"module_pos_hr": True})
1717

1818
# Admin employee
19-
admin = cls.env.ref("hr.employee_admin").sudo().copy({
19+
cls.admin = cls.env.ref("hr.employee_admin").sudo().copy({
2020
"company_id": cls.env.company.id,
2121
"user_id": cls.pos_admin.id,
2222
"name": "Mitchell Admin",
2323
"pin": False,
2424
})
2525

2626
# User employee
27-
emp1 = cls.env['hr.employee'].create({
27+
cls.emp1 = cls.env['hr.employee'].create({
2828
'name': 'Test Employee 1',
2929
"company_id": cls.env.company.id,
3030
})
@@ -35,24 +35,24 @@ def setUpClass(cls):
3535
name="Pos Employee1",
3636
3737
)
38-
emp1.write({"name": "Pos Employee1", "pin": "2580", "user_id": emp1_user.id})
38+
cls.emp1.write({"name": "Pos Employee1", "pin": "2580", "user_id": emp1_user.id})
3939

4040
# Non-user employee
41-
emp2 = cls.env['hr.employee'].create({
41+
cls.emp2 = cls.env['hr.employee'].create({
4242
'name': 'Test Employee 2',
4343
"company_id": cls.env.company.id,
4444
})
45-
emp2.write({"name": "Pos Employee2", "pin": "1234"})
46-
(admin + emp1 + emp2).company_id = cls.env.company
45+
cls.emp2.write({"name": "Pos Employee2", "pin": "1234"})
46+
(cls.admin + cls.emp1 + cls.emp2).company_id = cls.env.company
4747

48-
emp3 = cls.env['hr.employee'].create({
48+
cls.emp3 = cls.env['hr.employee'].create({
4949
'name': 'Test Employee 3',
5050
"user_id": cls.pos_user.id,
5151
"company_id": cls.env.company.id,
5252
})
5353

5454
cls.main_pos_config.write({
55-
'basic_employee_ids': [Command.link(emp1.id), Command.link(emp2.id), Command.link(emp3.id)]
55+
'basic_employee_ids': [Command.link(cls.emp1.id), Command.link(cls.emp2.id), Command.link(cls.emp3.id)]
5656
})
5757

5858

@@ -64,6 +64,7 @@ def test_01_pos_hr_tour(self):
6464
(4, self.env.ref('account.group_account_invoice').id)
6565
]
6666
})
67+
self.main_pos_config.advanced_employee_ids = self.admin.ids
6768
self.main_pos_config.with_user(self.pos_admin).open_ui()
6869
self.start_pos_tour("PosHrTour", login="pos_admin")
6970

@@ -90,6 +91,11 @@ def test_cashier_can_see_product_info(self):
9091

9192
def test_basic_user_cannot_close_session(self):
9293
# open a session, the /pos/ui controller will redirect to it
94+
self.main_pos_config.advanced_employee_ids = []
95+
self.main_pos_config.basic_employee_ids = [
96+
Command.link(self.emp3.id),
97+
Command.link(self.admin.id)
98+
]
9399
self.main_pos_config.with_user(self.pos_admin).open_ui()
94100

95101
self.start_tour(

0 commit comments

Comments
 (0)