This question has been flagged
5 Replies
16223 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

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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.

Avatar
Discard
Best Answer

Didn't work the code said by Mohammed Amal. It shows an internal server error.

from odoo import fields , models , api 

class PurchaseOrderFields(models.Model):

_inherit = 'purchase.order'
_description = "Purchase Order"

#-------------------- -----------------------------------New Fields of PO----------- -----------------------------------------------

series_code = fields .Char( string = "Series_Code" )
series_desc = fields.Selection(([ "1" , "" ]) , related = 'series_code.series_desc' )

effective_date = fields.Date( string= "Effective Date" )
# customer_code = fields.Integer(string="Customer Code & Name")
# customer_desc = fields.Char(related='customer_code.customer_desc')
activity = fields.Selection([( "1" , "Choose one" ) , ( "2" , "Yes" ) , ( "3" , "No" )] ,
string = "Activity" )


Avatar
Discard
Author Best Answer

Hi Niyas,


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


Thanku

Avatar
Discard

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

Did you checked the method mohammed amal told ?

Author

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

Best Answer
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.
Avatar
Discard