changeset 5c7e9852cdc4 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=5c7e9852cdc4
description:
Add CSV exports to print toolbar
issue8130
review54571002
diffstat:
CHANGELOG | 1 +
doc/ref/models/models.rst | 3 ++-
trytond/ir/export.py | 21 +++++++++++++++++++--
trytond/model/modelview.py | 11 +++++++++--
4 files changed, 31 insertions(+), 5 deletions(-)
diffs (99 lines):
diff -r 76eb7d9901f8 -r 5c7e9852cdc4 CHANGELOG
--- a/CHANGELOG Fri Mar 22 12:17:50 2019 +0100
+++ b/CHANGELOG Fri Mar 22 17:21:21 2019 +0100
@@ -1,3 +1,4 @@
+* Add exports in view_toolbar_get
* Add resources method to ModelStorage
* Validate selection format in Dict schema
* Allow to extend Field's string and help
diff -r 76eb7d9901f8 -r 5c7e9852cdc4 doc/ref/models/models.rst
--- a/doc/ref/models/models.rst Fri Mar 22 12:17:50 2019 +0100
+++ b/doc/ref/models/models.rst Fri Mar 22 17:21:21 2019 +0100
@@ -141,10 +141,11 @@
.. classmethod:: ModelView.view_toolbar_get()
- Returns the model specific actions in a dictionary with keys:
+ Returns the model specific actions and exports in a dictionary with keys:
- `print`: a list of available reports
- `action`: a list of available actions
- `relate`: a list of available relations
+ - `exports`: a list of available exports
.. classmethod:: ModelView.view_attributes()
diff -r 76eb7d9901f8 -r 5c7e9852cdc4 trytond/ir/export.py
--- a/trytond/ir/export.py Fri Mar 22 12:17:50 2019 +0100
+++ b/trytond/ir/export.py Fri Mar 22 17:21:21 2019 +0100
@@ -8,7 +8,24 @@
]
-class Export(ModelSQL, ModelView):
+class _ClearCache(ModelSQL):
+ @classmethod
+ def create(cls, vlist):
+ ModelView._view_toolbar_get_cache.clear()
+ return super().create(vlist)
+
+ @classmethod
+ def write(cls, *args):
+ ModelView._view_toolbar_get_cache.clear()
+ super().write(*args)
+
+ @classmethod
+ def delete(cls, records):
+ ModelView._view_toolbar_get_cache.clear()
+ super().delete(records)
+
+
+class Export(_ClearCache, ModelSQL, ModelView):
"Export"
__name__ = "ir.export"
name = fields.Char('Name')
@@ -17,7 +34,7 @@
'Fields')
-class ExportLine(ModelSQL, ModelView):
+class ExportLine(_ClearCache, ModelSQL, ModelView):
"Export line"
__name__ = 'ir.export.line'
name = fields.Char('Name')
diff -r 76eb7d9901f8 -r 5c7e9852cdc4 trytond/model/modelview.py
--- a/trytond/model/modelview.py Fri Mar 22 12:17:50 2019 +0100
+++ b/trytond/model/modelview.py Fri Mar 22 17:21:21 2019 +0100
@@ -354,13 +354,16 @@
@classmethod
def view_toolbar_get(cls):
"""
- Returns the model specific actions.
+ Returns the model specific actions and exports.
A dictionary with keys:
- print: a list of available reports
- action: a list of available actions
- relate: a list of available relations
+ - exports: a list of available exports
"""
- Action = Pool().get('ir.action.keyword')
+ pool = Pool()
+ Action = pool.get('ir.action.keyword')
+ Export = pool.get('ir.export')
key = cls.__name__
result = cls._view_toolbar_get_cache.get(key)
if result:
@@ -368,10 +371,14 @@
prints = Action.get_keyword('form_print', (cls.__name__, -1))
actions = Action.get_keyword('form_action', (cls.__name__, -1))
relates = Action.get_keyword('form_relate', (cls.__name__, -1))
+ exports = Export.search_read(
+ [('resource', '=', cls.__name__)],
+ fields_names=['name', 'export_fields.name'])
result = {
'print': prints,
'action': actions,
'relate': relates,
+ 'exports': exports,
}
cls._view_toolbar_get_cache.set(key, result)
return result