Browse Source

Jun 07: [FIX] Bug Fixed 'user_warehouse_restriction'

pull/331/head
RisvanaCybro 11 months ago
parent
commit
6e05d21c5e
  1. 2
      user_warehouse_restriction/__manifest__.py
  2. 5
      user_warehouse_restriction/doc/RELEASE_NOTES.md
  3. 30
      user_warehouse_restriction/models/res_config_settings.py
  4. 2
      user_warehouse_restriction/models/stock_warehouse.py

2
user_warehouse_restriction/__manifest__.py

@ -21,7 +21,7 @@
###############################################################################
{
'name': "User Warehouse Restriction",
'version': '17.0.2.0.0',
'version': '17.0.2.0.1',
'category': 'Warehouse',
'summary': """Restrict Warehouses and location for users.""",
'description': """This module helps you to restrict warehouse and stock

5
user_warehouse_restriction/doc/RELEASE_NOTES.md

@ -10,3 +10,8 @@
#### Version 17.0.2.0.0
#### UPDT
- Added Condition for stock picking
#### 23.04.2024
#### Version 17.0.2.0.1
#### UPDT
- Incorporated condition when modifying Warehouse Restriction.

30
user_warehouse_restriction/models/res_config_settings.py

@ -19,7 +19,11 @@
# If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
import logging
from odoo import api, fields, models
from odoo.exceptions import AccessError
_logger = logging.getLogger(__name__)
class ResConfigSettings(models.TransientModel):
@ -38,11 +42,21 @@ class ResConfigSettings(models.TransientModel):
"""This method is triggered when the 'group_user_warehouse_restriction'
field is changed. if it's true, assigns the current user as the
allowed user of all existing warehouses."""
warehouses = self.env['stock.warehouse'].search([])
for warehouse in warehouses:
if self.group_user_warehouse_restriction:
# Assign the current user to each warehouse
warehouse.user_ids = [(6, 0, [self.env.user.id])]
else:
# Clear the allowed users for each warehouse
warehouse.user_ids = [(5, 0, 0)]
rule = self.env.ref('user_warehouse_restriction.operation_type_rule_users', raise_if_not_found=False)
if rule:
rule.active = False
try:
warehouses = self.env['stock.warehouse'].search([])
for warehouse in warehouses:
if self.group_user_warehouse_restriction:
# Assign the current user to each warehouse
if not warehouse.user_ids:
warehouse.user_ids = [(6, 0, [self.env.user.id])]
else:
# Clear the allowed users for each warehouse
warehouse.user_ids = [(5, 0, 0)]
except AccessError as e:
_logger.warning(f"Access error occurred: {e}")
finally:
if rule:
rule.active = True

2
user_warehouse_restriction/models/stock_warehouse.py

@ -31,7 +31,7 @@ class StockWarehouse(models.Model):
comodel_name='res.users', string='Allowed Users',
domain=lambda self: [
('groups_id', 'in', self.env.ref('stock.group_stock_user').id)],
default=lambda self: self.env.user,
# default=lambda self: self.env.user,
help='Allowed users to this Warehouse.')
restrict_location = fields.Boolean(
string='Restrict Stock Location for this Warehouse',

Loading…
Cancel
Save