I'm running Odoo v13 Community Edition and I am trying to create a field in Purchase Order that changes its label and appears depending on the currency chosen in a many2one. I've overriden the purchase.order model and created the field. The following is the code I've written.
from odoo import api, fields, models
class PurchaseOrder (models.Model):
_inherit = "purchase.order"
rate = fields.Float( )
cur = fields.Boolean(compute="currency_rate", default=False)
@api.depends("currency_id")
def currency_rate(self):
for po in self:
if po['currency_id']:
if po['currency_id'].name == "USD" or po['currency_id'].name == "EUR":
po.cur = True
else:
po.cur = False
I added this line to the field rate in the xml:
<field name="rate" attrs="{'invisible':[('cur', '=', False)]}"/>
The field rate does not appear as a default (as it should) but when I change the Currency field to USD or EUR this error pops up:
Something went wrong !
purchase.order(<NewId 0x7f54a34b25b0>,).rate
What should I do?
Hope these tips will help you: https://sites.google.com/view/thinkincode/erp/odoo