简体   繁体   English

如何使用Many2one字段作为选择?

[英]How to Use Many2one Field as selection?

on Odoo, I want to create a many2one field which show some items created according to another field(named 'A') and can be changed once field 'A' is changed. 在Odoo上,我想创建一个many2one字段,该字段显示根据另一个字段(名为“ A”)创建的某些项目,并且一旦更改字段“ A”就可以更改。

I have tried to use field.Selection , but failed and I switch to field.Many2one ; 我试图使用field.Selection ,但是失败了,我切换到field.Many2one ; and until now I don't complete this. 直到现在我还没有完成。

class Selection(models.Model):
    _name = 'selection.model'

    _rec_name = 'select'
    select = fields.Char(string='selections', required=True)

class Checks(models.Model):
    _name = 'buy.goods'

    strs = fields.Char()
    results = fields.Many2one('selection.model', string='Selections')

    @api.onchange('strs')
    def _get_results(self):
        goods = self.strs.split(',')        

I want to use the list of words of 'goods' as items of 'results' field and once content of 'strs' field is changed, the list of 'goods' is changed and items of 'results' should be changed automaticly. 我想将“商品”一词的列表用作“结果”字段的项目,并且一旦更改“ strs”字段的内容,“商品”的列表也将更改,并且“结果”的项目应自动更改。

When you define the form view in XML you need to add a widget called selection. 当您使用XML定义表单视图时,您需要添加一个名为selection的小部件。 Through this way you can use your many2one field as a selection field. 通过这种方式,您可以将many2one字段用作选择字段。

For example: 例如:

<field name='results' widget='selection'/>

ps: clear cache and try it ! ps:清除缓存并尝试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM