book: digits für startbalance/balance ergänzt

This commit is contained in:
Frederik Jaeckel 2022-08-31 10:17:29 +02:00
parent 64e9bab592
commit 4615c04bce
2 changed files with 20 additions and 3 deletions

19
book.py
View file

@ -76,14 +76,16 @@ class Book(Workflow, ModelSQL, ModelView):
),
}, depends=DEPENDS+['lines'])
start_balance = fields.Numeric(string='Initial Amount', required=True,
digits=(16, Eval('currency_digits', 2)),
states={
'readonly': Or(
STATES['readonly'],
Bool(Eval('lines')),
),
}, depends=DEPENDS+['lines'])
balance = fields.Function(fields.Numeric(string='Balance', readonly=True),
'on_change_with_balance')
}, depends=DEPENDS+['lines', 'currency_digits'])
balance = fields.Function(fields.Numeric(string='Balance', readonly=True,
digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']), 'on_change_with_balance')
currency = fields.Many2One(string='Currency', required=True,
model_name='currency.currency',
states={
@ -92,6 +94,8 @@ class Book(Workflow, ModelSQL, ModelView):
Bool(Eval('lines', [])),
),
}, depends=DEPENDS+['lines'])
currency_digits = fields.Function(fields.Integer(string='Currency Digits',
readonly=True), 'on_change_with_currency_digits')
state = fields.Selection(string='State', required=True,
readonly=True, selection=sel_state_book)
state_string = state.translated('state')
@ -196,6 +200,15 @@ class Book(Workflow, ModelSQL, ModelView):
'state': self.state_string,
}
@fields.depends('currency')
def on_change_with_currency_digits(self, name=None):
""" currency of cashbook
"""
if self.currency:
return self.currency.digits
else:
return 2
@fields.depends('id', 'start_balance')
def on_change_with_balance(self, name=None):
""" compute balance

View file

@ -462,6 +462,10 @@ msgctxt "field:cashbook.book,currency:"
msgid "Currency"
msgstr "Währung"
msgctxt "field:cashbook.book,currency_digits:"
msgid "Currency Digits"
msgstr "Nachkommastellen Währung"
msgctxt "field:cashbook.book,start_balance:"
msgid "Initial Amount"
msgstr "Anfangsbetrag"