Community mailing list archives

community@mail.odoo.com

Re: Getting field in javascript

by
Mohamed Magdy
- 01/28/2015 08:13:19
Dear Heba,

It will be nice if you format the text in your email, so that we can read it easily.
I reformatted it to make it easier for others to help.

I am working on odoo 8 and I want to get the value of  model field in javascript code to do certain action when this field has certain value.

I tried the following idea but it doesn’t work:

var model = new instance.web.Model("survey.user_input");

model.call("get_state", {context: new instance.web.CompoundContext()}).then(function(result) { alert(result)});

and in the field survey.user_input I created the following function

def get_state(self, cr, uid, automatic=False, context=None):

        user_input_ids = self.search(cr, uid, [],context=context)

        id = len(user_input_ids)-1

        survey_obj = self.browse(cr, uid, id, context=context)

        return {'state': survey_obj.state}

How can this be performed?

Thanks in advance.

 

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe