On Friday, April 24, 2015 at 2:45:02 AM UTC-5, Cédric Krier wrote: > > On 23 Apr 14:34, M. Murray wrote: > > I am attempting to use the UnionMixin available in 3.4 to make a model > that > > is just a collection of records from other models. All the other > ModelSQLs > > have a few common fields and these fields are defined on the model that > > uses the UnionMixin. Based on my understanding, that's how the > UnionMixin > > determines which field to select from each of the models' tables used in > > the union. > > > > My questions are about the recommended way to do things as it relates to > > this Mixin. > > > > 1. Should I inherit from ModelSQL *and* UnionMixin? - I think yes > > because it's ModelSQL's methods that are overridden to make > UnionMixin work > > 2. If the answer to #1 is yes, should I register the model in the > Pool? > > When I do, it creates a table for the UnionMixin model. Is this > expected? > > It must be registered but it is not expected. > See how Union are define here: > http://hg.tryton.org/trytond/file/10cfbb9153b6/trytond/tests/model.py#l75 > The order of dependency is important. >
I see. So I have to put UnionMixin before ModelSQL. That makes sense and it worked. Also, no table created. > > 3. Looking at the code, I see that I can unshard the union-ised ID to > > get the index of the original model. Is this the recommended way for > me to > > identify the original model? > > Why not. > > 4. Is there a way to rewire the [New Record] button to give the user a > > chance to choose which model, within the union, to create or which > form to > > use? If not, I think I may be able to use a wizard > > No, Union are readonly. > I use the UnionMixin model in a One2Many relationship. When placed on a form, I have to explicitly make it read-only. Or else, I get a [New Record] button that uses the generic Tryton generated form. > > > 5. Further to #4, is there a way to rewire the double-click in the > tree > > view so it opens the appropriate form for the model of row clicked? > > You probably should be able to trigger a wizard on click that will open > the right form base on the active_id. > I've gotten as far as putting a button in the read-only tree that opens the right form. But, I can't seem to figure out how to pass the active_id to the form being opened. The other thing I would like to know, how can I make the form open in a popup window similar to the way the default form would popup for a One2Many field. > > > And finally, am I on the right track or did I misunderstand the purpose > of > > the UnionMixin? > > No, it seems you have a valid use case. > > -- > Cédric Krier - B2CK SPRL > Email/Jabber: [email protected] <javascript:> > Tel: +32 472 54 46 59 > Website: http://www.b2ck.com/ > And thanks for your help and your amazing contributions to the world. --- M
