diff --git a/user_warehouse_restriction/__manifest__.py b/user_warehouse_restriction/__manifest__.py index af17ecc0d..a0a72cb99 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.1', + 'version': '17.0.2.0.2', '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 cc33ce4c2..142a964c2 100644 --- a/user_warehouse_restriction/doc/RELEASE_NOTES.md +++ b/user_warehouse_restriction/doc/RELEASE_NOTES.md @@ -15,3 +15,8 @@ #### Version 17.0.2.0.1 #### UPDT - Incorporated condition when modifying Warehouse Restriction. + +#### 6.03.2025 +#### Version 17.0.2.0.2 +#### UPDT +- Incorporated condition when modifying Allowed Users. diff --git a/user_warehouse_restriction/models/res_config_settings.py b/user_warehouse_restriction/models/res_config_settings.py index b9971c017..2f5fd82b4 100755 --- a/user_warehouse_restriction/models/res_config_settings.py +++ b/user_warehouse_restriction/models/res_config_settings.py @@ -39,6 +39,7 @@ class ResConfigSettings(models.TransientModel): @api.onchange('group_user_warehouse_restriction') def _onchange_group_user_warehouse_restriction(self): + print("_onchange_group_user_warehouse_restriction") """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.""" diff --git a/user_warehouse_restriction/models/res_users.py b/user_warehouse_restriction/models/res_users.py index 00f2d17e5..0cd0d452d 100644 --- a/user_warehouse_restriction/models/res_users.py +++ b/user_warehouse_restriction/models/res_users.py @@ -46,9 +46,11 @@ class ResUsers(models.Model): def write(self, vals): self.clear_caches() + print(vals) return super(ResUsers, self).write(vals) def _compute_check_user(self): + print("_compute_check_user") """To determine if the user has warehouse location restrictions. Sets the check_user field accordingly.""" restriction_group_id = self.env.ref( diff --git a/user_warehouse_restriction/models/stock_picking.py b/user_warehouse_restriction/models/stock_picking.py index 9e8dd946f..c9e31ed4f 100644 --- a/user_warehouse_restriction/models/stock_picking.py +++ b/user_warehouse_restriction/models/stock_picking.py @@ -29,6 +29,7 @@ class StockPicking(models.Model): @api.onchange('location_id', 'location_dest_id') def _onchange_location_id(self): + print("_onchange_location_id") """Domain for location_id and location_dest_id.""" if self.env['ir.config_parameter'].sudo().get_param('user_warehouse_restriction.group_user_warehouse_restriction'): return { diff --git a/user_warehouse_restriction/models/stock_warehouse.py b/user_warehouse_restriction/models/stock_warehouse.py index 423843688..29677e3f1 100644 --- a/user_warehouse_restriction/models/stock_warehouse.py +++ b/user_warehouse_restriction/models/stock_warehouse.py @@ -20,6 +20,7 @@ # ############################################################################### from odoo import api, fields, models +from odoo.exceptions import ValidationError class StockWarehouse(models.Model): @@ -40,18 +41,46 @@ class StockWarehouse(models.Model): @api.onchange('restrict_location', 'user_ids') def _onchange_restrict_location(self): - """Triggered when the 'restrict_location' or 'user_ids' fields - are modified. It updates the 'restrict_location' field for selected - users when restricting stock location access.""" - for rec in self.user_ids: - if self.restrict_location: - rec._origin.write({'restrict_location': True, - 'allowed_warehouse_ids': [ - (4, self._origin.id)]}) - elif not self.restrict_location: - rec._origin.write({'restrict_location': True, - 'location_ids': False - }) + if not self.company_id: + return + + current_user = self.env.user + if current_user not in self.user_ids and self.restrict_location: + self.user_ids = [(4, current_user.id)] + + # Filter valid users with access to the warehouse’s company + valid_users = self.user_ids.filtered( + lambda u: self.company_id in u.company_ids + ) + if self.restrict_location: + valid_users.with_context( + allowed_company_ids=self.company_id.ids + ).write({ + 'restrict_location': True, + 'allowed_warehouse_ids': [(4, self._origin.id)], + }) + else: + valid_users.with_context( + allowed_company_ids=valid_users.company_ids.ids + ).write({ + 'restrict_location': True, + 'location_ids': False, + }) + + def write(self, vals): + """Override the write method to prevent the current user from being + removed from the user_ids Many2many field.""" + res = super(StockWarehouse, self).write(vals) + if 'user_ids' in vals: + # Check if the current user is still in user_ids after the update + current_user = self.env.user + for warehouse in self: + if current_user not in warehouse.user_ids: + raise ValidationError( + "You cannot remove yourself from the allowed users " + "of this warehouse." + ) + return res def action_open_users_view(self): """Return user basic form view to give restricted location for users""" diff --git a/website_signup_approval/__manifest__.py b/website_signup_approval/__manifest__.py index b15aab43f..ef24ce1d5 100755 --- a/website_signup_approval/__manifest__.py +++ b/website_signup_approval/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': "Website Signup Approval", - 'version': '17.0.1.0.3', + 'version': '17.0.1.0.4', 'summary': 'Approve signup request to login to the website', 'description': """This module approve or reject signup approval request of users from website.User can upload their documents for approval.""", diff --git a/website_signup_approval/doc/RELEASE_NOTES.md b/website_signup_approval/doc/RELEASE_NOTES.md index 37aeebacc..7ffa37f27 100755 --- a/website_signup_approval/doc/RELEASE_NOTES.md +++ b/website_signup_approval/doc/RELEASE_NOTES.md @@ -16,6 +16,11 @@ - Changed the Configuration from Sale Configuration to Website Configuration. #### 05.08.2024 -#### Version 17.0.1.0.2 +#### Version 17.0.1.0.3 +#### UPDT +- Added validation for the field in settings. + +#### 05.08.2024 +#### Version 17.0.1.0.4 #### UPDT - Added validation for the field in settings. diff --git a/website_signup_approval/views/res_config_settings_views.xml b/website_signup_approval/views/res_config_settings_views.xml index 1aef5de95..55b081364 100755 --- a/website_signup_approval/views/res_config_settings_views.xml +++ b/website_signup_approval/views/res_config_settings_views.xml @@ -14,6 +14,7 @@ id="signup_approval" invisible="auth_signup_uninvited == 'b2b'">