ReadOnly field saved with NULL value

2019-01-29 00:38发布

On CRM opportunity form view, i added readonly="1" for probability field. When i saved, whatever the value of my probability, it's stored with NULL value. Is it a bug on OpenERP ?

4条回答
ゆ 、 Hurt°
2楼-- · 2019-01-29 01:20

In openerp Readonly field is use to just display the content but it will not store any data in database. So it is displaying Null value. Readonly is just for informative purpose only.

查看更多
Root(大扎)
3楼-- · 2019-01-29 01:22

change your probability field to function field, and write a function (ex _get_probability). And keep the current probability calculating function as it is. Now default probability calculate function display the value and second function (_get_probability) will save the value.

查看更多
倾城 Initia
4楼-- · 2019-01-29 01:26

We have two values like client side and server side. In Server side coding done like float value have 0.0 etc. Read only field doesn't take value from the Client side because it's read only. In View, we see that 0.0 for float value because of server side coding. If you remove read only attribute, you can get value from the Client side and that value pass to the Server and store into the Database. Field with read only attribute, can't get value from the client side and store NULL into the Database.

Hope this will help you.

查看更多
趁早两清
5楼-- · 2019-01-29 01:42

I think its a bug in openerp. I have created a patch for that. In the openerp addons, web module, goto static/src/js/view_form.js.

Index: view_form.js
===================================================================
--- openerp/addons/web/static/src/js/view_form.js   
+++ openerp/addons/web/static/src/js/view_form.js   
@@ -833,11 +833,9 @@
                     // Special case 'id' field, do not save this field
                     // on 'create' : save all non readonly fields
                     // on 'edit' : save non readonly modified fields
-                    if (!f.get("readonly")) {
-                        values[f.name] = f.get_value();
-                    } else {
-                        readonly_values[f.name] = f.get_value();
-                    }
+                   values[f.name] = f.get_value();
+                    if (f.get("readonly"))
+                       readonly_values[f.name] = f.get_value();
                 }
             }
             if (form_invalid) {
查看更多
登录 后发表回答