如何添加两个具有不同货币符号的浮动字段?

How to add two float fields with different currency sign?

发票行上已有金额字段,它显示发票上所选货币的金额。我想将相同的金额转换为基础货币,并在带有基础货币符号的发票行上显示基础货币金额。

为此,我为基础货币添加了新的 many2one 字段,如下所示:

base_currency_id = fields.Many2one('res.currency', default=lambda self: self.invoice_id.company_id.currency_id.id)

然后我添加了新的浮动字段来计算基础货币的金额,如下所示:

@api.onchange('price_subtotal', 'invoice_id.currency_id')
def compute_amount_in_base_currency(self):
    company_currency = self.invoice_id.company_id.currency_id
    for l in self:
        amount_in_base = l.currency_id.compute(l.price_subtotal, company_currency)
        l.amount_in_base = amount_in_base

amount_in_base = fields.Float('Base Amount', readonly=True, compute='compute_amount_in_base_currency')

在 xml 文件中,我添加了 base_currency_id 字段并使其不可见。然后使用 widget='monetary'options="{'currency_field': 'base_currency_id'}"amount_in_base 字段添加到视图中。我的 xml 文件如下所示:

<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='price_subtotal']" position="after">
    <field name="base_currency_id" invisible="True"/>
    <field name="amount_in_base" widget="monetary" options="{'currency_field': 'base_currency_id'}"/>
</xpath>