Skip to Content
Menu
This question has been flagged
2 Replies
8599 Views

I am using odoo 10

I have a 2 models:

from odoo import models, fields, api

class BatchOrderLine(models.Model):

_name = 'batch.order.line'

product_id = fields.Many2one('product.product', string='Article')

description = fields.Text("Description")

 

class ProjectTask (models.Model):

_inherit = "project.task" 

   order_lines = fields.One2many('batch.order.line','batch_id',string="Articles")

@api.onchange('product_id') 

def product_id_change(self):

self.description = self.product_id

xml file :

<field name="product_id" on_change="product_id_change(product_id)"/>

 <field name="description" readonly="1"/>

 

My question is : how to update the "description" field value depending on the selected field "product_id" using onchange ?


Avatar
Discard
Best Answer

Hi,

In the onchange of the field product id,  you can update the field description like this,


self.description = self.product_id.name


, This will add the product name to field description.


You can replace the above line in your onchange function. Also you can use the related field concept, which will be easier,


product_id = fields.Many2one('product.product', string='Article')

description = fields.Text("Description",  related='product_id.name')


Thanks


Avatar
Discard
Author Best Answer

It worked, thank you for your answer.

Avatar
Discard