asset: Feld 'change_symbol' für Prozenzzeichen + test

This commit is contained in:
Frederik Jaeckel 2023-01-04 20:20:27 +01:00
parent 166a9e13a9
commit 8a4c8fa58f
7 changed files with 40 additions and 33 deletions

View file

@ -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

View file

@ -310,6 +310,10 @@ msgctxt "help:investment.asset,change_month12:"
msgid "percentage change in value during 1 year"
msgstr "Prozentuale Wertänderung während 1 Jahr"
msgctxt "field:investment.asset,change_symbol:"
msgid "Symbol"
msgstr "Symbol"
msgctxt "field:investment.asset,updtdays:"
msgid "Select days"
msgstr "Tage wählen"

View file

@ -270,6 +270,10 @@ msgctxt "help:investment.asset,change_month12:"
msgid "percentage change in value during 1 year"
msgstr "percentage change in value during 1 year"
msgctxt "field:investment.asset,change_symbol:"
msgid "Symbol"
msgstr "Symbol"
msgctxt "field:investment.asset,updtdays:"
msgid "Select days"
msgstr "Select days"

11
rate.py
View file

@ -3,13 +3,13 @@
# 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, Unique, Check
from trytond.model import ModelView, ModelSQL, fields, Unique, Check, SymbolMixin
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.pyson import Eval, Bool
class Rate(ModelSQL, ModelView):
class Rate(SymbolMixin, ModelSQL, ModelView):
'Rate'
__name__ = 'investment.rate'
@ -29,6 +29,8 @@ class Rate(ModelSQL, ModelView):
uom = fields.Function(fields.Many2One(string='Uom',
readonly=True, model_name='product.uom'),
'on_change_with_uom')
symbol = fields.Function(fields.Char(string='Symbol',
readonly=True), 'on_change_with_symbol')
@classmethod
def __setup__(cls):
@ -51,6 +53,11 @@ class Rate(ModelSQL, ModelView):
IrDate = Pool().get('ir.date')
return IrDate.today()
def on_change_with_symbol(self, name=None):
""" symbol:%
"""
return '%'
@fields.depends('asset', '_parent_asset.uom')
def on_change_with_uom(self, name=None):
""" get unit of asset

View file

@ -46,5 +46,7 @@ class RateTestCase(ModuleTestCase):
self.assertEqual(asset.rates[0].uom.rec_name, 'Unit')
self.assertEqual(asset.rates[0].asset_digits, 4)
self.assertEqual(asset.rates[0].currency.rec_name, 'usd')
self.assertEqual(asset.rates[0].symbol, '%')
self.assertEqual(asset.change_symbol.symbol, '%')
# end RateTestCase

View file

@ -6,7 +6,7 @@ full copyright notices and license terms. -->
<label name="product" />
<field name="product" colspan="3"/>
<label name="rate" />
<field name="rate" symbol="currency"/>
<field name="rate" symbol="asset_symbol"/>
<label id="labdate" string=" "/>
<label name="nextupdate" colspan="2"/>
@ -16,34 +16,16 @@ full copyright notices and license terms. -->
<separator id="sepperc" colspan="6" string="Gain and Loss"/>
<label name="change_day1" />
<group id="change_day1" col="2">
<field name="change_day1" xexpand="0"/>
<label name="change_day1" xexpand="1" xalign="0.0" string="%"/>
</group>
<field name="change_day1" symbol="change_symbol"/>
<label name="change_month1" />
<group id="change_month1" col="2">
<field name="change_month1" xexpand="0"/>
<label name="change_month1" xexpand="1" xalign="0.0" string="%"/>
</group>
<field name="change_month1" symbol="change_symbol"/>
<label name="change_month3" />
<group id="change_month3" col="2">
<field name="change_month3" xexpand="0"/>
<label name="change_month3" xexpand="1" xalign="0.0" string="%"/>
</group>
<label name="change_month6" />
<group id="change_month6" col="2">
<field name="change_month6" xexpand="0"/>
<label name="change_month6" xexpand="1" xalign="0.0" string="%"/>
</group>
<field name="change_month3" symbol="change_symbol"/>
<label name="change_month6" />
<field name="change_month6" symbol="change_symbol"/>
<label name="change_month12" />
<group id="change_month12" col="2">
<field name="change_month12" xexpand="0"/>
<label name="change_month12" xexpand="1" xalign="0.0" string="%"/>
</group>
<field name="change_month12" symbol="change_symbol"/>
<newline/>
<separator id="sepunits" colspan="6" string="Currency and Units"/>

View file

@ -4,10 +4,10 @@ The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. -->
<tree>
<field name="name" expand="1"/>
<field name="change_day1" />
<field name="change_month1" />
<field name="change_month3" />
<field name="change_month6" />
<field name="change_day1" symbol="change_symbol"/>
<field name="change_month1" symbol="change_symbol"/>
<field name="change_month3" symbol="change_symbol"/>
<field name="change_month6" symbol="change_symbol"/>
<field name="date"/>
<field name="rate" symbol="asset_symbol"/>
<field name="isin"/>