Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
17914 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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 ?

ผู้เขียน

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

คำตอบที่ดีที่สุด
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.
อวตาร
ละทิ้ง