Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_journal: remove restriction to archived users #326

Open
wants to merge 2 commits into
base: 13.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account_journal_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Journal Security',
'version': "13.0.1.0.0",
'version': "13.0.1.1.0",
'category': 'Accounting',
'sequence': 14,
'summary': 'Restrict the use of certain journals to certain users',
Expand Down
14 changes: 8 additions & 6 deletions account_journal_security/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AccountJournal(models.Model):
help='If choose some users, then this journal and the information'
' related to it will be only visible for those users.',
copy=False,
context={'active_test': False},
)

modification_user_ids = fields.Many2many(
Expand All @@ -31,6 +32,7 @@ class AccountJournal(models.Model):
' create, write or delete accounting data related of this journal. '
'Information will still be visible for other users.',
copy=False,
context={'active_test': False},
)

journal_restriction = fields.Selection(
Expand All @@ -39,10 +41,10 @@ class AccountJournal(models.Model):
('total', 'Total')],
string="Tipo de Restriccion",
compute='_compute_journal_restriction',
readonly=False,
inverse='_inverse_unset_modification_user_ids',
)

@api.depends()
@api.depends('user_ids', 'modification_user_ids')
def _compute_journal_restriction(self):
for rec in self:
if rec.user_ids:
Expand Down Expand Up @@ -111,18 +113,18 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, access_ri
return super()._search(args, offset, limit, order, count=count, access_rights_uid=access_rights_uid)

@api.onchange('journal_restriction')
def unset_modification_user_ids(self):
def _inverse_unset_modification_user_ids(self):
"""
Al cambiar una opción por otra, limpiar el campo M2M
que se oculta para evitar conflictos al guardar.
"""
if self.journal_restriction == 'modification':
if self.journal_restriction == 'modification' and self.user_ids:
self.modification_user_ids = self.user_ids
self.user_ids = None
elif self.journal_restriction == 'total':
elif self.journal_restriction == 'total' and self.modification_user_ids:
self.user_ids = self.modification_user_ids
self.modification_user_ids = None
else:
elif self.journal_restriction == 'none':
# Es necesario que se limpien ambos campos cuando se seleccione
# "Ninguna", sino no se guardan los cambios.
self.user_ids = None
Expand Down
8 changes: 6 additions & 2 deletions account_journal_security/views/account_journal_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group string="Restringir a Usuarios">
<field name="journal_restriction" widget="radio" groups="base.group_erp_manager"/>
<field name="user_ids" widget="many2many_tags" groups="base.group_erp_manager" attrs="{'invisible': [('journal_restriction', '!=', 'total')]}"/>
<field name="modification_user_ids" widget="many2many_tags" groups="base.group_erp_manager" attrs="{'invisible': [('journal_restriction', '!=', 'modification')]}"/>
<field name="user_ids" widget="many2many_tags" groups="base.group_erp_manager"
attrs="{'invisible': [('journal_restriction', '!=', 'total')]}"
context="{'search_default_no_share': True, 'search_default_active': True}"/>
<field name="modification_user_ids" widget="many2many_tags" groups="base.group_erp_manager"
attrs="{'invisible': [('journal_restriction', '!=', 'modification')]}"
context="{'search_default_no_share': True, 'search_default_active': True}"/>
<div class="alert alert-warning" attrs="{'invisible': [('journal_restriction', '!=', 'total')]}" colspan="2" role="alert">
<p>
Tenga mucho cuidado al elegir esta opción ya que puede bloquear acciones de odoo. No lo recomendamos para diarios de ventas, compras, liquidez o cualquier diario en el cual se generen registros desde otra acción. Un caso tipico para este tipo de restricción es el diario de sueldos.
Expand Down