Skip to content

Commit 4500b87

Browse files
committed
[FIX] account_journal_security: archived users restrictions, visible but not selectable
1 parent 25b5be0 commit 4500b87

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

account_journal_security/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
'name': 'Journal Security',
22-
'version': "13.0.1.0.0",
22+
'version': "13.0.1.1.0",
2323
'category': 'Accounting',
2424
'sequence': 14,
2525
'summary': 'Restrict the use of certain journals to certain users',

account_journal_security/models/account_journal.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AccountJournal(models.Model):
1919
help='If choose some users, then this journal and the information'
2020
' related to it will be only visible for those users.',
2121
copy=False,
22+
context={'active_test': False},
2223
)
2324

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

3638
journal_restriction = fields.Selection(
@@ -39,10 +41,10 @@ class AccountJournal(models.Model):
3941
('total', 'Total')],
4042
string="Tipo de Restriccion",
4143
compute='_compute_journal_restriction',
42-
readonly=False,
44+
inverse='_inverse_unset_modification_user_ids',
4345
)
4446

45-
@api.depends()
47+
@api.depends('user_ids', 'modification_user_ids')
4648
def _compute_journal_restriction(self):
4749
for rec in self:
4850
if rec.user_ids:
@@ -111,18 +113,18 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, access_ri
111113
return super()._search(args, offset, limit, order, count=count, access_rights_uid=access_rights_uid)
112114

113115
@api.onchange('journal_restriction')
114-
def unset_modification_user_ids(self):
116+
def _inverse_unset_modification_user_ids(self):
115117
"""
116118
Al cambiar una opción por otra, limpiar el campo M2M
117119
que se oculta para evitar conflictos al guardar.
118120
"""
119-
if self.journal_restriction == 'modification':
121+
if self.journal_restriction == 'modification' and self.user_ids:
120122
self.modification_user_ids = self.user_ids
121123
self.user_ids = None
122-
elif self.journal_restriction == 'total':
124+
elif self.journal_restriction == 'total' and self.modification_user_ids:
123125
self.user_ids = self.modification_user_ids
124126
self.modification_user_ids = None
125-
else:
127+
elif self.journal_restriction == 'none':
126128
# Es necesario que se limpien ambos campos cuando se seleccione
127129
# "Ninguna", sino no se guardan los cambios.
128130
self.user_ids = None

account_journal_security/models/res_users.py

-12
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,3 @@ class Users(models.Model):
2626
'Modification Journals',
2727
context={'active_test': False},
2828
)
29-
30-
# Cuando un usuario es archivado limpiamos los campos modification_journal_ids
31-
# y journal_ids para evitar problemas, ya que en el metodo unset_modification_user_ids(self)
32-
# no se limpiaban los usuarios archivados.
33-
# TODO ver mejora para v15 (posible compute/inverse)
34-
def write(self, vals):
35-
if 'active' in vals and not vals.get('active'):
36-
vals.update({
37-
'modification_journal_ids': [(5, 0, 0)],
38-
'journal_ids': [(5, 0, 0)],
39-
})
40-
return super().write(vals)

account_journal_security/views/account_journal_views.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
99
<group string="Restringir a Usuarios">
1010
<field name="journal_restriction" widget="radio" groups="base.group_erp_manager"/>
11-
<field name="user_ids" widget="many2many_tags" groups="base.group_erp_manager" attrs="{'invisible': [('journal_restriction', '!=', 'total')]}"/>
12-
<field name="modification_user_ids" widget="many2many_tags" groups="base.group_erp_manager" attrs="{'invisible': [('journal_restriction', '!=', 'modification')]}"/>
11+
<field name="user_ids" widget="many2many_tags" groups="base.group_erp_manager"
12+
attrs="{'invisible': [('journal_restriction', '!=', 'total')]}"
13+
context="{'search_default_no_share': True, 'search_default_active': True}"/>
14+
<field name="modification_user_ids" widget="many2many_tags" groups="base.group_erp_manager"
15+
attrs="{'invisible': [('journal_restriction', '!=', 'modification')]}"
16+
context="{'search_default_no_share': True, 'search_default_active': True}"/>
1317
<div class="alert alert-warning" attrs="{'invisible': [('journal_restriction', '!=', 'total')]}" colspan="2" role="alert">
1418
<p>
1519
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.

0 commit comments

Comments
 (0)