Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
8379 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

Dear Shalin,

This solved my problem.

Best regards

PM

Cel mai bun răspuns

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.



Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 21
16638
1
apr. 19
9986
0
mai 15
6377
3
iul. 24
24580
0
mai 24
1197