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

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.

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

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"/>
Ảnh đại diện
Huỷ bỏ
Tác giả

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.

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

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

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.



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

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

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

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..

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

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).

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 15
7424
1
thg 2 16
4904
3
thg 5 25
1956
1
thg 4 25
1471
3
thg 9 24
14462