Skip to content

Commit

Permalink
[FIX] account_journal_security: archived users restrictions, visible …
Browse files Browse the repository at this point in the history
…but not selectable
  • Loading branch information
augusto-weiss committed Jan 28, 2022
1 parent b92c2c2 commit ae47bf4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
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
12 changes: 0 additions & 12 deletions account_journal_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,3 @@ class Users(models.Model):
'Modification Journals',
context={'active_test': False},
)

# Cuando un usuario es archivado limpiamos los campos modification_journal_ids
# y journal_ids para evitar problemas, ya que en el metodo unset_modification_user_ids(self)
# no se limpiaban los usuarios archivados.
# TODO ver mejora para v15 (posible compute/inverse)
def write(self, vals):
if 'active' in vals and not vals.get('active'):
vals.update({
'modification_journal_ids': [(5, 0, 0)],
'journal_ids': [(5, 0, 0)],
})
return super().write(vals)
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

0 comments on commit ae47bf4

Please sign in to comment.