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

I have to display fields from diferents models on one new form view.

Any suggestion?

Awatar
Odrzuć

you can make use of the related fields or compute fields. Meanwhile, if you can brief your requirements you will get more accurate suggestions

Najlepsza odpowiedź

Hi, 


To display fields from different models on a new form view in Odoo, you can use related fields. Create a model with related fields that point to the fields you want to display. Here's an example:


from odoo import models, fields, api

class CustomModel(models.TransientModel):
    _name = 'custom.model'

    # Fields related to the Partner model
    partner_id = fields.Many2one('res.partner', string='Partner')
    partner_name = fields.Char(string='Partner Name', related='partner_id.name', readonly=True)

    # Fields related to the Product model
    product_id = fields.Many2one('product.product', string='Product')
    product_name = fields.Char(string='Product Name', related='product_id.name', readonly=True)

    # Fields related to the Sale Order model
    sale_order_id = fields.Many2one('sale.order', string='Sale Order')
    sale_order_date = fields.Date(string='Sale Order Date', related='sale_order_id.date_order', readonly=True)In this example, partner_name, product_name, and sale_order_date are related fields that fetch information from the res.partner, product.product, and sale.order models, respectively.


Now, you can create a new form view for this custom.model where you can display these related fields.


Hope it helps

Awatar
Odrzuć