Skip to content

Commit

Permalink
[UPD] stock_lock_lot
Browse files Browse the repository at this point in the history
Fix permissions issue when creating product categories
  • Loading branch information
FLAlvaroGomez committed Jan 22, 2025
1 parent ef9f111 commit 35ea60c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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)

0 comments on commit 35ea60c

Please sign in to comment.