Odoo Help

Welcome!

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.

0

Field.function / method not automatically updating field

By
Erhuvwu Akpobaro
on 3/25/15, 7:27 PM 1,348 views

Field.function / method not automatically updating field

i have a function which currently works when a user pick and item from  a dropdown menu it changes the value of  another field.

however the other field only changes when i click save how can i make this that as soon as i change the value of  the dropdown field the , other fields value changes without having to click save.


.py file


class account_analytic_account(osv.osv):

_name = "account.analytic.account"

_inherit = "account.analytic.account"

def get_rental(self,cr,uid,ids,context,table1,obj2):

x={}

obj1 = self.pool.get('mm.control')

for record in self.browse(cr, uid , ids):

table1 = obj1.search(cr,uid,[('company','=',record.invcompany_id.id)])

obj2=obj1.browse(cr,uid,table1[0])

x[record.id]=obj2.rental_split

print table1

print record.invcompany_id

print obj2.rental_split

return x

_columns = {


'invcompany_id': fields.many2one('res.company', 'Invoicing Company ' , domain="[('company_type', '=', 'Property Company')]" ,required=True, select=1),

'rental_split': fields.function(get_rental , method=True ,string= 'Rent', store=False, type="integer", help="Rent split of total rent amount *25"),

}


.xml


<group>

<field name="rental_split"/>

<field name="invcompany_id"/>

</group>


Any ideas to make the field automatically update without saving

1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 3/26/15, 1:29 AM

In OpenERP v7, the function and related fields  are computed and stored only after the SAVE event.

For your question, you need to have an onchange that does the same computation as your function field.

In acounting module, we have a similar case for "writeoff_amount" field.  Here, you can check that with the help of onchange they set the value for this field.

onchange_compute_method: https://github.com/odoo/odoo/blob/7.0/addons/account_voucher/account_voucher.py#L252-L259.

function_compute_method: https://github.com/odoo/odoo/blob/7.0/addons/account_voucher/account_voucher.py#L284-L297

0
Hammad hussain qureshi
On 3/26/15, 12:21 AM

Use on_change attribute in your field view defination. This can help you https://www.odoo.com/forum/help-1/question/how-to-use-onchange-in-openerp-v7-21185

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

1 follower(s)

Stats

Asked: 3/25/15, 7:27 PM
Seen: 1348 times
Last updated: 3/30/15, 1:55 AM