line: Einheit für Anzahl, book: symbol für Asset + tests

This commit is contained in:
Frederik Jaeckel 2022-12-22 16:01:10 +01:00
parent 70416dbc12
commit 71aa1de06f
6 changed files with 29 additions and 14 deletions

15
book.py
View file

@ -3,14 +3,14 @@
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.model import fields
from trytond.model import fields, SymbolMixin
from trytond.exceptions import UserError
from trytond.pool import PoolMeta
from trytond.pyson import Eval, Or, Len
from trytond.modules.cashbook.book import STATES2, DEPENDS2
class Book(metaclass=PoolMeta):
class Book(SymbolMixin, metaclass=PoolMeta):
__name__ = 'cashbook.book'
asset = fields.Many2One(string='Asset',
@ -53,6 +53,8 @@ class Book(metaclass=PoolMeta):
Len(Eval('lines')) > 0,
),
}, depends=DEPENDS2+['feature', 'lines', 'asset_uomcat'])
symbol = fields.Function(fields.Char(string='Symbol', readonly=True),
'on_change_with_symbol')
@fields.depends('asset', 'quantity_uom')
def on_change_asset(self):
@ -67,6 +69,15 @@ class Book(metaclass=PoolMeta):
"""
return 4
@fields.depends('quantity_uom', 'currency')
def on_change_with_symbol(self, name=None):
""" get symbol for asset
"""
return '%(currency)s/%(unit)s' % {
'currency': getattr(self.currency, 'symbol', '-'),
'unit': getattr(self.quantity_uom, 'symbol', '-'),
}
@fields.depends('asset', '_parent_asset.uom')
def on_change_with_asset_uomcat(self, name=None):
""" get uom-category of asset