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 14 條件隱藏刪除按鈕

odoo 14 條件隱藏刪除按鈕

Scheduled Pinned Locked Moved Odoo 开发与实施交流
9 Posts 2 Posters 3.9k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    samchou
    wrote on last edited by
    #1

    請問ODOO 14 如何有條件的隱藏刪除按鈕

    D 1 Reply Last reply
    0
    • S samchou

      請問ODOO 14 如何有條件的隱藏刪除按鈕

      D Offline
      D Offline
      digitalsatori
      管理员
      wrote on last edited by
      #2

      @samchou 可以考虑一下字段的state属性,可以设置在某个state下,该数据为只读,只读数据也就没有了删除按钮。

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        samchou
        wrote on last edited by samchou
        #3

        請問是這樣嗎?
        <field name="state" attrs="{'readonly':[('state', '=', 'Y')]}" invisible="1" / >
        我試過刪除按鈕還是存在

        D 1 Reply Last reply
        0
        • S samchou

          請問是這樣嗎?
          <field name="state" attrs="{'readonly':[('state', '=', 'Y')]}" invisible="1" / >
          我試過刪除按鈕還是存在

          D Offline
          D Offline
          digitalsatori
          管理员
          wrote on last edited by
          #4

          @samchou 在 odoo 14 條件隱藏刪除按鈕 中说:

          請問是這樣嗎?
          <field name="state" attrs="{'readonly':[('state', '=', 'Y')]}" invisible="1" / >
          我試過刪除按鈕還是存在

          不是的。

          你可以看一下订单中的order_line字段的定义(对应sale.order.line对象), 注意一下里面的states用法。

              order_line = fields.One2many('sale.order.line', 'order_id', string='Order Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True, auto_join=True)
          

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            samchou
            wrote on last edited by
            #5

            ef5e20f6-bea8-4d7b-a061-39d162cb5ba1-圖片.png

            1ffb079d-c9e9-4624-bde0-124e8e5ad84c-圖片.png

            我在state 有設定 Y 跟 N

            D 1 Reply Last reply
            0
            • S samchou

              ef5e20f6-bea8-4d7b-a061-39d162cb5ba1-圖片.png

              1ffb079d-c9e9-4624-bde0-124e8e5ad84c-圖片.png

              我在state 有設定 Y 跟 N

              D Offline
              D Offline
              digitalsatori
              管理员
              wrote on last edited by
              #6

              @samchou 首先你的对象上要有state这个字段,不要想当然的乱用啊,自己看一下文档介绍吧:https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#fields

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                samchou
                wrote on last edited by
                #7

                8cb64f10-4790-47e1-9a1a-92a2f288671d-圖片.png
                但是擋不掉
                d9afbff5-c6f7-4d29-8f85-7ec212e6d7ac-圖片.png

                D 1 Reply Last reply
                0
                • S samchou

                  8cb64f10-4790-47e1-9a1a-92a2f288671d-圖片.png
                  但是擋不掉
                  d9afbff5-c6f7-4d29-8f85-7ec212e6d7ac-圖片.png

                  D Offline
                  D Offline
                  digitalsatori
                  管理员
                  wrote on last edited by
                  #8

                  @samchou

                  state是作为一个对象中的一个标志字段,用来作为动态判断的条件,比如这条记录的状态在'confirmed'的时候,这条记录就变成readonly,也就是不能删除了。

                  所以,首先你要有一个名字叫state的状态字段, 然后比如象订单明细(order_line)这样的字段就可以使用states属性来动态改变order_line在什么state下变为readonly。

                  你目前的用法完全不对啊, 还是看看我上面的文档链接,然后再看看addons/sale里的例子的用法吧。

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    samchou
                    wrote on last edited by samchou
                    #9

                    13334f32-634f-467d-ae0d-1b3b98b6832b-圖片.png
                    sale.order的設定

                    3990d876-8152-47d9-bf3b-e1293301099d-圖片.png

                    1bd0f1e9-c8bc-41b5-9a7f-c09ce7627b48-圖片.png
                    我的設定

                    但是還是出現錯誤
                    ac2f9b22-a45d-493f-a6f5-a022e3eac194-圖片.png

                    1 Reply Last reply
                    0

                    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