Odoo Help


How to get value of one field to another field?

on 7/17/17, 4:29 AM 794 views

Hi everyone,

I created one field in product.template table called 'sac_hsn_code': fields.char(type='string', string='SAC/HSN code'), now same field i created in sale.order.line table ..I need value of 'sac_hsn_code' in product table to be displayed in same field of sale.order.line table.

KIndly post the suggestions how i can be done.

Thanku in advance


Niyas Raphy

--Niyas Raphy--
--Niyas Raphy--

Odoo Techno Functionalist @ Cybrosys Techno Solutions

Graduation : B-Tech in Computer Science & Engineering from Calicut University (2012 - 2016)

Feel free to contact :  niyasraphyk@gmail.com

Niyas Raphy
On 7/17/17, 4:41 AM


As you have a new field named "sac_hsn_code" in the product.template , if you have already a field in the sale order line to display the value of the "sac_hsn_code", then in the onchange function of the product id in the sale order line, you can write the value of the corresponding product like this,

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

sac_hsn_code = fields.Char('HSN Code')

def set_code(self):
self.sac_hsn_code = self.product_id.sac_hsn_code



Mohammed Amal

--Mohammed Amal--

| 5 3 7
Malappuram, India
--Mohammed Amal--

Email : mohammedamal.n@gmail.com

Mohammed Amal
On 7/17/17, 5:27 AM


You can use related fields

sac_hsn_code = fields.Char(related='product_id.sac_hsn_code')

Or you can add a compute field for your field.

On 7/17/17, 5:35 AM

Hi Niyas,

Unable to get the value in sale.order.line.


Did you add a new field in the sale order line ? what error does it show ?

Did you checked the method mohammed amal told ?

Niyas Raphy
on 7/17/17, 5:44 AM


class product_template(osv.osv):

_name = "product.template"

'sac_hsn_code': fields.char(type='string', string='SAC/HSN code'),

class SaleOrderLine(models.Model):

_name = 'sale.order.line'

sac_hsn_code = fields.Char(type='string', string='SAC/HSN code')


def set_code(self):

self.sac_hsn_code = self.product_id.sac_hsn_code

im unable to get the value in sale order line

on 7/17/17, 7:26 AM
Paulius Pažarauskas
On 7/17/17, 10:35 AM
Mohammed Amal's answer is correct. Simply add the field with the related attribute to sale.order.line model. Keep in mind that related fields are not stored in the database by default. If you need it stored, add store=True to the field parameters.
For the field to show up in sale order lines, you also need to inherit the sale.order.line tree view inside of sale.order form view, and add your field there, otherwise you will not be able to see it.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/17/17, 4:29 AM
Seen: 794 times
Last updated: 7/18/17, 9:23 AM