我正在使用 Odoo v10 。
正如我们在purchase.order 中所知,有一个基础(货币)字段amount_total,它包含基于(self)currency_id 的采购订单总金额的值。
现在,我在 purchase.order 中创建了一个新的 float 字段 home_currency_amount_total 。
home_currency_amount_total = fields.Float(string='Total Amount in company currency', store=True)
我如何根据公司货币在此字段中获得值(value)?即我想在公司基础货币中有一个相应的值,并且可以在我的树和表单 View 中使用。
我是 Odoo 的新手,我想知道是否有“快捷方式”(例如内置计算方法)而不是我必须编写相关代码。
最佳答案
有一种内置的货币转换方法。
例如。
@api.model
def _compute(self, from_currency, to_currency, from_amount, round=True):
if (to_currency == from_currency):
amount = to_currency.round(from_amount) if round else from_amount
else:
rate = self._get_conversion_rate(from_currency, to_currency)
amount = to_currency.round(from_amount * rate) if round else from_amount * rate
return amount
所以,如果你想计算转换,你可以使用这个方法。
此方法需要 3 个参数,第一个是货币,第二个是您要转换为第三个参数的货币和金额。
例如。
self.env['res.currency']._compute(order.currency_id,order.company_id.currency_id,order.amount_total)
更新:
像这样创建你的领域。
home_currency_amount_total = fields.Float(string='Total Amount in company currency', compute="_compute", store=True)
@api.depends('order_lines.price_subtotal','company_id','currency_id')
def _compute(self);
for order in self:
home_currency_amount_total = self.env['res.currency']._compute(order.currency_id,order.company_id.currency_id,order.amount_total)
关于openerp - Odoo v10 在采购树和表单 View 中以公司货币显示金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44982478/