I am currently running Odoo v13 Community Edition. I am trying to make fields that show the converted value from USD or EUR to the currency of the Company (EGP)
I already have a Currency Rate field (currency_rate) that I can use to convert the currencies. The thing is the field called Unit Price in EGP (x_price_unit) sees the Currency Rate Field equal to zero.
Another problem I am facing is that the Currency Rate field is in the purchase.order model while the Unit Price in EGP field is in the purchase.order.line model and I do not know how I can compute Unit Price in EGP from that value. Below the image I added the code I've written to compute Unit Price in EGP.
Please guys help me if you can
Thank you in advance
Here is the code:
class PurchOrderLine(models.Model):
_inherit = 'purchase.order.line'
x_price_unit = fields.Float(readonly=True, compute="calc_unit_p", string='Unit Price in EGP', store=False)
x_sub_tot = fields.Float(readonly=True, compute="calc_sub_t", string='Subtotal in EGP', store=False)
@api.depends('price_unit')
def calc_unit_p(self):
for p in self:
po = p.env['purchase.order'].search([])
if po.currency_rate:
p.x_price_unit = p.price_unit / po.currency_rate
else:
p.x_price_unit = p.price_unit
There will be already a compute function for unit price calculation in lines. Why you are fetching all purchase orders? To achieve single record's computation, you will fetch 1000s of purchase orders?
I do not know how do I fetch the purchase order that belongs to the order line. Can you help me?