diff --git a/asset.py b/asset.py index 9c40c3d..f428cab 100644 --- a/asset.py +++ b/asset.py @@ -46,6 +46,8 @@ class Asset(ModelSQL, ModelView): domain=[ ('category', '=', Eval('product_uom')), ], 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', model_name='investment.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: 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 def get_rate_data_sql(cls): """ get sql for rate/date diff --git a/locale/de.po b/locale/de.po index ac567f4..2185c6d 100644 --- a/locale/de.po +++ b/locale/de.po @@ -138,6 +138,10 @@ msgctxt "field:investment.asset,uom:" msgid "UOM" msgstr "Einheit" +msgctxt "field:investment.asset,uom_symbol:" +msgid "UOM" +msgstr "Einheit" + msgctxt "field:investment.asset,wkn:" msgid "NSIN" msgstr "WKN" diff --git a/locale/en.po b/locale/en.po index f35f434..42552c2 100644 --- a/locale/en.po +++ b/locale/en.po @@ -110,6 +110,10 @@ msgctxt "field:investment.asset,uom:" msgid "UOM" msgstr "UOM" +msgctxt "field:investment.asset,uom_symbol:" +msgid "UOM" +msgstr "UOM" + msgctxt "field:investment.asset,wkn:" msgid "NSIN" msgstr "NSIN" diff --git a/tests/test_asset.py b/tests/test_asset.py index 798518f..5499638 100644 --- a/tests/test_asset.py +++ b/tests/test_asset.py @@ -83,6 +83,7 @@ class AssetTestCase(ModuleTestCase): asset = self.prep_asset_item( company=company, product = product) + self.assertEqual(asset.uom_symbol, 'usd/u') @with_transaction() def test_asset_rec_name(self): diff --git a/view/asset_list.xml b/view/asset_list.xml index 9f2834a..0da0451 100644 --- a/view/asset_list.xml +++ b/view/asset_list.xml @@ -12,6 +12,5 @@ full copyright notices and license terms. --> - - +