To create a relation field from products to currency rate, you can use the currency_id field on the product.product model, which represents the currency of the product. You can then define a related field that gets the USD rate for that currency.
Here's an example of how you can define the related field:
from odoo import fields, models
class ProductProduct(models.Model):
_inherit = 'product.product'
usd_rate = fields.Float(string='USD Rate', compute='_compute_usd_rate', store=True)
def _compute_usd_rate(self):
for product in self:
currency = product.currency_id
if currency:
usd_currency = self.env['res.currency'].search([('name', '=', 'USD')], limit=1)
if usd_currency:
usd_rate = currency._convert(1, usd_currency, product.company_id, fields.Date.today())
product.usd_rate = usd_rate
Hope this will help you
Thanks