Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    Openerp 中的 readonly

    Odoo 开发与实施交流
    6
    10
    5500
    Loading More Posts
    • 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.
    • C
      ccdos last edited by

      关于 OE 中 readonly 属性,其 本质跟我们平常 的定义有些许 不同,它直接就 禁止了form界面中的字段值写入到数据库。

      我们常用(至少我常用)的 readonly 字段,往往是希望,该字段的数值 是由程序产生和赋值,禁止人工修改,但是 这个值是需要写入到数据库的,
      但我们的愿望跟 OE 的处理是不一样的。

      这里有以前的讨论:

      【求助】如何实现添加采购明细时,采购员不能修改采购单价?<br / [检测到链接无效,已移除] br />

      今天在群里问了众位大牛,恕不一一列名了
      给出了几个方法,我自己尝试了一个感觉 较简单的,

      就是方法1 , 在 意图 只读的字段 也定义一个 onchange 函数,该函数直接使用 计算该字段值的  onchange,
      这样修改后,就会 自动强行再计算一遍,又是我们希望的数值了。

      <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;metric_spec&quot; on_change=&quot;onchange_metric_spec(metric_spec,stratify_base,nwtid)&quot;&nbsp; &nbsp; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;input_type&quot;/&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;product_id&quot; on_change=&quot;onchange_metric_spec(metric_spec,stratify_base,nwtid)&quot;&nbsp; /&gt;<br /><br />
      




      方法2,

      我自己还尝试了一个 比较 暴力的方法, 用 domain 将该字段的值 限定在其自身。

      但是 这方法 似乎不通用,非引用值 的 字段可以吗?

      <br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;product_id&#039;: fields.many2one(&#039;product.product&#039;, u&#039;对应产品&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  domain=&quot;[(&#039;id&#039;, &#039;=&#039;, product_id)]&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),<br />
      




      方法3:
      就是重载model的  write 函数,重新计算一次 只读字段的值,并加入到 vals 中,使之写入。 感觉为了一个 只读,涉及多处改写,有点麻烦.
      但是 这个 用户体验是比较好的,跟我们 平常的只读逻辑一样。只是在界面 处理后数据保存时 计算了两次


      方法4,  这是 我最希望 完成的方法, 就是 改变Oe 的处理逻辑,
      webclient 传递到 server 数据中,能包含 readonly 的值,而不是直接忽略。
      哪位能 指点 一二 ?

      1 Reply Last reply Reply Quote 0
      • mrshelly
        mrshelly last edited by

        搬凳子.... 围观..........

        1 Reply Last reply Reply Quote 0
        • 1
          18684036 last edited by

          我觉得最大的可能性就是 readonly字段,OE不写入vals中,而在onchange中,又不能控制vals,所以导致了这个字段无法保存

          1 Reply Last reply Reply Quote 0
          • wjfonhand
            wjfonhand last edited by

            赞第一种解法,实现简单。
            虽然用户体验不太好,改了白改。。。

            1 Reply Last reply Reply Quote 0
            • Joshua
              Joshua 管理员 last edited by

              第一种解法让他们“改了白改”之余,还可以返回一个waring,让他们明白为什么“改了白改”。

              1 Reply Last reply Reply Quote 0
              • mrshelly
                mrshelly last edited by

                我还是推荐

                字段 readonly 然后 onchange 后改变,

                再在 default 中, 取 onchange 的结果 返回.

                1 Reply Last reply Reply Quote 0
                • C
                  ccdos last edited by

                  不明觉历 😞

                  “在 default 中, 取 onchange 的结果”

                  不会做

                  1 Reply Last reply Reply Quote 0
                  • digitalsatori
                    digitalsatori 管理员 last edited by

                    为什么不把需要只读但是需要内部计算的字段定义成function field呢?

                    就象‘产品’对象的incoming, outgoing字段,其值是动态变化的,但是对用户是只读的,它们都是function字段

                    1 Reply Last reply Reply Quote 0
                    • Joshua
                      Joshua 管理员 last edited by

                      [quote author=digitalsatori link=topic=6052.msg15224#msg15224 date=1368024061]
                      为什么不把需要只读但是需要内部计算的字段定义成function field呢?
                      [/quote]

                      我刚开始也建议直接function field 然后加个 “计算” 按钮

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post