Python 3.x 如何添加两个具有不同货币符号的浮动字段?
我们已经在发票行上显示了金额字段,该字段以发票上选择的货币显示金额。我希望将相同金额转换为基础货币,并在带有基础货币符号的发票行上显示基础货币金额。为此,我为基础货币添加了新的manyOne字段,如下所示:Python 3.x 如何添加两个具有不同货币符号的浮动字段?,python-3.x,odoo,odoo-11,Python 3.x,Odoo,Odoo 11,我们已经在发票行上显示了金额字段,该字段以发票上选择的货币显示金额。我希望将相同金额转换为基础货币,并在带有基础货币符号的发票行上显示基础货币金额。为此,我为基础货币添加了新的manyOne字段,如下所示: base_currency_id = fields.Many2one('res.currency', default=lambda self: self.invoice_id.company_id.currency_id.id) 然后我添加了新的float字段,用于计算基础货币的金额,如下
base_currency_id = fields.Many2one('res.currency', default=lambda self: self.invoice_id.company_id.currency_id.id)
然后我添加了新的float字段,用于计算基础货币的金额,如下所示:
@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')
<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>
在xml文件中,我添加了base\u currency\u id
字段并使其不可见。然后使用widget='monetary'
和options=“{'currency\u field':'base\u currency\u id'}”将amount\u添加到视图中。我的xml文件如下所示:
@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')
<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>
使用发票的公司货币而不是用户的公司货币不是更好吗?因为用户可以切换公司。并使用dependens
而不是onchange
。