Odoo Help

0

How to get value of one field to another field?

By
savita
on 7/17/17, 4:29 AM 308 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

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

Hi,

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

@api.onchange('product_id')
def set_code(self):
self.sac_hsn_code = self.product_id.sac_hsn_code

Thanks

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

Hello,

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.

0
savita
On 7/17/17, 5:35 AM

Hi Niyas,


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


Thanku

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

yes

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

@api.onchange('product_id')

def set_code(self):

self.sac_hsn_code = self.product_id.sac_hsn_code

im unable to get the value in sale order line

savita
on 7/17/17, 7:26 AM
0
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.

Register

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)

Stats

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