Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Is it possible to calculate the value of a field from another field in the same form?

on 7/11/13, 9:46 PM 1,917 views


I need to calculate the interest of a payment depending of the amountPay and the interestType fields that the user completes on a form. When the user hits submit I need to insert in the interest field lets say amountPay * 0.05.

The problem is that as interest is a function field and it searches for the value of the current amountPay and interestType records it fails because they haven't been saved yet. If after saving I edit the field and save it again then I get the correct interest.

Is there any way I can do this on the fly just by hitting submit 1 time?

Any tip in the right direction will be much appreciated, thanks!

You should take a look at on_change function.

voathnak lim
on 7/11/13, 10:48 PM

Grover Menacho

--Grover Menacho--
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 7/11/13, 11:15 PM

A dummy button can be useful to update your values with a function field.

Anyways you can write a on_change function. You can do something like this. I'm just supposing that your module is like this. But, It's going to guide you.

def onchange_amountPay(self, cr, uid, ids, amountPay, interestType)
return {'value': {'interest': interest}}

and on your view

<field name='amountPay' on_change="onchange_amountPay(amountPay, interestType)"/>
<field name='interestType' on_change="onchange_amountPay(amountPay, interestType)"/>

That it's going to help you. But it just calculate and show it only to the user. It's just to change it on the fly. The real value is calculated on the function.

If you have any question comment here.


Thanks! I always forget how many things the onchange method can achieve!

on 7/12/13, 3:22 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 7/11/13, 9:46 PM
Seen: 1917 times
Last updated: 3/16/15, 8:10 AM