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

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'
          
      

الصورة الرمزية
إهمال
أفضل إجابة

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

أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
فبراير 16
5279
1
يوليو 19
3181
2
نوفمبر 16
5893
1
سبتمبر 16
7853
0
مارس 25
1279