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

Update field on on_change method.

By
Yogesh
on 1/20/15, 9:13 AM 524 views

how to update field of parent object? eg: I want to update 'partner_id' field of 'sale.order' on changeing 'product_id' field of 'sale.order.line'. Is that possible?

I tried something like
 @api.onchange('product_id')
    def _onchange_type(self):
        if self.product_id:
            # it updates fields of same class
            self.product_uom_qty = 3232


           # but system ignores fields from parent class
            self.order_id.partner_id =  1
            self.order_id.client_order_ref = 'xyz'
          
      

0
Aitor Bouzas
On 1/20/15, 9:24 AM

Hi,

Try to use the relation field: sale.order.line has a field called order_id which could help to answer your question. Maybe you can update using "order_id.partner_id = 'id' "

Hope this helps.

Aitor Bouzas : order_id is False until record is saved (line is created).

Yogesh
on 1/20/15, 9:41 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/20/15, 11:28 PM

The first question that pops into my mind is: what is the rule if there are more than one lines are changed and each of the line yields different partner_id?

A more appropriate approach, AFAIK, is to put on_change on the order_line (which is the one2many field in sale.order to sale.order.line) and change the partner_id based on all of product_ids in order_line.

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: 1/20/15, 9:13 AM
Seen: 524 times
Last updated: 3/16/15, 8:10 AM