diff --git a/account_restrict_journal/__manifest__.py b/account_restrict_journal/__manifest__.py index dca587388..be3896b8c 100644 --- a/account_restrict_journal/__manifest__.py +++ b/account_restrict_journal/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': "Restrict Journal for Users", - "version": "16.0.2.1.1", + "version": "16.0.2.1.2", "category": "Accounting", "summary": "User can select only allowed journals", "description": """ Restrict account journal for the specific users to @@ -30,7 +30,7 @@ 'company': 'Cybrosys Techno Solutions', 'maintainer': 'Cybrosys Techno Solutions', 'website': "https://www.cybrosys.com", - 'depends': ['base', 'base_accounting_kit'], + 'depends': ['base', 'account'], 'data': [ 'security/account_journal_security.xml', 'security/ir_rule.xml', diff --git a/account_restrict_journal/doc/RELEASE_NOTES.md b/account_restrict_journal/doc/RELEASE_NOTES.md index 0a28ae1ef..3c5c02713 100644 --- a/account_restrict_journal/doc/RELEASE_NOTES.md +++ b/account_restrict_journal/doc/RELEASE_NOTES.md @@ -9,3 +9,8 @@ #### Version 16.0.2.1.1 #### UPDT - Bug Fix and Change Functionality + +#### 09.01.2024 +#### Version 16.0.2.1.2 +#### BUGFIX +- Solved the issue in enterprise and added extra conditions to validation error. diff --git a/account_restrict_journal/models/account_move.py b/account_restrict_journal/models/account_move.py index 715a3c1bc..31fd331e2 100644 --- a/account_restrict_journal/models/account_move.py +++ b/account_restrict_journal/models/account_move.py @@ -40,9 +40,13 @@ class AccountMove(models.Model): if rec.full_reconcile_id: payment = self.env['account.payment.register'].search( [('id', '=', rec.full_reconcile_id.id)]) - if payment.journal_id.id in self.env.user.journal_ids.ids: + if payment.journal_id.id in self.env.user.journal_ids.ids and \ + self.env.user.has_group( + "account_restrict_journal.user_allowed_journal"): raise ValidationError(_('Restricted journals found.')) - if self.journal_id.id in self.env.user.journal_ids.ids: + if self.journal_id.id in self.env.user.journal_ids.ids and \ + self.env.user.has_group( + "account_restrict_journal.user_allowed_journal"): raise ValidationError(_('Restricted journals found.')) @api.onchange('partner_id') diff --git a/account_restrict_journal/models/account_payment_register.py b/account_restrict_journal/models/account_payment_register.py index 9aad72e73..9d722e92f 100644 --- a/account_restrict_journal/models/account_payment_register.py +++ b/account_restrict_journal/models/account_payment_register.py @@ -35,8 +35,8 @@ class AccountPaymentRegister(models.TransientModel): for wizard in self: if wizard.can_edit_wizard: batch = wizard._get_batches()[0] - wizard.available_journal_ids = wizard._get_batch_available_journals( - batch) + wizard.available_journal_ids = \ + wizard._get_batch_available_journals(batch) else: wizard.available_journal_ids = self.env[ 'account.journal'].search( diff --git a/account_restrict_journal/models/res_users.py b/account_restrict_journal/models/res_users.py index 67b0897d9..4bffae55e 100644 --- a/account_restrict_journal/models/res_users.py +++ b/account_restrict_journal/models/res_users.py @@ -19,7 +19,8 @@ # If not, see . # ############################################################################# -from odoo import fields, models +from odoo import fields, models, _ +from odoo.exceptions import ValidationError class ResUsers(models.Model): @@ -35,6 +36,28 @@ class ResUsers(models.Model): help='Only the selected journal will be visible' ' to the particular user') + def write(self, vals): + """ + Override the write method to restrict users with specific groups. + :param vals: Dictionary of field values to update. + :type vals: dict + :raises: ValidationError if the current user has both + 'account_restrict_journal.user_allowed_journal' + and 'base.group_system' groups and attempts to restrict + journals of the Administrator. + :return: None + """ + super().write(vals) + if self.env.user.has_group( + 'account_restrict_journal.user_allowed_journal') and \ + self.env.user.has_group('base.group_system'): + user_groups = self.env.user.groups_id.filtered( + lambda g: g.name == 'Restrict Journals') + if user_groups: + raise ValidationError( + _("You are not allowed to restrict journals for the " + "Administrator.")) + def _compute_check_user(self): """Function for viewing the page for restrict journal users.""" self.check_user = False diff --git a/account_restrict_journal/security/ir_rule.xml b/account_restrict_journal/security/ir_rule.xml index 23f97f1ff..ff9c107c3 100644 --- a/account_restrict_journal/security/ir_rule.xml +++ b/account_restrict_journal/security/ir_rule.xml @@ -1,6 +1,6 @@ - + Account Journal Restrict on Users @@ -15,6 +15,7 @@ + Account Payment Restrict on Users