changeset 4b2f3943f786 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=4b2f3943f786
description:
Add symbol widget
issue9059
review276871002
diffstat:
CHANGELOG | 1 +
COPYRIGHT | 2 ++
doc/ref/models/models.rst | 17 +++++++++++++++++
doc/topics/views/index.rst | 8 ++++++++
trytond/ir/ui/form.rnc | 1 +
trytond/ir/ui/form.rng | 8 ++++++++
trytond/ir/ui/tree.rnc | 1 +
trytond/ir/ui/tree.rng | 8 ++++++++
trytond/model/__init__.py | 3 ++-
trytond/model/modelview.py | 2 +-
trytond/model/symbol.py | 21 +++++++++++++++++++++
trytond/tests/test_tryton.py | 2 +-
12 files changed, 71 insertions(+), 3 deletions(-)
diffs (204 lines):
diff -r f79c2d67df48 -r 4b2f3943f786 CHANGELOG
--- a/CHANGELOG Fri Oct 09 13:06:42 2020 +0200
+++ b/CHANGELOG Fri Oct 09 19:09:06 2020 +0200
@@ -1,3 +1,4 @@
+* Add symbol widget
* Add sql_pairing tool
* Add format_datetime to Report
* Allow sharing view searches
diff -r f79c2d67df48 -r 4b2f3943f786 COPYRIGHT
--- a/COPYRIGHT Fri Oct 09 13:06:42 2020 +0200
+++ b/COPYRIGHT Fri Oct 09 19:09:06 2020 +0200
@@ -4,6 +4,8 @@
Copyright (C) 2008-2020 B2CK SPRL.
Copyright (C) 2011 Openlabs Technologies & Consulting (P) Ltd.
Copyright (C) 2011-2020 Nicolas Évrard.
+Copyright (C) 2020 Maxime Richez
+Copyright (C) 2020 SALUC SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff -r f79c2d67df48 -r 4b2f3943f786 doc/ref/models/models.rst
--- a/doc/ref/models/models.rst Fri Oct 09 13:06:42 2020 +0200
+++ b/doc/ref/models/models.rst Fri Oct 09 19:09:06 2020 +0200
@@ -762,6 +762,23 @@
Return the SQL table and columns to use for the UNION for the model name.
+===========
+SymbolMixin
+===========
+
+.. class:: SymbolMixin
+
+A mixin_ to manage the display of symbols on the client side.
+
+Instance methods:
+
+.. method:: SymbolMixin.get_symbol(sign, [symbol])
+
+ Return a symbol and its position.
+ The position indicates whether the symbol should appear before (0) or after
+ (1) the value. If no symbol parameter is supplied then the mixin uses the
+ value of attribute named `symbol`.
+
================
sequence_ordered
================
diff -r f79c2d67df48 -r 4b2f3943f786 doc/topics/views/index.rst
--- a/doc/topics/views/index.rst Fri Oct 09 13:06:42 2020 +0200
+++ b/doc/topics/views/index.rst Fri Oct 09 19:09:06 2020 +0200
@@ -162,6 +162,10 @@
:class:`trytond.model.fields.Numeric` to display on the widget. The
default value is 1.
+ .. _common-attributes-symbol:
+
+ * ``symbol``: Only on numerical fields, the name of field which provides
+ the symbol to display.
form
^^^^
@@ -283,6 +287,8 @@
that will be evaluated to the language code for which spell checking must
be done.
+ * ``symbol``: see in common-attributes-symbol_.
+
image
^^^^^
@@ -601,6 +607,8 @@
* ``factor``: see in common-attributes-factor_.
+ * ``symbol``: see in common-attributes-symbol_.
+
prefix or suffix
^^^^^^^^^^^^^^^^
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/ir/ui/form.rnc
--- a/trytond/ir/ui/form.rnc Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/ir/ui/form.rnc Fri Oct 09 19:09:06 2020 +0200
@@ -107,6 +107,7 @@
attlist.field &= attribute filename { text }?
attlist.field &=
[a:defaultValue = "0"] attribute toolbar { "0" | "1" }?
+attlist.field &= attribute symbol { text }?
image = element image { attlist.image, empty }
attlist.image &= attribute name { text }
attlist.image &= [ a:defaultValue = "1" ] attribute colspan { text }?
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/ir/ui/form.rng
--- a/trytond/ir/ui/form.rng Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/ir/ui/form.rng Fri Oct 09 19:09:06 2020 +0200
@@ -476,6 +476,14 @@
</attribute>
</optional>
</define>
+ <define name="attlist.field" combine="interleave">
+ <optional>
+ <attribute>
+ <name ns="">symbol</name>
+ <text/>
+ </attribute>
+ </optional>
+ </define>
<define name="image">
<element>
<name ns="">image</name>
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/ir/ui/tree.rnc
--- a/trytond/ir/ui/tree.rnc Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/ir/ui/tree.rnc Fri Oct 09 19:09:06 2020 +0200
@@ -64,6 +64,7 @@
attlist.field &= [a:defaultValue = "1"] attribute factor { text }?
attlist.field &= attribute filename { text }?
attlist.field &= attribute view_ids { text }?
+attlist.field &= attribute symbol { text }?
prefix = element prefix { attlist.affix, empty }
suffix = element suffix { attlist.affix, empty }
attlist.affix &= attribute string { text }?
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/ir/ui/tree.rng
--- a/trytond/ir/ui/tree.rng Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/ir/ui/tree.rng Fri Oct 09 19:09:06 2020 +0200
@@ -256,6 +256,14 @@
</attribute>
</optional>
</define>
+ <define name="attlist.field" combine="interleave">
+ <optional>
+ <attribute>
+ <name ns="">symbol</name>
+ <text/>
+ </attribute>
+ </optional>
+ </define>
<define name="prefix">
<element>
<name ns="">prefix</name>
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/model/__init__.py
--- a/trytond/model/__init__.py Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/model/__init__.py Fri Oct 09 19:09:06 2020 +0200
@@ -9,6 +9,7 @@
from .dictschema import DictSchemaMixin
from .match import MatchMixin
from .union import UnionMixin
+from .symbol import SymbolMixin
from .multivalue import MultiValueMixin, ValueMixin
from .descriptors import dualmethod
from .order import sequence_ordered
@@ -18,5 +19,5 @@
__all__ = ['Model', 'ModelView', 'ModelStorage', 'ModelSingleton', 'ModelSQL',
'Check', 'Unique', 'Exclude',
'Workflow', 'DictSchemaMixin', 'MatchMixin', 'UnionMixin', 'dualmethod',
- 'MultiValueMixin', 'ValueMixin',
+ 'MultiValueMixin', 'ValueMixin', 'SymbolMixin',
'EvalEnvironment', 'sequence_ordered', 'DeactivableMixin', 'tree']
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/model/modelview.py
--- a/trytond/model/modelview.py Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/model/modelview.py Fri Oct 09 19:09:06 2020 +0200
@@ -578,7 +578,7 @@
break
return views
- for attr in ('name', 'icon'):
+ for attr in ('name', 'icon', 'symbol'):
if not element.get(attr):
continue
fields_attrs.setdefault(element.get(attr), {})
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/model/symbol.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/trytond/model/symbol.py Fri Oct 09 19:09:06 2020 +0200
@@ -0,0 +1,21 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.rpc import RPC
+
+
+class SymbolMixin(object):
+ __slots__ = ()
+
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ cls.__rpc__.update({
+ 'get_symbol': RPC(instantiate=0, cache=dict(days=1)),
+ })
+
+ def get_symbol(self, sign, symbol=None):
+ 'Return the symbol and its position'
+ position = 1
+ if symbol is None:
+ symbol = getattr(self, 'symbol', None)
+ return symbol, position
diff -r f79c2d67df48 -r 4b2f3943f786 trytond/tests/test_tryton.py
--- a/trytond/tests/test_tryton.py Fri Oct 09 13:06:42 2020 +0200
+++ b/trytond/tests/test_tryton.py Fri Oct 09 19:09:06 2020 +0200
@@ -280,7 +280,7 @@
for element in tree_root.iter():
if element.tag in ('field', 'label', 'separator', 'group'):
- for attr in ('name', 'icon'):
+ for attr in ['name', 'icon', 'symbol']:
field = element.get(attr)
if field:
self.assertIn(field, res['fields'],