diff --git a/user_warehouse_restriction/__manifest__.py b/user_warehouse_restriction/__manifest__.py index 674635ce2..af17ecc0d 100644 --- a/user_warehouse_restriction/__manifest__.py +++ b/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 diff --git a/user_warehouse_restriction/doc/RELEASE_NOTES.md b/user_warehouse_restriction/doc/RELEASE_NOTES.md index b4b1fdd70..cc33ce4c2 100644 --- a/user_warehouse_restriction/doc/RELEASE_NOTES.md +++ b/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. diff --git a/user_warehouse_restriction/models/res_config_settings.py b/user_warehouse_restriction/models/res_config_settings.py index 7ecc9b805..b9971c017 100755 --- a/user_warehouse_restriction/models/res_config_settings.py +++ b/user_warehouse_restriction/models/res_config_settings.py @@ -19,7 +19,11 @@ # If not, see . # ############################################################################### +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 diff --git a/user_warehouse_restriction/models/stock_warehouse.py b/user_warehouse_restriction/models/stock_warehouse.py index 568fe17fc..423843688 100644 --- a/user_warehouse_restriction/models/stock_warehouse.py +++ b/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',