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

How to access the return values of on_change without saving?

By
René Schuster
on 12/12/13, 9:31 AM 1,588 views

After the execution of an on_change method the returned values are displayed in the view. But how can I get them for further processing?

def onchange_date(self, cr, uid, ids, date, context=None):
    vals={'field1': 123};
    .
    .
   return {'value': vals};

In particular I need the values to be available in a button method.

def save_action(self, cr, uid, ids, context):
    a = context.get('val1', False);
    .
    .
    return True;

I've tried passing them over using a context in the xml view.

<button name="save_action" string="Save" type="object"
        context="{'val1': field1, 'val2': 6, 'val3': 'abc'}"></button>

But only the default values are passed. Not the return values of the onchange method.

2
medhabib
On 12/13/13, 4:23 AM

the fields must be of type function and you apply on_change in the xml file at the same time

Can I return a value for fields.function in onchange method? Even if: If I set the invoking field to type function, the user wont be able to change it anymore...

René Schuster
on 12/13/13, 4:29 AM

I've tried your way and was very surprised it works. onchange return values for function fields will immediately view the value. It also seems like a default value would trigger the onchange (which is not important in that case, but interessting).

Thx for your reply and the help!

René Schuster
on 12/13/13, 5:53 AM
2
Subhin P V
On 12/13/13, 5:45 AM

Use res= self.browse(cr, uid, ids, context=context) in your button function. Print res.field1 value '123' will be printed

Thank you.

Your suggestion might be the most intuitive approach. Although I thought I couldnt browse the record before it was saved...

René Schuster
on 12/13/13, 5:57 AM

but the button click occurs only after the onchange has occured. Hence if The browse is written in the Button click function then you can Surely browse the values updated during The Onchange without Saving The record

Subhin P V
on 12/18/13, 1:55 AM

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)

Stats

Asked: 12/12/13, 9:31 AM
Seen: 1588 times
Last updated: 3/16/15, 8:10 AM