[ADD] account_restrict_journal
This commit is contained in:
47
account_restrict_journal/README.rst
Normal file
47
account_restrict_journal/README.rst
Normal file
@@ -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 <https://cybrosys.com/>`__
|
||||||
|
|
||||||
|
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 <https://cybrosys.com/>`__
|
||||||
|
|
||||||
|
Further information
|
||||||
|
===================
|
||||||
|
HTML Description: `<static/description/index.html>`__
|
||||||
22
account_restrict_journal/__init__.py
Normal file
22
account_restrict_journal/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# -*- 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 models
|
||||||
46
account_restrict_journal/__manifest__.py
Normal file
46
account_restrict_journal/__manifest__.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# -*- 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/>.
|
||||||
|
#
|
||||||
|
#############################################################################
|
||||||
|
{
|
||||||
|
'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
|
||||||
|
}
|
||||||
16
account_restrict_journal/doc/RELEASE_NOTES.md
Normal file
16
account_restrict_journal/doc/RELEASE_NOTES.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Module <account_restrict_journal>
|
||||||
|
|
||||||
|
#### 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
|
||||||
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
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- New user group created for journal restriction-->
|
||||||
|
<record id="user_allowed_journal" model="res.groups">
|
||||||
|
<field name="name">Restrict Journals</field>
|
||||||
|
<field name="category_id" ref="base.module_category_usability"/>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
32
account_restrict_journal/security/ir_rule.xml
Normal file
32
account_restrict_journal/security/ir_rule.xml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- Created new record rule for created user group-->
|
||||||
|
<record id="account_journal_rule_users" model="ir.rule">
|
||||||
|
<field name="name">Account Journal Restrict on Users</field>
|
||||||
|
<field name="model_id" ref="account.model_account_journal"/>
|
||||||
|
<field name="domain_force">[('id','not in', user.journal_ids.ids)]
|
||||||
|
</field>
|
||||||
|
<field name="groups"
|
||||||
|
eval="[(4, ref('account_restrict_journal.user_allowed_journal'))]"/>
|
||||||
|
<field name="perm_read" eval="True"/>
|
||||||
|
<field name="perm_write" eval="True"/>
|
||||||
|
<field name="perm_create" eval="True"/>
|
||||||
|
<field name="perm_unlink" eval="True"/>
|
||||||
|
<field name="active"
|
||||||
|
eval="True"/>
|
||||||
|
</record>
|
||||||
|
<record id="account_payment_rule_users" model="ir.rule">
|
||||||
|
<field name="name">Account Payment Restrict on Users</field>
|
||||||
|
<field name="model_id" ref="account.model_account_payment"/>
|
||||||
|
<field name="domain_force">[('journal_id','not in', user.journal_ids.ids)]
|
||||||
|
</field>
|
||||||
|
<field name="groups"
|
||||||
|
eval="[(4, ref('account_restrict_journal.user_allowed_journal'))]"/>
|
||||||
|
<field name="perm_read" eval="True"/>
|
||||||
|
<field name="perm_write" eval="True"/>
|
||||||
|
<field name="perm_create" eval="True"/>
|
||||||
|
<field name="perm_unlink" eval="True"/>
|
||||||
|
<field name="active"
|
||||||
|
eval="True"/>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
BIN
account_restrict_journal/static/description/banner.png
Normal file
BIN
account_restrict_journal/static/description/banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
BIN
account_restrict_journal/static/description/icon.png
Normal file
BIN
account_restrict_journal/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
16
account_restrict_journal/views/account_move_views.xml
Normal file
16
account_restrict_journal/views/account_move_views.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- Added fields for check journal type -->
|
||||||
|
<record id="view_move_form" model="ir.ui.view">
|
||||||
|
<field name="name">account.move.form.inherit.account.restrict.journal
|
||||||
|
</field>
|
||||||
|
<field name="model">account.move</field>
|
||||||
|
<field name="mode">extension</field>
|
||||||
|
<field name="inherit_id" ref="account.view_move_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='currency_id']" position="after">
|
||||||
|
<field name="check_journal" invisible="1"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
21
account_restrict_journal/views/res_users_views.xml
Normal file
21
account_restrict_journal/views/res_users_views.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<!-- Added fields for accessible journals -->
|
||||||
|
<record id="view_users_form" model="ir.ui.view">
|
||||||
|
<field name="name">res.users.form.inherit.account.restrict.journal
|
||||||
|
</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="mode">extension</field>
|
||||||
|
<field name="inherit_id" ref="base.view_users_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//page[@name='security']" position="after">
|
||||||
|
<page name="account_journal" string="Restricted Journal" attrs="{'invisible': [('check_user','=', False)]}">
|
||||||
|
<group>
|
||||||
|
<field name="journal_ids" widget="many2many_tags"/>
|
||||||
|
<field name="check_user" invisible="1"/>
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user