From 3844823465bcba3c93eb2af6c8da45be0ca5002b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 16 Jul 2014 17:43:46 +0200 Subject: [PATCH] Add Report issue4038 review9471002 --- CHANGELOG | 1 + README | 13 ++++++++++++- proteus/__init__.py | 16 +++++++++++++++- proteus/tests/test_report.py | 23 +++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 proteus/tests/test_report.py diff --git a/CHANGELOG b/CHANGELOG index fbbc16bda9..24a2c1971b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add Report * Explicitly set value of parent field * Add duplicate method diff --git a/README b/README index 0b23a110cc..400212bc1f 100644 --- a/README +++ b/README @@ -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 ------- diff --git a/proteus/__init__.py b/proteus/__init__.py index a9f50e24f0..45d2dacc13 100644 --- a/proteus/__init__.py +++ b/proteus/__init__.py @@ -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) diff --git a/proteus/tests/test_report.py b/proteus/tests/test_report.py new file mode 100644 index 0000000000..264b2bc0a5 --- /dev/null +++ b/proteus/tests/test_report.py @@ -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')