asset: einheit als währung/menge

This commit is contained in:
Frederik Jaeckel 2022-12-01 16:30:50 +01:00
parent c8c2afb190
commit de99f0e473
5 changed files with 30 additions and 2 deletions

View file

@ -46,6 +46,8 @@ class Asset(ModelSQL, ModelView):
domain=[ domain=[
('category', '=', Eval('product_uom')), ('category', '=', Eval('product_uom')),
], depends=['product_uom', 'product']) ], depends=['product_uom', 'product'])
uom_symbol = fields.Function(fields.Char(string='UOM', readonly=True),
'on_change_with_uom_symbol', searcher='search_uom_symbol')
rates = fields.One2Many(string='Rates', field='asset', rates = fields.One2Many(string='Rates', field='asset',
model_name='investment.rate') model_name='investment.rate')
rate = fields.Function(fields.Numeric(string='Current Rate', rate = fields.Function(fields.Numeric(string='Current Rate',
@ -259,6 +261,24 @@ class Asset(ModelSQL, ModelView):
if self.company.currency.id != self.currency.id: if self.company.currency.id != self.currency.id:
return self.company.currency.id return self.company.currency.id
@fields.depends('uom', 'currency')
def on_change_with_uom_symbol(self, name=None):
""" get symbl of uom
"""
return '%(currency)s/%(unit)s' % {
'currency': self.currency.symbol if self.currency is not None else '-',
'unit': self.uom.symbol if self.uom is not None else '-',
}
@classmethod
def search_uom_symbol(cls, names, clause):
""" search in uom
"""
return ['OR',
(('uom.rec_name',) + tuple(clause[1:])),
(('currency.rec_name',) + tuple(clause[1:])),
]
@classmethod @classmethod
def get_rate_data_sql(cls): def get_rate_data_sql(cls):
""" get sql for rate/date """ get sql for rate/date

View file

@ -138,6 +138,10 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM" msgid "UOM"
msgstr "Einheit" msgstr "Einheit"
msgctxt "field:investment.asset,uom_symbol:"
msgid "UOM"
msgstr "Einheit"
msgctxt "field:investment.asset,wkn:" msgctxt "field:investment.asset,wkn:"
msgid "NSIN" msgid "NSIN"
msgstr "WKN" msgstr "WKN"

View file

@ -110,6 +110,10 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM" msgid "UOM"
msgstr "UOM" msgstr "UOM"
msgctxt "field:investment.asset,uom_symbol:"
msgid "UOM"
msgstr "UOM"
msgctxt "field:investment.asset,wkn:" msgctxt "field:investment.asset,wkn:"
msgid "NSIN" msgid "NSIN"
msgstr "NSIN" msgstr "NSIN"

View file

@ -83,6 +83,7 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item( asset = self.prep_asset_item(
company=company, company=company,
product = product) product = product)
self.assertEqual(asset.uom_symbol, 'usd/u')
@with_transaction() @with_transaction()
def test_asset_rec_name(self): def test_asset_rec_name(self):

View file

@ -12,6 +12,5 @@ full copyright notices and license terms. -->
<field name="change_month6" /> <field name="change_month6" />
<field name="date" expand="1"/> <field name="date" expand="1"/>
<field name="rate" expand="1"/> <field name="rate" expand="1"/>
<field name="currency"/> <field name="uom_symbol"/>
<field name="uom" />
</tree> </tree>