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',
|
help='percentage change in value during 1 year',
|
||||||
readonly=True, digits=(16,digits_percent)),
|
readonly=True, digits=(16,digits_percent)),
|
||||||
'get_percentage_change', searcher='search_percentage')
|
'get_percentage_change', searcher='search_percentage')
|
||||||
|
change_symbol = fields.Function(fields.Many2One(string='Symbol',
|
||||||
|
readonly=True, model_name='investment.rate'),
|
||||||
|
'get_percentage_change')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __register__(cls, module_name):
|
def __register__(cls, module_name):
|
||||||
|
@ -564,10 +567,12 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
cursor = Transaction().connection.cursor()
|
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)
|
tab_percent = cls.get_percentage_sql(name_lst)
|
||||||
query = tab_percent.select(
|
query = tab_percent.select(
|
||||||
tab_percent.id,
|
tab_percent.id,
|
||||||
|
tab_percent.id_rate,
|
||||||
*[getattr(tab_percent, x) for x in name_lst],
|
*[getattr(tab_percent, x) for x in name_lst],
|
||||||
where=tab_percent.id.in_([x.id for x in assets]),
|
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}
|
result = {x:{y.id: None for y in assets} for x in names}
|
||||||
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
exp = Decimal(Decimal(1) / 10 ** digits_percent)
|
||||||
for record in records:
|
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:
|
for x in name_lst:
|
||||||
result['change_%s' % x][record[0]] = record[cnt1].quantize(exp) \
|
result['change_%s' % x][record[0]] = record[cnt1].quantize(exp) \
|
||||||
if record[cnt1] is not None else None
|
if record[cnt1] is not None else None
|
||||||
|
|
|
@ -310,6 +310,10 @@ msgctxt "help:investment.asset,change_month12:"
|
||||||
msgid "percentage change in value during 1 year"
|
msgid "percentage change in value during 1 year"
|
||||||
msgstr "Prozentuale Wertänderung während 1 Jahr"
|
msgstr "Prozentuale Wertänderung während 1 Jahr"
|
||||||
|
|
||||||
|
msgctxt "field:investment.asset,change_symbol:"
|
||||||
|
msgid "Symbol"
|
||||||
|
msgstr "Symbol"
|
||||||
|
|
||||||
msgctxt "field:investment.asset,updtdays:"
|
msgctxt "field:investment.asset,updtdays:"
|
||||||
msgid "Select days"
|
msgid "Select days"
|
||||||
msgstr "Tage wählen"
|
msgstr "Tage wählen"
|
||||||
|
|
|
@ -270,6 +270,10 @@ msgctxt "help:investment.asset,change_month12:"
|
||||||
msgid "percentage change in value during 1 year"
|
msgid "percentage change in value during 1 year"
|
||||||
msgstr "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:"
|
msgctxt "field:investment.asset,updtdays:"
|
||||||
msgid "Select days"
|
msgid "Select days"
|
||||||
msgstr "Select days"
|
msgstr "Select days"
|
||||||
|
|
11
rate.py
11
rate.py
|
@ -3,13 +3,13 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains the
|
# The COPYRIGHT file at the top level of this repository contains the
|
||||||
# full copyright notices and license terms.
|
# 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.transaction import Transaction
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.pyson import Eval, Bool
|
from trytond.pyson import Eval, Bool
|
||||||
|
|
||||||
|
|
||||||
class Rate(ModelSQL, ModelView):
|
class Rate(SymbolMixin, ModelSQL, ModelView):
|
||||||
'Rate'
|
'Rate'
|
||||||
__name__ = 'investment.rate'
|
__name__ = 'investment.rate'
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ class Rate(ModelSQL, ModelView):
|
||||||
uom = fields.Function(fields.Many2One(string='Uom',
|
uom = fields.Function(fields.Many2One(string='Uom',
|
||||||
readonly=True, model_name='product.uom'),
|
readonly=True, model_name='product.uom'),
|
||||||
'on_change_with_uom')
|
'on_change_with_uom')
|
||||||
|
symbol = fields.Function(fields.Char(string='Symbol',
|
||||||
|
readonly=True), 'on_change_with_symbol')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
@ -51,6 +53,11 @@ class Rate(ModelSQL, ModelView):
|
||||||
IrDate = Pool().get('ir.date')
|
IrDate = Pool().get('ir.date')
|
||||||
return IrDate.today()
|
return IrDate.today()
|
||||||
|
|
||||||
|
def on_change_with_symbol(self, name=None):
|
||||||
|
""" symbol:%
|
||||||
|
"""
|
||||||
|
return '%'
|
||||||
|
|
||||||
@fields.depends('asset', '_parent_asset.uom')
|
@fields.depends('asset', '_parent_asset.uom')
|
||||||
def on_change_with_uom(self, name=None):
|
def on_change_with_uom(self, name=None):
|
||||||
""" get unit of asset
|
""" get unit of asset
|
||||||
|
|
|
@ -46,5 +46,7 @@ class RateTestCase(ModuleTestCase):
|
||||||
self.assertEqual(asset.rates[0].uom.rec_name, 'Unit')
|
self.assertEqual(asset.rates[0].uom.rec_name, 'Unit')
|
||||||
self.assertEqual(asset.rates[0].asset_digits, 4)
|
self.assertEqual(asset.rates[0].asset_digits, 4)
|
||||||
self.assertEqual(asset.rates[0].currency.rec_name, 'usd')
|
self.assertEqual(asset.rates[0].currency.rec_name, 'usd')
|
||||||
|
self.assertEqual(asset.rates[0].symbol, '%')
|
||||||
|
self.assertEqual(asset.change_symbol.symbol, '%')
|
||||||
|
|
||||||
# end RateTestCase
|
# end RateTestCase
|
||||||
|
|
|
@ -6,7 +6,7 @@ full copyright notices and license terms. -->
|
||||||
<label name="product" />
|
<label name="product" />
|
||||||
<field name="product" colspan="3"/>
|
<field name="product" colspan="3"/>
|
||||||
<label name="rate" />
|
<label name="rate" />
|
||||||
<field name="rate" symbol="currency"/>
|
<field name="rate" symbol="asset_symbol"/>
|
||||||
|
|
||||||
<label id="labdate" string=" "/>
|
<label id="labdate" string=" "/>
|
||||||
<label name="nextupdate" colspan="2"/>
|
<label name="nextupdate" colspan="2"/>
|
||||||
|
@ -16,34 +16,16 @@ full copyright notices and license terms. -->
|
||||||
|
|
||||||
<separator id="sepperc" colspan="6" string="Gain and Loss"/>
|
<separator id="sepperc" colspan="6" string="Gain and Loss"/>
|
||||||
<label name="change_day1" />
|
<label name="change_day1" />
|
||||||
<group id="change_day1" col="2">
|
<field name="change_day1" symbol="change_symbol"/>
|
||||||
<field name="change_day1" xexpand="0"/>
|
|
||||||
<label name="change_day1" xexpand="1" xalign="0.0" string="%"/>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
|
|
||||||
<label name="change_month1" />
|
<label name="change_month1" />
|
||||||
<group id="change_month1" col="2">
|
<field name="change_month1" symbol="change_symbol"/>
|
||||||
<field name="change_month1" xexpand="0"/>
|
|
||||||
<label name="change_month1" xexpand="1" xalign="0.0" string="%"/>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<label name="change_month3" />
|
<label name="change_month3" />
|
||||||
<group id="change_month3" col="2">
|
<field name="change_month3" symbol="change_symbol"/>
|
||||||
<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>
|
|
||||||
|
|
||||||
|
<label name="change_month6" />
|
||||||
|
<field name="change_month6" symbol="change_symbol"/>
|
||||||
<label name="change_month12" />
|
<label name="change_month12" />
|
||||||
<group id="change_month12" col="2">
|
<field name="change_month12" symbol="change_symbol"/>
|
||||||
<field name="change_month12" xexpand="0"/>
|
|
||||||
<label name="change_month12" xexpand="1" xalign="0.0" string="%"/>
|
|
||||||
</group>
|
|
||||||
<newline/>
|
<newline/>
|
||||||
|
|
||||||
<separator id="sepunits" colspan="6" string="Currency and Units"/>
|
<separator id="sepunits" colspan="6" string="Currency and Units"/>
|
||||||
|
|
|
@ -4,10 +4,10 @@ The COPYRIGHT file at the top level of this repository contains the
|
||||||
full copyright notices and license terms. -->
|
full copyright notices and license terms. -->
|
||||||
<tree>
|
<tree>
|
||||||
<field name="name" expand="1"/>
|
<field name="name" expand="1"/>
|
||||||
<field name="change_day1" />
|
<field name="change_day1" symbol="change_symbol"/>
|
||||||
<field name="change_month1" />
|
<field name="change_month1" symbol="change_symbol"/>
|
||||||
<field name="change_month3" />
|
<field name="change_month3" symbol="change_symbol"/>
|
||||||
<field name="change_month6" />
|
<field name="change_month6" symbol="change_symbol"/>
|
||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
<field name="rate" symbol="asset_symbol"/>
|
<field name="rate" symbol="asset_symbol"/>
|
||||||
<field name="isin"/>
|
<field name="isin"/>
|
||||||
|
|
Loading…
Reference in a new issue