Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

5

How to truncate text field ?

By
Nicolas Clavier
on 3/14/13, 6:57 AM 4,942 views

Hi folks,

Is there a way to truncate text of a fields.text() (in tree view especially), so that lines aren't huge in height ? I was thinking of a widget attribute in xml maybe ?

Thanks for your time. Nicolas

3
Quentin THEURET
On 3/14/13, 7:06 AM

You can use a fields.function with type='char'. The function to compute this field will give the fields.text value and truncate it.

Then, in the tree view, if you want the whole text, you display the fields.text otherwise, display the fields.function.

Hi, thanks for the trick. it's a good work around if you are not willing to have inline editing (e.i. editable="bottom"). Because we can't have an editable function field.

Nicolas Clavier
on 3/19/13, 6:17 AM

This is not true, you can define the parameter fnct_inv to create the write method of function field. However, in your case I agree that it wouldn't be conveniant as you would need a truncated field only in view mode and a full text in edit mode. A widget might be the best choice.

Camptocamp SA
on 3/19/13, 8:37 AM

I stumbled upon fnct_inv this morning to find that out .. how do you mean "a widget" .. writing a widget ?

Nicolas Clavier
on 3/19/13, 10:12 AM

Yes it is what I meant. Creating a widget that extends the base text widget and hides parts of the text only in view mode.

Camptocamp SA
on 3/20/13, 8:58 AM

I'm ok to get into writing widgets but have no time for now. Would it be complex ? Any link examples / repo ?

Nicolas Clavier
on 3/20/13, 10:32 AM

I'm marking this answer as a solution because in the end it's the only quick way to achieve this. Except that the list view won't be editable inline. I'll show the function field inline, and the original text field in the form. Thank @all

Nicolas Clavier
on 3/20/13, 10:35 AM
3

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/18/13, 7:39 PM

Hi, there is a function which do that in 6.0, function truncate_data, you can find it here :

http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/mail_gateway/mail_gateway.py

update with new informations given by comment after :

if you can have status of the page, editable or browse, you can use function I gave before :

create a new field text which is updated by onchange with first you are already created.

in tree view in function of state of the page (editable or browse), one is visible, the second no.

Bye

Hi, thanks for pointing this out to me but the idea here is to have a text field that can be fully edited inline, and that only shows so many characters when in browse mode. If the behavior doesn't exist, I'll post a feedback on http://feedback.openerp.com. These features are lacking, along with placeholders, rich text, etc.

Nicolas Clavier
on 3/19/13, 6:27 AM

I update my answer

Cyril Gaspard (GEM)
on 3/19/13, 6:50 AM

ok, sounds like the answer I was looking for. Still have to detect the field/view state, any hint ? is it a variable available in xml (a bit like active_id, parent, etc) ?

Nicolas Clavier
on 3/19/13, 10:02 AM

I can't find in the view the boolean context variable set_editable mentioned here : http://doc.openerp.com/trunk/developers/web/list_view/#editability-status

Nicolas Clavier
on 3/19/13, 10:23 AM

I believe you do not understood what I would say by editable/browse. Editable is when you push a button create or edit, browse is a view in state read (I wanted just use terms you used yourself). By regarding your other new questions, attribute set_editable is to have a tree with lines editable without wizard form opened to modify value of fields, this is not the same thing. I do not if it is possible to have the status edit/read mode of a view. bye

Cyril Gaspard (GEM)
on 3/19/13, 7:58 PM

Hi GEM, thanks for coming back to me. I understand both contexts are different. The link above discusses a javascript context accessed from the client side which could as well be a completely different context from the server side context. I created a new question to dig and clarify this topic.

Nicolas Clavier
on 3/20/13, 5:28 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/14/13, 6:57 AM
Seen: 4942 times
Last updated: 4/15/16, 10:45 AM