changeset f1bba6574201 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=f1bba6574201
description:
Allow to deactivate button access
issue11284
review364911002
diffstat:
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(-)
diffs (88 lines):
diff -r 897423a42a3f -r f1bba6574201 CHANGELOG
--- a/CHANGELOG Sun Mar 20 01:45:22 2022 +0100
+++ b/CHANGELOG Mon Mar 21 16:11:04 2022 +0100
@@ -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 -r 897423a42a3f -r f1bba6574201 trytond/ir/message.xml
--- a/trytond/ir/message.xml Sun Mar 20 01:45:22 2022 +0100
+++ b/trytond/ir/message.xml Mon Mar 21 16:11:04 2022 +0100
@@ -384,5 +384,8 @@
<record model="ir.message" id="msg_language_code_unique">
<field name="text">The code on language must be unique.</field>
</record>
+ <record model="ir.message" id="msg_button_name_unique">
+ <field name="text">The button name in model must be unique.</field>
+ </record>
</data>
</tryton>
diff -r 897423a42a3f -r f1bba6574201 trytond/ir/model.py
--- a/trytond/ir/model.py Sun Mar 20 01:45:22 2022 +0100
+++ b/trytond/ir/model.py Mon Mar 21 16:11:04 2022 +0100
@@ -10,12 +10,13 @@
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 @@
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)
@@ -870,12 +871,23 @@
'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 -r 897423a42a3f -r f1bba6574201 trytond/ir/view/model_button_form.xml
--- a/trytond/ir/view/model_button_form.xml Sun Mar 20 01:45:22 2022 +0100
+++ b/trytond/ir/view/model_button_form.xml Mon Mar 21 16:11:04 2022 +0100
@@ -8,7 +8,8 @@
<field name="name"/>
<label name="string"/>
<field name="string"/>
- <newline/>
+ <label name="active"/>
+ <field name="active"/>
<separator name="help" colspan="4"/>
<field name="help" colspan="4"/>
<separator name="confirm" colspan="4"/>