Skip to Content
Menu
This question has been flagged
7 Replies
14811 Views
Best Answer

Hi,

It is simple as the name suggests. Means its a field, related to another model through a field on the same model.

We use them normally when we need to fetch some value from another model (say model_B) and we already have one field in current model (say model_A) which is linked to that model (for eg. a many2one field). So through that many2one field we can reach model_B and fetch the value to our related field.

For eg:

Suppose I want to show qty_available of a product on the sale order line. So through the product_id (many2one) field you can reach product.template model and fetch the qty_available. Here the qty_avail field is related to product_id.qty_available

class sale_order_line(models.Model):

_inherit = "sale.order.line"

qty_avail = fields.Float(related="product_id.qty_available", string="Quantity Available", readonly=True)

One thing to note is that, both the field types should be same. That means here the qty_avail and qty_available

Hope this helps!

Avatar
Discard
Author

Perfect Thank You Akhil :)

HI sir, product_id (many2one) field can reach product.product , not yet reach product.template.

Best Answer

In sort ,it use the HAS-A relation in between entity ,  and help in  simplifying your task .

the Changes will always  reflect in both the related model simultaneously .


Lets' take an example:

if i have a model student.student and student.student have a Many2one field associated with res.partner .


At the time of creation :

if you will make the name and email as the related field , it will automatically fill  the data ( name , email) in the  student.student  from res.partner

This save the end-user time.

At time of updation :

in future if you want to change the email and also want to synchronize the records between entity  , here related field will also help you.

if you change the email  and name here, it will  automatically update the email , name of res.partner also .

 

try these link for reference :

http://stackoverflow.com/questions/3887675/what-is-the-use-of-related-fields-in-openerp

http://stackoverflow.com/questions/33869087/how-to-use-related-fields-fields-related-in-odoo-8

Avatar
Discard
Author

thank you sharma

Best Answer

That example of using a related field on product.qty_available doesn't work, at least not in Odoo 8. Field qty_available is a function field, and the related field is not updated properly.

Avatar
Discard
Best Answer

The Related field is used to fetch another field from the relational table.

Avatar
Discard