Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
8411 Visualizzazioni

Hello everyone,

I am using Odoo 12 and need to show a field from a related model on a tree view.

Model 1: This is the origin model where I want to grab the field

    class OriginModel(models.Model):
        _name = 'model1'

        desired_field = fields.Char('Desired Field)

Model 2: This is the destination model

    class DestinationModel(models.Model):
        _name = 'model2'
        _description = 'This is where I need to show the related field from model1'

        model1_id = fields.Many2one('model1','Origin Model')

Now I need to show the "desired_field" from model1 on a tree view for "model2"

The tree view:

    <record id="any_name_tree_view" model="ir.ui.view">
        <field name="name">tree view that shows model1 field</field>
        <field name="model">model2</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree>
                    <!-- HOW TO SHOW DESIRED FIELD HERE????? -->
            </tree>
        </field>
    </record>

Thank you all in advance

Regards

PM


Avatar
Abbandona
Risposta migliore

is it ok for you to create a related field in model2
relatedfield = fields.something(related='model1_id.desired_field'
and show the relatedfield in model 2s tree view

Avatar
Abbandona
Autore

Dear Shalin,

This solved my problem.

Best regards

PM

Risposta migliore

Hi Paulo,

You can create a new related field in model 2 . 

desired_field_related = fields.Char(related = 'model1_id.desired_field')

Then you can write this new field in your xml file.

 Hope this helps.



Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
dic 21
16728
1
apr 19
10022
0
mag 15
6478
3
lug 24
24709
0
mag 24
1252