diff --git a/account_restrict_journal/README.rst b/account_restrict_journal/README.rst new file mode 100644 index 0000000..2a20188 --- /dev/null +++ b/account_restrict_journal/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +Restrict Journal for Users +==================== +This module helps to restrict journal for the specific users.Users can access allowed journals only + +Configuration +============= +No additional configuration required + +Company +------- +* `Cybrosys Techno Solutions `__ + +License +------- +General Public License, Version 3 (LGPL v3). +(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) + +Credits +------- +Developer: (V16) Sreeshanth V S @cybrosys, Contact: odoo@cybrosys.com + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com +* Website : https://cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if +your issue has already been reported. + +Maintainer +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit `Our Website `__ + +Further information +=================== +HTML Description: ``__ \ No newline at end of file diff --git a/account_restrict_journal/__init__.py b/account_restrict_journal/__init__.py new file mode 100644 index 0000000..7b2c59c --- /dev/null +++ b/account_restrict_journal/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import models diff --git a/account_restrict_journal/__manifest__.py b/account_restrict_journal/__manifest__.py new file mode 100644 index 0000000..0174d91 --- /dev/null +++ b/account_restrict_journal/__manifest__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +{ + 'name': "Restrict Journal for Users", + "version": "16.0.2.1.2", + "category": "Accounting", + "summary": "User can select only allowed journals", + "description": """ Restrict account journal for the specific users to + access allowed journals only""", + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': "https://www.cybrosys.com", + 'depends': ['base','account'], + 'data': [ + 'security/account_journal_security.xml', + 'security/ir_rule.xml', + 'views/res_users_views.xml', + 'views/account_move_views.xml' + ], + 'images': [ + 'static/description/banner.png'], + 'license': 'LGPL-3', + 'installable': True, + 'application': False, + 'auto_install': False +} diff --git a/account_restrict_journal/doc/RELEASE_NOTES.md b/account_restrict_journal/doc/RELEASE_NOTES.md new file mode 100644 index 0000000..b0f2c42 --- /dev/null +++ b/account_restrict_journal/doc/RELEASE_NOTES.md @@ -0,0 +1,16 @@ +## Module + +#### 05.05.2023 +#### Version 16.0.1.0.0 +#### ADD +- Initial commit for Restrict Journal for Users + +#### 11.09.2023 +#### Version 16.0.2.1.1 +#### UPDT +- Bug Fix and Change Functionality + +#### 12.07.2024 +#### Version 16.0.2.1.2 +#### UPDT +- Bug Fix for Invoice restriction diff --git a/account_restrict_journal/models/__init__.py b/account_restrict_journal/models/__init__.py new file mode 100644 index 0000000..97a0885 --- /dev/null +++ b/account_restrict_journal/models/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import account_move +from . import account_payment_register +from . import res_users diff --git a/account_restrict_journal/models/account_move.py b/account_restrict_journal/models/account_move.py new file mode 100644 index 0000000..c321c3d --- /dev/null +++ b/account_restrict_journal/models/account_move.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class AccountMove(models.Model): + """Inherited model for checking the journal type in account.move.""" + _inherit = 'account.move' + + check_journal = fields.Boolean(string="Check Journal", + help="Compute field for check the current " + "record's journal type ", + compute="_compute_journal") + + def _compute_journal(self): + """Compute field for showing validation error for restricted journal's + records""" + self.check_journal = True + if self.env.user.has_group('account_restrict_journal.user_allowed_journal'): + for rec in self.line_ids: + 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: + raise ValidationError(_('Restricted journals found.')) + if self.journal_id.id in self.env.user.journal_ids.ids: + raise ValidationError(_('Restricted journals found.')) + + @api.onchange('partner_id') + def _onchange_partner_id(self): + """Function for hiding restricted journals from account.move.""" + if self.journal_id.id in self.env.user.journal_ids.ids: + self.journal_id = False + return super(AccountMove, self)._onchange_partner_id() diff --git a/account_restrict_journal/models/account_payment_register.py b/account_restrict_journal/models/account_payment_register.py new file mode 100644 index 0000000..9aad72e --- /dev/null +++ b/account_restrict_journal/models/account_payment_register.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import api, models + + +class AccountPaymentRegister(models.TransientModel): + """ Adding allowed journal in functionality""" + + _inherit = 'account.payment.register' + + @api.depends('payment_type', 'company_id', 'can_edit_wizard') + def _compute_available_journal_ids(self): + """ + Check all available journals on register payment. + """ + for wizard in self: + if wizard.can_edit_wizard: + batch = wizard._get_batches()[0] + wizard.available_journal_ids = wizard._get_batch_available_journals( + batch) + else: + wizard.available_journal_ids = self.env[ + 'account.journal'].search( + [('company_id', '=', wizard.company_id.id), + ('type', 'in', ('bank', 'cash')), + ('id', 'not in', self.env.user.journal_ids.ids)]) + + @api.model + def _get_batch_available_journals(self, batch_result): + """ Helper to compute the available journals based on the batch. + + :param batch_result: A batch returned by '_get_batches'. + :return: A recordset of account.journal. + """ + payment_type = batch_result['payment_values']['payment_type'] + company = batch_result['lines'].company_id + journals = self.env['account.journal'].search( + [('company_id', '=', company.id), ('type', 'in', ('bank', 'cash')), + ('id', 'not in', self.env.user.journal_ids.ids)]) + if payment_type == 'inbound': + return journals.filtered('inbound_payment_method_line_ids') + else: + return journals.filtered('outbound_payment_method_line_ids') diff --git a/account_restrict_journal/models/res_users.py b/account_restrict_journal/models/res_users.py new file mode 100644 index 0000000..a53a62b --- /dev/null +++ b/account_restrict_journal/models/res_users.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import fields, models + + +class ResUsers(models.Model): + """ Adding journal fields where we can select allowed journal """ + + _inherit = 'res.users' + + check_user = fields.Boolean(string="Check", compute='_compute_check_user', + help="Check the field is true or false") + journal_ids = fields.Many2many( + 'account.journal', 'account_restrict_journal_journal_ids_rel', + string='Restricted Journals', + help='Only the selected journal will be visible' + ' to the particular user') + + def _compute_check_user(self): + """Function for viewing the page for restrict journal users.""" + self.check_user = False + if (self.env.ref('account_restrict_journal.user_allowed_journal').id in + self.groups_id.mapped('id')): + self.check_user = True diff --git a/account_restrict_journal/security/account_journal_security.xml b/account_restrict_journal/security/account_journal_security.xml new file mode 100644 index 0000000..34097f2 --- /dev/null +++ b/account_restrict_journal/security/account_journal_security.xml @@ -0,0 +1,8 @@ + + + + + Restrict Journals + + + diff --git a/account_restrict_journal/security/ir_rule.xml b/account_restrict_journal/security/ir_rule.xml new file mode 100644 index 0000000..23f97f1 --- /dev/null +++ b/account_restrict_journal/security/ir_rule.xml @@ -0,0 +1,32 @@ + + + + + Account Journal Restrict on Users + + [('id','not in', user.journal_ids.ids)] + + + + + + + + + + Account Payment Restrict on Users + + [('journal_id','not in', user.journal_ids.ids)] + + + + + + + + + diff --git a/account_restrict_journal/static/description/banner.png b/account_restrict_journal/static/description/banner.png new file mode 100644 index 0000000..666b61f Binary files /dev/null and b/account_restrict_journal/static/description/banner.png differ diff --git a/account_restrict_journal/static/description/icon.png b/account_restrict_journal/static/description/icon.png new file mode 100644 index 0000000..440c7d2 Binary files /dev/null and b/account_restrict_journal/static/description/icon.png differ diff --git a/account_restrict_journal/views/account_move_views.xml b/account_restrict_journal/views/account_move_views.xml new file mode 100644 index 0000000..4c3f7bf --- /dev/null +++ b/account_restrict_journal/views/account_move_views.xml @@ -0,0 +1,16 @@ + + + + + account.move.form.inherit.account.restrict.journal + + account.move + extension + + + + + + + + diff --git a/account_restrict_journal/views/res_users_views.xml b/account_restrict_journal/views/res_users_views.xml new file mode 100644 index 0000000..aa92468 --- /dev/null +++ b/account_restrict_journal/views/res_users_views.xml @@ -0,0 +1,21 @@ + + + + + res.users.form.inherit.account.restrict.journal + + res.users + extension + + + + + + + + + + + + +