asset:tabellenzugriff optimiert,
diagram: darstellung in diagramm ergänzt
This commit is contained in:
parent
83acfbb14b
commit
1a61b112e0
9 changed files with 352 additions and 6 deletions
112
diagram.py
Normal file
112
diagram.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the investment-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, ModelSQL, fields
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from sql.functions import Function
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class Concat2(Function):
|
||||
""" concat columns
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'concat'
|
||||
|
||||
# end Concat2
|
||||
|
||||
|
||||
class GraphDef(metaclass=PoolMeta):
|
||||
__name__ = 'diagram.graphdef'
|
||||
|
||||
asset = fields.Many2One(string='Asset',
|
||||
model_name='investment.asset',
|
||||
states={
|
||||
'invisible': Eval('dtype', '') != 'investment.asset',
|
||||
'required': Eval('dtype', '') == 'investment.asset',
|
||||
}, depends=['dtype'])
|
||||
|
||||
@classmethod
|
||||
def _get_dtypes(cls):
|
||||
""" return list of types
|
||||
"""
|
||||
l1 = super(GraphDef, cls)._get_dtypes()
|
||||
l1.append('investment.asset')
|
||||
return l1
|
||||
|
||||
def get_recname_value(self):
|
||||
""" value by dtype
|
||||
"""
|
||||
if self.dtype == 'investment.asset':
|
||||
return getattr(self.asset, 'rec_name', '-')
|
||||
return super(GraphDef, self).get_recname_value()
|
||||
|
||||
def get_field_key(self):
|
||||
""" get to read value from json
|
||||
"""
|
||||
if self.dtype == 'investment.asset':
|
||||
return 'asset%d' % self.asset.id
|
||||
return super(GraphDef, self).get_field_key()
|
||||
|
||||
def get_scaling_for_investment_asset(self):
|
||||
""" get scaling for currency
|
||||
"""
|
||||
Rate = Pool().get('investment.rate')
|
||||
|
||||
if self.scaling == 'fix':
|
||||
return None
|
||||
|
||||
if self.scaling == 'alldata':
|
||||
query = [('asset.id', '=', self.asset.id)]
|
||||
elif self.scaling == 'view':
|
||||
query = [
|
||||
('asset.id', '=', self.asset.id),
|
||||
('date', '>=', self.chart.used_start_date()),
|
||||
('date', '<=', self.chart.used_end_date()),
|
||||
]
|
||||
elif self.scaling == 'six':
|
||||
query = [
|
||||
('asset.id', '=', self.asset.id),
|
||||
('date', '>=', self.chart.used_start_date() - timedelta(days=180)),
|
||||
('date', '<=', self.chart.used_end_date()),
|
||||
]
|
||||
|
||||
min_rec = Rate.search(query, limit=1, order=[('rate', 'ASC')])
|
||||
max_rec = Rate.search(query, limit=1, order=[('rate', 'DESC')])
|
||||
min_val = min_rec[0].rate if len(min_rec) > 0 else None
|
||||
max_val = max_rec[0].rate if len(max_rec) > 0 else None
|
||||
|
||||
return self.compute_scaling_factor(min_val, max_val)
|
||||
|
||||
# end GraphDef
|
||||
|
||||
|
||||
class ChartPoint(metaclass=PoolMeta):
|
||||
__name__ = 'diagram.point'
|
||||
|
||||
@classmethod
|
||||
def get_table_parts(cls):
|
||||
""" return a list of tables to union,
|
||||
table must contain the columns:
|
||||
date, key, val
|
||||
"""
|
||||
pool = Pool()
|
||||
Rate = pool.get('investment.rate')
|
||||
tab_rate = Rate.__table__()
|
||||
|
||||
tabparts = super(ChartPoint, cls).get_table_parts()
|
||||
|
||||
# rate
|
||||
tabparts.append(tab_rate.select(
|
||||
tab_rate.date,
|
||||
Concat2('asset', tab_rate.asset).as_('key'),
|
||||
tab_rate.rate.as_('val'),
|
||||
))
|
||||
return tabparts
|
||||
|
||||
# end ChartPoint
|
Loading…
Add table
Add a link
Reference in a new issue