تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6496 أدوات العرض

Hello,

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.

أفضل إجابة

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)
interest=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.

Regards.

الصورة الرمزية
إهمال
الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
مايو 25
2430
1
أبريل 25
1846
3
سبتمبر 24
15090
2
فبراير 24
2893
1
يوليو 23
3038