Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
8 Trả lời
7940 Lượt xem

Hi


I am in situation,Need to save the readonly field values so need to get those values in the write and create method vals
Ảnh đại diện
Huỷ bỏ

I have the same requirement!

Hi, Can you please explain your need ,, may be there will be other better solution..?? For Eg: you can use compute field.

Câu trả lời hay nhất

@Sairam.  Unfortunately readonly fields are implemented INPUT tag with disabled attribute turned on (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input) and thus will not be submitted to the server.

Now, if a field is readonly, usually it won't be changed by the user anyway, so the only possibilities, that I can think, of the value dynamically changed will be due to default or on change mechanism.

If it is due to default (specified in the default_get method or _default attribute of ORM).  You can just create/write without the value of that field.  ORM will automatically get the value from the default mechanism.

If it is due to on change mechanism, you can, by inheriting the write and/or create method, obtain the value of the field from the return of the on change method.

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks Ivan. I changed base code in js file to get the readonly values in create or write method

Câu trả lời hay nhất

bad thing, but use a direct database request ...

or set your field invisible and not readonly and add a field function which change its value depending the value of your invisible field.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Thank you Cyril, works fine.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Hi,

Got the solution by changing the code in base files readonly values will get in create ,write methods so the it will store in database

addons/web/static/js/view_form.js:

In view_form.js:

in line: 840:

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();

}

}

 Thanks.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can easily access readonly fields on the server throught the context like this:
 

self.env.context


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 6 22
2291
0
thg 4 15
186
3
thg 9 23
59504
7
thg 5 20
19178
0
thg 9 19
98