From 8f8cb9ba040e5d52cfa12efe56493a63a44fd46a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Mon, 21 Mar 2022 16:11:04 +0100 Subject: [PATCH] Allow to deactivate button access issue11284 review364911002 --- CHANGELOG | 1 + trytond/ir/message.xml | 3 +++ trytond/ir/model.py | 24 ++++++++++++++++++------ trytond/ir/view/model_button_form.xml | 3 ++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b8a849e106..e081f3b3ab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow to deactivate button access * Always return tuple for MultiSelection * Use default selectors instead of select * Add batch option to push queue tasks diff --git a/trytond/ir/message.xml b/trytond/ir/message.xml index da81bcc5a9..44bfba1a31 100644 --- a/trytond/ir/message.xml +++ b/trytond/ir/message.xml @@ -384,5 +384,8 @@ this repository contains the full copyright notices and license terms. --> The code on language must be unique. + + The button name in model must be unique. + diff --git a/trytond/ir/model.py b/trytond/ir/model.py index a7802da03d..abc6c6f4b6 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -10,12 +10,13 @@ from itertools import groupby from sql import Literal, Null from sql.aggregate import Max from sql.conditionals import Case +from sql.operators import Equal from trytond.cache import Cache from trytond.i18n import gettext from trytond.model import ( - DeactivableMixin, EvalEnvironment, ModelSQL, ModelView, Unique, Workflow, - fields) + DeactivableMixin, EvalEnvironment, Exclude, ModelSQL, ModelView, Unique, + Workflow, fields) from trytond.model.exceptions import AccessError, ValidationError from trytond.pool import Pool from trytond.protocols.jsonrpc import JSONDecoder, JSONEncoder @@ -834,7 +835,7 @@ class ModelFieldAccess(DeactivableMixin, ModelSQL, ModelView): ModelView._fields_view_get_cache.clear() -class ModelButton(ModelSQL, ModelView): +class ModelButton(DeactivableMixin, ModelSQL, ModelView): "Model Button" __name__ = 'ir.model.button' name = fields.Char('Name', required=True, readonly=True) @@ -869,13 +870,24 @@ class ModelButton(ModelSQL, ModelView): _view_attributes_cache = Cache( 'ir.model.button.view_attributes', context=False) + @classmethod + def __register__(cls, module_name): + super().__register__(module_name) + + table_h = cls.__table_handler__(module_name) + + # Migration from 6.2: replace unique by exclude + table_h.drop_constraint('name_model_uniq') + @classmethod def __setup__(cls): super(ModelButton, cls).__setup__() - table = cls.__table__() + t = cls.__table__() cls._sql_constraints += [ - ('name_model_uniq', Unique(table, table.name, table.model), - 'The button name in model must be unique!'), + ('name_model_exclude', + Exclude(t, (t.name, Equal), (t.model, Equal), + where=(t.active == Literal(True))), + 'ir.msg_button_name_unique'), ] cls._order.insert(0, ('model', 'ASC')) diff --git a/trytond/ir/view/model_button_form.xml b/trytond/ir/view/model_button_form.xml index a2d9b4582c..f4a3506775 100644 --- a/trytond/ir/view/model_button_form.xml +++ b/trytond/ir/view/model_button_form.xml @@ -8,7 +8,8 @@ this repository contains the full copyright notices and license terms. -->