Hello,
I am facing an issue with Odoo 16 when trying to implement a calculation in a Server Action for the Purchase Order Line model. I have added a custom field called "Currency Exchange Rate" (x_studio_monetary_field_atjMK) where users manually enter the exchange rate. I want to use this exchange rate to multiply the unit price (price_unit) and update the subtotal (price_subtotal) accordingly. The calculation should be:
makefileCopy codeprice_subtotal = price_unit * exchange_rate
However, I am getting the following error:
"forbidden opcode(s) in 'lambda': STORE_ATTR"
I understand that this error occurs because certain actions like direct field updates (record.price_subtotal = ...) are restricted in Server Actions for security reasons.
Here is the code I used for the Server Action:
if record.x_studio_monetary_field_atjMK: record.price_subtotal = record.price_unit * record.x_studio_monetary_field_atjMK else: record.price_subtotal = record.price_unit
Is there any workaround or a proper way to perform this calculation and update the price_subtotal using a Server Action in Odoo 16? I would also be open to using a computed field if it helps resolve this issue.
Any help would be greatly appreciated!
Thank you.