Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
17162 Widoki

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 !

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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')
Awatar
Odrzuć
Autor

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 ?

Powiązane posty Odpowiedzi Widoki Czynność
3
sty 17
3158
0
lut 16
3017
0
lut 16
3651
0
mar 24
3216
2
mar 18
3591