Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] stock_lock_lot fix: fixed permissions issue when creating product categories #1832

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions stock_lock_lot/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2015 AvanzOsc (http://www.avanzosc.es)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, exceptions, fields, models
from odoo import _, exceptions, fields, models


class ProductCategory(models.Model):
Expand All @@ -14,9 +14,16 @@ class ProductCategory(models.Model):
"by default",
)

@api.constrains("lot_default_locked")
def _check_category_lock_unlock(self):
if not self.user_has_groups("stock_lock_lot.group_lock_lot"):
raise exceptions.AccessError(
_("You are not allowed to block/unblock Serial Numbers/Lots")
)

def write(self, vals):
if (
"lot_default_locked" in vals
and vals["lot_default_locked"] != self.lot_default_locked
):
self._check_category_lock_unlock()
return super().write(vals)
11 changes: 11 additions & 0 deletions stock_lock_lot/tests/test_stock_lock_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ def test_track_subtype_locked(self):
self.assertEqual(
subtype, expected_subtype, "Incorrect subtype for unlocked state"
)

def test_category_lock_permissions(self):
# Remove lock permission
self.env.user.groups_id -= self.env.ref("stock_lock_lot.group_lock_lot")
# Change lot_default_locked should fail
with self.assertRaises(exceptions.AccessError):
self.category.write({"lot_default_locked": False})
self.env.user.groups_id += self.env.ref("stock_lock_lot.group_lock_lot")
# Now the change should work
self.category.write({"lot_default_locked": False})
self.assertFalse(self.category.lot_default_locked)
Loading