Add format method to DictSchemaMixin
issue10758 review354001002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add format method to DictSchemaMixin
|
||||
* Allow modify record name on the reports
|
||||
* Add methods to format number and symbol on Lang
|
||||
* Add format number with symbol on Report
|
||||
|
||||
@@ -737,6 +737,10 @@ Instance methods:
|
||||
|
||||
Getter for the :attr:`selection_json`.
|
||||
|
||||
.. method:: DictSchemaMixin.format(value[, lang])
|
||||
|
||||
Format the value using the key definition and the language.
|
||||
|
||||
==========
|
||||
MatchMixin
|
||||
==========
|
||||
|
||||
@@ -124,6 +124,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_dict_schema_help_selection_json">
|
||||
<field name="text">Help Selection JSON</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_dict_yes">
|
||||
<field name="text">Yes</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_dict_no">
|
||||
<field name="text">No</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_sequence">
|
||||
<field name="text">Sequence</field>
|
||||
</record>
|
||||
|
||||
@@ -211,3 +211,29 @@ class DictSchemaMixin(object):
|
||||
def delete(cls, records):
|
||||
super().delete(records)
|
||||
cls._relation_fields_cache.clear()
|
||||
|
||||
def format(self, value, lang=None):
|
||||
pool = Pool()
|
||||
Lang = pool.get('ir.lang')
|
||||
if lang is None:
|
||||
lang = Lang.get()
|
||||
if value is None:
|
||||
return ''
|
||||
if self.type_ == 'boolean':
|
||||
if value:
|
||||
return gettext('ir.msg_dict_yes')
|
||||
else:
|
||||
return gettext('ir.msg_dict_no')
|
||||
elif self.type_ == 'integer':
|
||||
return lang.format('%i', value)
|
||||
elif self.type_ in {'float', 'numeric'}:
|
||||
return lang.format('%.*f', (self.digits, value))
|
||||
elif self.type_ in {'date', 'datetime'}:
|
||||
return lang.strftime(value)
|
||||
elif self.type_ in {'selection', 'multiselection'}:
|
||||
values = dict(json.loads(self.selection_json))
|
||||
if self.type_ == 'selection':
|
||||
return values.get(value, '')
|
||||
else:
|
||||
return "; ".join(values.get(v, '') for v in value)
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user