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

Hi,


I want to add product type in sale order lines but the field is on another model.

How can I get its value ?


Thanks in advance !

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

I put it here in case someone needs to do it as well.

Here is the final code :

class SaleOrder(models.Model):

    _inherit = "sale.order"


class SaleOrderLine(models.Model):

    _inherit = "sale.order.line"


    product_type_id = fields.Selection(related='product_id.product_tmpl_id.type', string='Type')


I found it thanks to this link : https://www.odoo.com/fr_FR/forum/aide-1/question/odoo-10-how-to-set-a-product-category-field-to-the-sale-order-line-128344

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

When you need to show the value of a field from a relational model to the current model you can do that by defining a related field. To do that you need in the field definition to define attribute related with value sequence of field names.

class AccountInvoiceInherited(models.Model):

    _inherit = 'account.invoice'

    company_selection = fields.Many2one('account.analytic.account', string="Company")

class AccountMoveInherited(models.Model):

    _inherit = 'account.move'

    rel_account_invoice = fields.Many2one('account.invoice', string='Related Account Invoice')

    rel_company_selection = fields.Many2one('account.analytic.account', string="Company",     related='rel_account_invoice.company_selection')
อวตาร
ละทิ้ง
ผู้เขียน

OK, so I have this :

class SaleOrder(models.Model):

_inherit = "sale.order"

class ProductTemplate(models.Model):

_inherit = 'product.template'

class SaleOrderLine(models.Model):

_inherit = "sale.order.line"

type_id = fields.Many2one("product.template", string="Type")

rel_type_id = fields.Many2one("product.template.type", string="Type", related="type_id.type")

What am I missing ?

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ม.ค. 17
3244
0
ก.พ. 16
3067
0
ก.พ. 16
3739
0
มี.ค. 24
3358
2
มี.ค. 18
3650