连接字符串和浮点数
Concatenate string and float
在openerp v7中是否可以输出一个前面加欧元符号的金额?
如果我尝试,例如,'€ ' + 0.0
它说我不能将浮点数附加到字符串。
您可以使用 货币 小部件轻松完成此操作。我们使用这个已经很久了。
在 python 文件中:
class your_class(orm.Model):
_inherit = 'your.class'
def _get_your_currency_id(self, cr, uid, ids, name, args, context=None):
res = {}
for voucher in self.browse(cr, uid, ids, context=context):
your_currency_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'EUR')], context=context)
if your_currency_id:
res[voucher.id] = your_currency_id[0]
return res
_columns = {
'your_amount_field' :fields.float('Your Amount Field'),
'your_currency_id': fields.function(_get_your_currency_id, type='many2one', relation='res.currency', string='Currency', readonly=True, required=True),
}
在 xml 文件中:
<field name="your_currency_id" invisible="1" />
<field name="your_amount_field" class="oe_inline" string="Test Amount" widget="monetary" options="{'currency_field': 'your_currency_id'}" />
从技术上讲,它的作用是,我们已经在 table 中拥有一堆所有可能可用的国家/地区货币,称为 res_currency。
我们只是在搜索欧元并让货币小部件使用选项字典使用特定的搜索到的欧元货币。其余的将由小部件本身处理。
您只需将小部件添加到您想要货币符号的金额字段,
<field name="your_field" widget="monetary" options="{'currency_field': 'currency_field_of_you_model'}"
在选项中,您需要在模型中提供可用的货币字段,因此它将显示特别属于该记录的货币符号,或者您可以将静态货币 ID 放在那里,然后它将显示通用符号每个案例。
在openerp v7中是否可以输出一个前面加欧元符号的金额?
如果我尝试,例如,'€ ' + 0.0
它说我不能将浮点数附加到字符串。
您可以使用 货币 小部件轻松完成此操作。我们使用这个已经很久了。
在 python 文件中:
class your_class(orm.Model):
_inherit = 'your.class'
def _get_your_currency_id(self, cr, uid, ids, name, args, context=None):
res = {}
for voucher in self.browse(cr, uid, ids, context=context):
your_currency_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'EUR')], context=context)
if your_currency_id:
res[voucher.id] = your_currency_id[0]
return res
_columns = {
'your_amount_field' :fields.float('Your Amount Field'),
'your_currency_id': fields.function(_get_your_currency_id, type='many2one', relation='res.currency', string='Currency', readonly=True, required=True),
}
在 xml 文件中:
<field name="your_currency_id" invisible="1" />
<field name="your_amount_field" class="oe_inline" string="Test Amount" widget="monetary" options="{'currency_field': 'your_currency_id'}" />
从技术上讲,它的作用是,我们已经在 table 中拥有一堆所有可能可用的国家/地区货币,称为 res_currency。
我们只是在搜索欧元并让货币小部件使用选项字典使用特定的搜索到的欧元货币。其余的将由小部件本身处理。
您只需将小部件添加到您想要货币符号的金额字段,
<field name="your_field" widget="monetary" options="{'currency_field': 'currency_field_of_you_model'}"
在选项中,您需要在模型中提供可用的货币字段,因此它将显示特别属于该记录的货币符号,或者您可以将静态货币 ID 放在那里,然后它将显示通用符号每个案例。