ansicht begonnen

This commit is contained in:
Frederik Jaeckel 2022-10-31 20:45:40 +01:00
parent f4950c5033
commit 5809a7caba
2 changed files with 76 additions and 3 deletions

View file

@ -12,6 +12,7 @@ from trytond.i18n import gettext
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.pool import Pool from trytond.pool import Pool
from .colors import sel_color as sel_bgcolor from .colors import sel_color as sel_bgcolor
from .templates import template_view_graph, template_view_line
sel_etype = [ sel_etype = [
@ -93,6 +94,11 @@ 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',
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')
@classmethod @classmethod
def default_currency(cls): def default_currency(cls):
""" currency of company """ currency of company
@ -145,6 +151,73 @@ class Evaluation(ModelSQL, ModelView):
""" """
return 'pie' return 'pie'
@classmethod
def actionview_create(cls, evaluations):
""" create action views for current setup of evaluation
"""
pool = Pool()
ActionActWindow = pool.get('ir.action.act_window')
UiView = pool.get('ir.ui.view')
#cls.actionview_delete(charts)
to_write_eval = []
for evaluation in evaluations:
if evaluation.dtype:
if getattr(evaluation, evaluation.dtype) == 0:
continue
view_graph, = UiView.create([{
'model': 'cashbook_report.%s' % {
'cashbooks': 'eval_book',
'types': 'eval_type',
'currenciews': 'eval_currency',
}[evaluation.dtype],
'module': 'cashbook_report',
'priority': 10,
'type': 'graph',
'data': template_view_graph % {
'bgcol': '#ffffc0',
'legend': '1',
'lines': template_view_line % {
'fill': '1',
'string': evaluation.dtype,
},
},
}])
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],
{
'ui_view_point': view_point.id,
'ui_view_chart': view_chart.id,
'action_view': action_view.id,
}])
if len(to_write_chart) > 0:
Chart2.write(*to_write_chart)
@classmethod @classmethod
def write(cls, *args): def write(cls, *args):
""" unlink records if dtype changes """ unlink records if dtype changes

View file

@ -4,12 +4,12 @@
# full copyright notices and license terms. # full copyright notices and license terms.
template_view_line = '<field %(linecolor)s name="%(yname)s" fill="%(fill)s" empty="0" string="%(string)s"/>' template_view_line = '<field name="name" fill="%(fill)s" empty="0" string="%(string)s"/>'
template_view_point = """<?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>
<x> <x>
<field name="%(xname)s"/> <field name="name"/>
</x> </x>
<y> <y>
%(lines)s %(lines)s