当需要继承并覆写Odoo的Selection 字段,如何确定新选项的位置
-
我们知道Odoo的Selection字段的选项值为包含多个元组的一个列表,其中每个元组包含两个字符串成员,第一个成员为内部保存值,第二个用来界面显示,比如
class TestModel(model.Model): _name = 'test.model' myselection = fields.Selection([('a', 'A'), ('b', 'B')], string='MySelection')当在新的模块里需要继承修改这个Selection字段的选项时,我们可以使用
selection_add, 比如:class TestModel(model.Model): _inherit = 'test.model' myselection = fields.Selection(selection_add=[('c', 'C')])问题是这样的继承得到的结果是
[('a', 'A'), ('b', 'B'), ('c', 'C')],新添加的选项在列表的尾端。那有没有办法指定新添加选项在列表中的位置呢?在Odoo13以后实际上我们可以在选项值后面添加由单个成员组成的元组来确认新选项的插入位置,比如上例中:selection_add = [('c', 'C'), ('b',)] > result = [('a', 'A'), ('c', 'C'), ('b', 'B')]
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login