A frequent need is to run a button on a form based on selected records from a xxx2Many.
For example the wizards to handle exception on sale and purchase are indeed a way to implement this missing feature. A better design would be to launch the actions from a list of lines in exception.
We add a new attribute to
button tag on
form. The attribute
selected contains a comma separated list of names of the
xxx2Many fields for which the selected record ids are passed as argument to the button method as a list of dictionaries (following the same order as the records).
The button is deactivated if no record is selected for the
xxx2Many field (this shows to the user that the button is related to the selection). But also if the
xxx2Many contains any record without a positive id (this is because after save we could not ensure to select the right one).
ModelView.button_selected is added to complete the existing button decorator. It is in charge of instantiate and testing the selected dictionary:
- it instantiates the ids using the target class of the named
- it raise an error message if any selected records are not in the corresponding
xxx2Manyof the record.
The form parser get
<button/> defined inside the
<field/> and add them inside the frame of the widget (only for
many2many) at the bottom.
This attribute can be used for both kind of buttons.
button_action it will be up to the developer to pass the selected ids to the action.