跳至内容
菜单
此问题已终结
2 回复
839 查看

Hello! 

I'm developing an addon, and in the list view I need to show some data from the inventory addon. 

I know the way to show the data from another model in a selection field, but I don't get a clue about how to show it on a list view. 


Thanks for the orientation. 

形象
丢弃
最佳答案

Hi,

In Odoo, if you want to show data from another model (like inventory) in your addon's list view, you don’t need a selection field—you should instead use a related field or a Many2one relation.


Example:

from odoo import models, fields


class MyModel(models.Model):

    _name = "my.model"

    _description = "My Custom Model"


    product_id = fields.Many2one("product.product", string="Product")


This code defines a new custom model in Odoo called my.model. Inside it, you added a field named product_id, which is a Many2one relation to the product.product model (the standard Odoo model for products). That means in your model, each record can be linked to one specific product, and in the form or list views, Odoo will show it as a dropdown/searchable field with all available products. The string="Product" part is just the label that will be shown to users in the UI.


Hope it helps.

形象
丢弃
最佳答案

You need to create a new field on the model you are listing. Then you can use that field on the list view.

The new fields needs to be computed, see the documentation here:
https://www.odoo.com/documentation/15.0/developer/tutorials/getting_started/09_compute_onchange.html

形象
丢弃
编写者

Yeah, I get that. But how I tell to the model that the data is already on another model?

相关帖文 回复 查看 活动
2
7月 25
875
0
8月 24
1433
2
12月 23
1865
1
7月 24
2321
3
6月 23
2455