uiview erstellen+test, context-view begonnen
This commit is contained in:
parent
5809a7caba
commit
17ddfa12ca
7 changed files with 135 additions and 40 deletions
|
@ -7,6 +7,7 @@ from trytond.pool import Pool
|
||||||
from .evaluation import Evaluation, EvaluationCashbookRel, \
|
from .evaluation import Evaluation, EvaluationCashbookRel, \
|
||||||
EvaluationTypeRel, EvaluationCurrencyRel
|
EvaluationTypeRel, EvaluationCurrencyRel
|
||||||
from .currency import Currency
|
from .currency import Currency
|
||||||
|
from .evaluation_context import EvaluationContext
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
@ -15,4 +16,5 @@ def register():
|
||||||
EvaluationCashbookRel,
|
EvaluationCashbookRel,
|
||||||
EvaluationTypeRel,
|
EvaluationTypeRel,
|
||||||
EvaluationCurrencyRel,
|
EvaluationCurrencyRel,
|
||||||
|
EvaluationContext,
|
||||||
module='cashbook_report', type_='model')
|
module='cashbook_report', type_='model')
|
||||||
|
|
|
@ -94,9 +94,7 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
field='evaluation', readonly=True,
|
field='evaluation', readonly=True,
|
||||||
model_name='cashbook_report.eval_type')
|
model_name='cashbook_report.eval_type')
|
||||||
|
|
||||||
action_view = fields.Many2One(string='Action View',
|
ui_view_chart = fields.Many2One(string='UI View Point',
|
||||||
model_name='ir.action.act_window', ondelete='SET NULL')
|
|
||||||
ui_view_point = fields.Many2One(string='UI View Point',
|
|
||||||
model_name='ir.ui.view', ondelete='SET NULL')
|
model_name='ir.ui.view', ondelete='SET NULL')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -152,34 +150,53 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
return 'pie'
|
return 'pie'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def actionview_create(cls, evaluations):
|
def uiview_delete(cls, evaluations):
|
||||||
""" create action views for current setup of evaluation
|
""" delete action view from evalualtion
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
ActionActWindow = pool.get('ir.action.act_window')
|
|
||||||
UiView = pool.get('ir.ui.view')
|
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 = []
|
to_write_eval = []
|
||||||
for evaluation in evaluations:
|
for evaluation in evaluations:
|
||||||
if evaluation.dtype:
|
if evaluation.dtype:
|
||||||
if getattr(evaluation, evaluation.dtype) == 0:
|
# skip if no data to show
|
||||||
|
if len(getattr(evaluation, evaluation.dtype, [])) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
view_graph, = UiView.create([{
|
view_graph, = UiView.create([{
|
||||||
'model': 'cashbook_report.%s' % {
|
'model': 'cashbook_report.%s' % {
|
||||||
'cashbooks': 'eval_book',
|
'cashbooks': 'eval_book',
|
||||||
'types': 'eval_type',
|
'types': 'eval_type',
|
||||||
'currenciews': 'eval_currency',
|
'currencies': 'eval_currency',
|
||||||
}[evaluation.dtype],
|
}[evaluation.dtype],
|
||||||
'module': 'cashbook_report',
|
'module': 'cashbook_report',
|
||||||
'priority': 10,
|
'priority': 10,
|
||||||
'type': 'graph',
|
'type': 'graph',
|
||||||
'data': template_view_graph % {
|
'data': template_view_graph % {
|
||||||
'bgcol': '#ffffc0',
|
'bgcol': '' if evaluation.bgcolor == 'default' \
|
||||||
'legend': '1',
|
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 % {
|
'lines': template_view_line % {
|
||||||
'fill': '1',
|
'fill': '1',
|
||||||
'string': evaluation.dtype,
|
'string': evaluation.dtype,
|
||||||
|
@ -187,36 +204,22 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
},
|
},
|
||||||
}])
|
}])
|
||||||
|
|
||||||
view_chart, = UiView.create([{
|
to_write_eval.extend([
|
||||||
'model': 'cashbook_reporting.chart',
|
[evaluation],
|
||||||
'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],
|
|
||||||
{
|
{
|
||||||
'ui_view_point': view_point.id,
|
'ui_view_chart': view_graph.id,
|
||||||
'ui_view_chart': view_chart.id,
|
|
||||||
'action_view': action_view.id,
|
|
||||||
}])
|
}])
|
||||||
|
|
||||||
if len(to_write_chart) > 0:
|
if len(to_write_eval) > 0:
|
||||||
Chart2.write(*to_write_chart)
|
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
|
@classmethod
|
||||||
def write(cls, *args):
|
def write(cls, *args):
|
||||||
|
@ -224,7 +227,14 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
to_write = []
|
to_write = []
|
||||||
actions = iter(args)
|
actions = iter(args)
|
||||||
|
to_update_uiview = []
|
||||||
for evaluations, values in zip(actions, actions):
|
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():
|
if 'dtype' in values.keys():
|
||||||
for evaluation in evaluations:
|
for evaluation in evaluations:
|
||||||
if evaluation.dtype == values['dtype']:
|
if evaluation.dtype == values['dtype']:
|
||||||
|
@ -262,6 +272,16 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
args.extend(to_write)
|
args.extend(to_write)
|
||||||
super(Evaluation, cls).write(*args)
|
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
|
# end Evaluation
|
||||||
|
|
||||||
|
|
||||||
|
|
25
evaluation_context.py
Normal file
25
evaluation_context.py
Normal file
|
@ -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
|
31
evaluation_context.xml
Normal file
31
evaluation_context.xml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- This file is part of the cashbook-module from m-ds for Tryton.
|
||||||
|
The COPYRIGHT file at the top level of this repository contains the
|
||||||
|
full copyright notices and license terms. -->
|
||||||
|
<tryton>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- graph-view with context-form -->
|
||||||
|
<record model="ir.ui.view" id="evaluation_context_form">
|
||||||
|
<field name="model">cashbook_report.evaluation.context</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">evaluation_context_form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- action view - cashbook-graph -->
|
||||||
|
<record model="ir.action.act_window" id="act_evaluation_book_view">
|
||||||
|
<field name="name">Evaluation</field>
|
||||||
|
<field name="res_model">cashbook_report.eval_book</field>
|
||||||
|
<field name="context_model">cashbook_report.evaluation.context</field>
|
||||||
|
<field name="domain"
|
||||||
|
eval="[('evaluation', '=', Eval('evaluation', -1))]"
|
||||||
|
pyson="1"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.act_window.view" id="act_evaluation_book_view-1">
|
||||||
|
<field name="sequence" eval="10"/>
|
||||||
|
<field name="view" ref="book_view_graph"/>
|
||||||
|
<field name="act_window" ref="act_evaluation_book_view"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</tryton>
|
|
@ -4,7 +4,7 @@
|
||||||
# full copyright notices and license terms.
|
# full copyright notices and license terms.
|
||||||
|
|
||||||
|
|
||||||
template_view_line = '<field name="name" fill="%(fill)s" empty="0" string="%(string)s"/>'
|
template_view_line = '<field name="balance" fill="%(fill)s" empty="0" string="%(string)s"/>'
|
||||||
|
|
||||||
template_view_graph = """<?xml version="1.0"?>
|
template_view_graph = """<?xml version="1.0"?>
|
||||||
<graph type="%(type)s" legend="%(legend)s" %(colscheme)s %(bgcol)s>
|
<graph type="%(type)s" legend="%(legend)s" %(colscheme)s %(bgcol)s>
|
||||||
|
|
|
@ -306,6 +306,22 @@ class ReportTestCase(CashbookTestCase):
|
||||||
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
||||||
self.assertEqual(evaluation.currency.code, 'EUR')
|
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, """<?xml version="1.0"?>
|
||||||
|
<graph type="pie" legend="1" background="#ffffc0">
|
||||||
|
<x>
|
||||||
|
<field name="name"/>
|
||||||
|
</x>
|
||||||
|
<y>
|
||||||
|
<field name="balance" fill="1" empty="0" string="cashbooks"/>
|
||||||
|
</y>
|
||||||
|
</graph>
|
||||||
|
""")
|
||||||
|
|
||||||
self.assertEqual(len(evaluation.cashbooks), 3)
|
self.assertEqual(len(evaluation.cashbooks), 3)
|
||||||
self.assertEqual(evaluation.cashbooks[0].rec_name, 'Book 1 | 25.00 usd | Open')
|
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')
|
self.assertEqual(evaluation.cashbooks[1].rec_name, 'Book 2 | 12.50 usd | Open')
|
||||||
|
|
|
@ -7,4 +7,5 @@ xml:
|
||||||
message.xml
|
message.xml
|
||||||
graph.xml
|
graph.xml
|
||||||
evaluation.xml
|
evaluation.xml
|
||||||
|
evaluation_context.xml
|
||||||
menu.xml
|
menu.xml
|
||||||
|
|
Loading…
Reference in a new issue