Add Report

issue4038
review9471002
This commit is contained in:
Cédric Krier
2014-07-16 17:43:46 +02:00
parent 870b98e654
commit 3844823465
4 changed files with 51 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add Report
* Explicitly set value of parent field
* Add duplicate method
+12 -1
View File
@@ -11,7 +11,7 @@ See INSTALL
Example of usage
----------------
>>> from proteus import config, Model, Wizard
>>> from proteus import config, Model, Wizard, Report
Creating a database
~~~~~~~~~~~~~~~~~~~
@@ -99,6 +99,17 @@ Append it to categories of the party
>>> party.categories #doctest: +ELLIPSIS
[proteus.Model.get('party.category')(...)]
Print party label
~~~~~~~~~~~~~~~~~
There is a label report on `Party`.
>>> label = Report('party.label')
The report is executed with a list of records and some extra data.
>>> type_, data, print_, name = label.execute([party], {})
Support
-------
+15 -1
View File
@@ -4,7 +4,7 @@
A library to access Tryton's models like a client.
'''
__version__ = "3.3.0"
__all__ = ['Model', 'Wizard']
__all__ = ['Model', 'Wizard', 'Report']
import sys
try:
import cdecimal
@@ -997,3 +997,17 @@ class Wizard(object):
if self.state == self.end_state:
self._proxy.delete(self.session_id, self._config.context)
class Report(object):
'Report class for Tryton reports'
def __init__(self, name, config=None, context=None):
super(Report, self).__init__()
self.name = name
self._config = config or proteus.config.get_config()
self._context = context or {}
self._proxy = self._config.get_proxy(name, type='report')
def execute(self, models, data):
return self._proxy.execute([m.id for m in models], data, self._context)
+23
View File
@@ -0,0 +1,23 @@
#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 unittest import TestCase
from proteus import config, Report, Model
class TestReport(TestCase):
def setUp(self):
config.set_trytond(database_type='sqlite')
def test_model_graph(self):
IrModel = Model.get('ir.model')
models = IrModel.find([])
data = {
'level': 1,
'filter': '',
}
report = Report('ir.model.graph')
type_, data, print_, name = report.execute(models, data)
self.assertEqual(type_, 'png')
self.assertEqual(print_, False)
self.assertEqual(name, 'Graph')