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.

1

[8] Show a state depending on a field

By
PY
on 8/5/15, 4:17 AM 547 views

Hi !

Is this possible to show/hide a certain state (with the statusbar widget) depending on a certain field.

For example:

class Test(models.Model):
_name = 'test.test'

foo = fields.Selection([('a', 'B'), ('b', 'B')])
state = fields.Selection([('open', 'Open'), ('a', 'A'), ('b', 'B'), ('closed', 'Closed')])


<field name="state" widget="statusbar" statusbar_visible="open,closed"/>

so:

- if field foo is set to a, visible sates would be: open, a, closed

- if field foo is set to b, visible sates would be: open, b, closed

Is something like that possible ?

So far, I can only hide both a and b states, and show them when the record state is in either of them.

1
Emanuel Cino
On 12/3/15, 5:16 AM

One way to do it is to add two related fields :

state_a = fields.Selection(related='state')
state_b = fields.Selection(related='state')

In the view :

<field name="state" invisible="1"/>
<field name="state_a" attrs="{'invisible': [('foo', '=', 'b')]}" statusbar_visible="open,a,closed"/>
<field name="state_b" attrs="{'invisible': [('foo', '=', 'a')]}" statusbar_visible="open,b,closed"/>

Did you test this yourself ? I'm not on this anymore, but if it actually works, I'm going to accept this answer, so that other people can use it.

PY
on 12/7/15, 3:16 AM

Yes I used this in my code and it is working.

Emanuel Cino
on 12/7/15, 3:23 AM
0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/5/15, 6:49 AM

Hey friend:

Here is what you need:

in your XML:

In front of field_a :

<field name="field_a" attrs="{'invisible': [(foo','=',b)]}"/> 

And, in front of field_b:

<field name="field_b" attrs="{'invisible': [(foo','=',a)]}"/>  

Hope this may help you.

Regards.



No, there's no field_a or field_b. I'll update my question.

PY
on 8/5/15, 8:04 AM
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 8/5/15, 9:04 AM

Hello,

We can play with invisible attribute,

So you can use:


<field name="state" widget="statusbar" statusbar_visible="open,a,closed" attrs="{'invisible': [('foo','!=','a')]}"/>
<field name="state" widget="statusbar" statusbar_visible="open,b,closed" attrs="{'invisible': [('foo','!=','b')]}"/>

 ;)

Regards..

Nope :/ I already tried that. Only the last statusbar will work properly. For example, in the state 'open', only the second statusbar will be colored blue (on the 'Open' li tag).

PY
on 8/5/15, 9:07 AM

Mate !!!!, I removed for sure :)

Ahmed M.Elmubarak
on 8/5/15, 9:21 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: 8/5/15, 4:17 AM
Seen: 547 times
Last updated: 12/7/15, 3:35 AM