Skip to Content
Menu
This question has been flagged
3 Replies
1134 Views

Hello ,
I want to send and display a customer field in sale order line
Currently my field is correctly set in the sale order line by onchange but when I click on the save button of the order line the field becomes empty.
Here is my code below :

class Sale_order_line(models.Model):
_name = 'sale.order.line'
_inherit = 'sale.order.line'

myfield= fields.Char("taille")


@api.onchange('myfield') 
def onchange_taille(self): 

if self.order_partner_id.my_customerfield: 
values = {
'myfield': self.order_partner_id.my_customerfield and self.order_partner_id.my_customerfield or False, 
}
self.update(values)

Can anyone help me please?

Thank you

Avatar
Discard

try to give as myfield= fields.Char("taille",store="True")

Author

Thank you.I have already tried it without success

Best Answer

Hi Mame Penda Diop,

From your above explanation, i think you have defined custom field (my_customerfield) in customer (res.partner model) of sale order's customer and you want to store that field to order line's custom field (myfield).

So it's very simple to use that field's value in order line's field. You can do it by following way:

class Sale_order_line(models.Model):

    _inherit = 'sale.order.line'

    myfield= fields.Char(related='order_partner_id.my_customerfield', store=True)

Hope it will helpful for you.

Thanks and regards

Haresh Kansara

Avatar
Discard