diff --git a/book.py b/book.py index dd92f35..2adfb4f 100644 --- a/book.py +++ b/book.py @@ -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 diff --git a/locale/de.po b/locale/de.po index 37bc9fb..b8b5947 100644 --- a/locale/de.po +++ b/locale/de.po @@ -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"