asset: Feld 'change_symbol' für Prozenzzeichen + test
This commit is contained in:
parent
166a9e13a9
commit
8a4c8fa58f
7 changed files with 40 additions and 33 deletions
12
asset.py
12
asset.py
|
@ -114,6 +114,9 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
help='percentage change in value during 1 year',
|
||||
readonly=True, digits=(16,digits_percent)),
|
||||
'get_percentage_change', searcher='search_percentage')
|
||||
change_symbol = fields.Function(fields.Many2One(string='Symbol',
|
||||
readonly=True, model_name='investment.rate'),
|
||||
'get_percentage_change')
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
|
@ -564,10 +567,12 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
"""
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
name_lst = [x[len('change_'):] for x in names]
|
||||
name_lst = [x[len('change_'):] for x in names
|
||||
if x != 'change_symbol']
|
||||
tab_percent = cls.get_percentage_sql(name_lst)
|
||||
query = tab_percent.select(
|
||||
tab_percent.id,
|
||||
tab_percent.id_rate,
|
||||
*[getattr(tab_percent, x) for x in name_lst],
|
||||
where=tab_percent.id.in_([x.id for x in assets]),
|
||||
)
|
||||
|
@ -577,7 +582,10 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
|||
result = {x:{y.id: None for y in assets} for x in names}
|
||||
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
||||
for record in records:
|
||||
cnt1 = 1
|
||||
if 'change_symbol' in names:
|
||||
result['change_symbol'][record[0]] = record[1]
|
||||
|
||||
cnt1 = 2
|
||||
for x in name_lst:
|
||||
result['change_%s' % x][record[0]] = record[cnt1].quantize(exp) \
|
||||
if record[cnt1] is not None else None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue