[ADD] account_restrict_journal
This commit is contained in:
24
account_restrict_journal/models/__init__.py
Normal file
24
account_restrict_journal/models/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
from . import account_move
|
||||
from . import account_payment_register
|
||||
from . import res_users
|
||||
54
account_restrict_journal/models/account_move.py
Normal file
54
account_restrict_journal/models/account_move.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
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()
|
||||
62
account_restrict_journal/models/account_payment_register.py
Normal file
62
account_restrict_journal/models/account_payment_register.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
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')
|
||||
43
account_restrict_journal/models/res_users.py
Normal file
43
account_restrict_journal/models/res_users.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#############################################################################
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
#
|
||||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
||||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#############################################################################
|
||||
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
|
||||
Reference in New Issue
Block a user