Help making action context dependent based upon selected items


(Richard PALO) #1

I’m looking for a hint on how to make an action context dependent, for example in the invoices tree view to enable the action only when two or more invoices involving the same party are selected.
(I’d like to add it to the pop-up menu thus as well)
There doesn’t seem, at first sight, a means to hide the keyword from the action menu via the xml file, how to do so in code then?
Pointer to existing example is welcome!
BTW, disabling is needed in the form view as well.


(Jean Cavallo) #2

Hi,

You can do part of that by using a button with the “keyword” attribute set : Issue 7067: Button location in the toolbar is hardcoded to be on the Action button - Tryton issue tracker

Basically, declare a button with the appropriate states, then use the keyword attribute when adding the button to your view to say in which menu it should appear.

However, your particular use case will probably not be possible, since it depends on multiple selected lines, and there is no way as far as I know to access those multiple lines in an Eval statement.


(Richard PALO) #3

is it possible to check len(Transaction().Context[‘active_ids’]) >2?


(Jean Cavallo) #4

I am almost sure that states on buttons are only evaluated if only one line is selected @ced ?


(Sergi Almacellas Abellana) #5

You can with the len operator of pyson:

Len(Eval('active_ids', [])) > 2