Odoo:如何显示 one2many 字段内的 many2one 字段的字段

Odoo: how to show fields of a many2one fields which is inside a one2many field

我不知道怎么说,但这就是我想要的,我想在 one2many 字段的树视图中显示 custom.product 模型的字段我的代码如下

class CustomSale(models.Model):
    _name = 'custom.sale'
    _description = 'Sale Record'

    name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True,
                       default=lambda self: _('New'))
    order_line = fields.One2many('custom.sale.line', 'order_id', string='Order Lines', copy=True,
                                 auto_join=True)


class CustomSaleLine(models.Model):
    _name = 'custom.sale.line'
    _description = 'Sales Line'

    order_id = fields.Many2one('custom.sale', string='Order Reference', required=True,)

    product_id = fields.Many2one('custom.product', string='Product', change_default=True, ondelete='restrict')
    product_uom_qty = fields.Integer(string='Ordered Quantity', required=True, )
<record id="form_custom_sale" model="ir.ui.view">
        <field name="name">custom.sale.form</field>
        <field name="model">custom.sale</field>
        <field name="arch" type="xml">
            <form string="Sales">
                <sheet>
                    <group>
                        <group>
                            <field name="name"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Order Lines" name="order_lines">
                            <field name="order_line" widget="section_and_note_one2many" mode="tree">
                                <tree editable="bottom">
                                    <control>
                                        <create string="Add a product"/>
                                    </control>
                                    <field name="product_id">
                                        <tree>
                                            <field name="brand_id"/>
                                            <field name="country_id"/>
                                            <field name="sell_price"/>
                                        </tree>
                                    </field>
                                    <field name="product_uom_qty" string="Ordered Qty"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

但我仍然无法显示 "brand_id"、"country_id" 和 "sell_price"

为要在树视图中显示的字段添加 related 字段。

class CustomSaleLine(models.Model):
    _name = 'custom.sale.line'
    _description = 'Sales Line'

    order_id = fields.Many2one('custom.sale', string='Order Reference', required=True,)

    product_id = fields.Many2one('custom.product', string='Product', change_default=True, ondelete='restrict')
    product_uom_qty = fields.Integer(string='Ordered Quantity', required=True, )
    brand_id = fields.Many2one('BRAND_MODEL_HERE',related='product_id.brand_id')
    country_id = fields.Many2one('COUNTRY_MODEL_HERE',related='product_id.country_id')
    sell_price = fields.Float(related='product_id.sell_price')


<record id="form_custom_sale" model="ir.ui.view">
    <field name="name">custom.sale.form</field>
    <field name="model">custom.sale</field>
    <field name="arch" type="xml">
        <form string="Sales">
            <sheet>
                <group>
                    <group>
                        <field name="name"/>
                    </group>
                </group>
                <notebook>
                    <page string="Order Lines" name="order_lines">
                        <field name="order_line" widget="section_and_note_one2many" mode="tree">
                            <tree editable="bottom">
                                <control>
                                    <create string="Add a product"/>
                                </control>
                                <field name="product_id">
                                <field name="brand_id"/>
                                <field name="country_id"/>
                                <field name="sell_price"/>
                                <field name="product_uom_qty" string="Ordered Qty"/>
                            </tree>
                        </field>
                    </page>
                </notebook>
            </sheet>
        </form>
    </field>
</record>