diff --git a/__init__.py b/__init__.py
index f91263d..e0167ce 100644
--- a/__init__.py
+++ b/__init__.py
@@ -7,6 +7,7 @@ from trytond.pool import Pool
from .evaluation import Evaluation, EvaluationCashbookRel, \
EvaluationTypeRel, EvaluationCurrencyRel
from .currency import Currency
+from .evaluation_context import EvaluationContext
def register():
Pool.register(
@@ -15,4 +16,5 @@ def register():
EvaluationCashbookRel,
EvaluationTypeRel,
EvaluationCurrencyRel,
+ EvaluationContext,
module='cashbook_report', type_='model')
diff --git a/evaluation.py b/evaluation.py
index 1ad6cd7..00bc39f 100644
--- a/evaluation.py
+++ b/evaluation.py
@@ -94,9 +94,7 @@ class Evaluation(ModelSQL, ModelView):
field='evaluation', readonly=True,
model_name='cashbook_report.eval_type')
- action_view = fields.Many2One(string='Action View',
- model_name='ir.action.act_window', ondelete='SET NULL')
- ui_view_point = fields.Many2One(string='UI View Point',
+ ui_view_chart = fields.Many2One(string='UI View Point',
model_name='ir.ui.view', ondelete='SET NULL')
@classmethod
@@ -152,34 +150,53 @@ class Evaluation(ModelSQL, ModelView):
return 'pie'
@classmethod
- def actionview_create(cls, evaluations):
- """ create action views for current setup of evaluation
-
+ def uiview_delete(cls, evaluations):
+ """ delete action view from evalualtion
"""
pool = Pool()
- ActionActWindow = pool.get('ir.action.act_window')
UiView = pool.get('ir.ui.view')
- #cls.actionview_delete(charts)
+ to_delete_uiview = []
+ for evaluation in evaluations:
+ if evaluation.ui_view_chart:
+ to_delete_uiview.append(evaluation.ui_view_chart)
+
+ if len(to_delete_uiview) > 0:
+ UiView.delete(to_delete_uiview)
+
+ @classmethod
+ def uiview_create(cls, evaluations):
+ """ create ui view for current setup of evaluation
+ """
+ pool = Pool()
+ UiView = pool.get('ir.ui.view')
+ Evaluation2 = pool.get('cashbook_report.evaluation')
+
+ cls.uiview_delete(evaluations)
to_write_eval = []
for evaluation in evaluations:
if evaluation.dtype:
- if getattr(evaluation, evaluation.dtype) == 0:
+ # skip if no data to show
+ if len(getattr(evaluation, evaluation.dtype, [])) == 0:
continue
view_graph, = UiView.create([{
'model': 'cashbook_report.%s' % {
'cashbooks': 'eval_book',
'types': 'eval_type',
- 'currenciews': 'eval_currency',
+ 'currencies': 'eval_currency',
}[evaluation.dtype],
'module': 'cashbook_report',
'priority': 10,
'type': 'graph',
'data': template_view_graph % {
- 'bgcol': '#ffffc0',
- 'legend': '1',
+ 'bgcol': '' if evaluation.bgcolor == 'default' \
+ else 'background="%s"' % evaluation.bgcolor,
+ 'legend': '1' if evaluation.legend == True else '0',
+ 'type': evaluation.chart,
+ 'colscheme': '' if evaluation.maincolor == 'default' \
+ else 'color="%s"' % evaluation.maincolor,
'lines': template_view_line % {
'fill': '1',
'string': evaluation.dtype,
@@ -187,36 +204,22 @@ class Evaluation(ModelSQL, ModelView):
},
}])
- view_chart, = UiView.create([{
- 'model': 'cashbook_reporting.chart',
- 'module': 'cashbook_reporting',
- 'priority': 10,
- 'type': 'form',
- 'data': template_view_chart % {
- 'view_ids': view_point.id,
- 'fname': html.escape(chart.name),
- },
- }])
-
- action_view, = ActionActWindow.create([{
- 'res_model': 'cashbook_reporting.chart',
- 'name': chart.name,
- 'act_window_views': [('create', [{
- 'view': view_chart.id,
- 'sequence': 1,
- }])],
- }])
-
- to_write_chart.extend([
- [chart],
+ to_write_eval.extend([
+ [evaluation],
{
- 'ui_view_point': view_point.id,
- 'ui_view_chart': view_chart.id,
- 'action_view': action_view.id,
+ 'ui_view_chart': view_graph.id,
}])
- if len(to_write_chart) > 0:
- Chart2.write(*to_write_chart)
+ if len(to_write_eval) > 0:
+ Evaluation2.write(*to_write_eval)
+
+ @classmethod
+ def create(cls, vlist):
+ """ add chart
+ """
+ records = super(Evaluation, cls).create(vlist)
+ cls.uiview_create(records)
+ return records
@classmethod
def write(cls, *args):
@@ -224,7 +227,14 @@ class Evaluation(ModelSQL, ModelView):
"""
to_write = []
actions = iter(args)
+ to_update_uiview = []
for evaluations, values in zip(actions, actions):
+
+ # update ui-view if related fields change
+ if len(set({'name', 'dtype', 'bgcolor', 'maincolor',
+ 'legend', 'chart'}).intersection(values.keys())) > 0:
+ to_update_uiview.extend(evaluations)
+
if 'dtype' in values.keys():
for evaluation in evaluations:
if evaluation.dtype == values['dtype']:
@@ -262,6 +272,16 @@ class Evaluation(ModelSQL, ModelView):
args.extend(to_write)
super(Evaluation, cls).write(*args)
+ if len(to_update_uiview) > 0:
+ cls.uiview_create(to_update_uiview)
+
+ @classmethod
+ def delete(cls, evaluations):
+ """ delete views
+ """
+ cls.uiview_delete(evaluations)
+ super(Evaluation, cls).delete(evaluations)
+
# end Evaluation
diff --git a/evaluation_context.py b/evaluation_context.py
new file mode 100644
index 0000000..5aa0b4a
--- /dev/null
+++ b/evaluation_context.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# This file is part of the diagram-module from m-ds for Tryton.
+# The COPYRIGHT file at the top level of this repository contains the
+# full copyright notices and license terms.
+
+from trytond.model import ModelView, fields
+from trytond.transaction import Transaction
+
+
+class EvaluationContext(ModelView):
+ 'Evaluation Context'
+ __name__ = 'cashbook_report.evaluation.context'
+
+ evaluation = fields.Many2One(string='Evaluation', readonly=True,
+ model_name='cashbook_report.evaluation',
+ states={'invisible': True})
+
+ @classmethod
+ def default_evaluation(cls):
+ """ get default from context
+ """
+ context = Transaction().context
+ return context.get('evaluation', None)
+
+# end EvaluationContext
diff --git a/evaluation_context.xml b/evaluation_context.xml
new file mode 100644
index 0000000..ef2bd74
--- /dev/null
+++ b/evaluation_context.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+ cashbook_report.evaluation.context
+ form
+ evaluation_context_form
+
+
+
+
+ Evaluation
+ cashbook_report.eval_book
+ cashbook_report.evaluation.context
+
+
+
+
+
+
+
+
+
+
diff --git a/templates.py b/templates.py
index 75d361d..d3432f9 100644
--- a/templates.py
+++ b/templates.py
@@ -4,7 +4,7 @@
# full copyright notices and license terms.
-template_view_line = ''
+template_view_line = ''
template_view_graph = """
diff --git a/tests/test_report.py b/tests/test_report.py
index d5fceb6..aa7c1d9 100644
--- a/tests/test_report.py
+++ b/tests/test_report.py
@@ -306,6 +306,22 @@ class ReportTestCase(CashbookTestCase):
self.assertEqual(evaluation.bgcolor, '#ffffc0')
self.assertEqual(evaluation.currency.code, 'EUR')
+ # check uiview
+ self.assertEqual(evaluation.ui_view_chart.model, 'cashbook_report.eval_book')
+ self.assertEqual(evaluation.ui_view_chart.module, 'cashbook_report')
+ self.assertEqual(evaluation.ui_view_chart.priority, 10)
+ self.assertEqual(evaluation.ui_view_chart.type, 'graph')
+ self.assertEqual(evaluation.ui_view_chart.data, """
+
+
+
+
+
+
+
+
+""")
+
self.assertEqual(len(evaluation.cashbooks), 3)
self.assertEqual(evaluation.cashbooks[0].rec_name, 'Book 1 | 25.00 usd | Open')
self.assertEqual(evaluation.cashbooks[1].rec_name, 'Book 2 | 12.50 usd | Open')
diff --git a/tryton.cfg b/tryton.cfg
index 04a291e..38efdc7 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -7,4 +7,5 @@ xml:
message.xml
graph.xml
evaluation.xml
+ evaluation_context.xml
menu.xml