跳至內容
選單
此問題已被標幟
2 回覆
8400 瀏覽次數

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


頭像
捨棄
最佳答案

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

頭像
捨棄
作者

Dear Shalin,

This solved my problem.

Best regards

PM

最佳答案

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.



頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
12月 21
16701
1
4月 19
10015
0
5月 15
6463
3
7月 24
24664
0
5月 24
1245