Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 培训
  4. 当需要继承并覆写Odoo的Selection 字段,如何确定新选项的位置

当需要继承并覆写Odoo的Selection 字段,如何确定新选项的位置

Scheduled Pinned Locked Moved Odoo 培训
odoo技术selection字段
1 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digitalsatori
    管理员
    wrote on last edited by digitalsatori
    #1

    我们知道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')] 
    

    【上海先安科技】(tony AT openerp.cn)

    1 Reply Last reply
    1

    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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Tags
    • Popular
    • Users
    • Groups