On 06/10/10 11:35 +0200, Cédric Krier wrote:
> On 06/10/10 02:26 -0700, Vincent wrote:
> > Hi,
> >
> > I've a little problem that's related to this.
> >
> > I have the following models (changed the names to not distract from
> > the problem):
> >
> > class Model1(ModelSQL, ModelView):
> > _name = "model1.model1"
> > _description = __doc__
> >
> > is_parent = fields.Boolean('This item is a parent', help='')
> > Model1()
> >
> > class Model2(ModelSQL, ModelView):
> > _name = "model2.model2"
> > main_item = fields.Many2One('model1.model1', 'Main Item')
> > child_items = fields.Many2Many('model3', 'model2field',
> > 'model1field', 'Example', help='',
> > domain = [
> > ('parent', '=',
> > Eval('main_item'))
> > ],
> > states = {
> > 'invisible':
> > Not(Bool(Eval('_parent_main_item.is_parent'))),
> > },
> > )
> > Model2()
> >
> > class Model3(ModelSQL, ModelView):
> > _name = "model3.model3"
> >
> > model2field = fields.Many2One('model2.model2', 'Model 2 record',
> > help='')
> > model1field = fields.Many2One('model1.model1', 'Model 1 record',
> > help='')
> > Model3()
> >
> > Basically in Model2 you select a main_item. If this main_item is a
> > parent, then the many2many field child_items should be visible so the
> > user can select its childs. The domain= part works, but the control is
> > always invisible regardless if a main_item is selected that is a
> > parent.
>
> This could only work if you edit Model2 from inside a one2many on Model1.
I need to complete the answer. What you did will work if the sequence of popup
windows is from bottom to top: Model1 - Model2 - Model3.
But you want this sequence: Model2 - Model3. So any of both form know about
values on Model1. So you must create a function field on Model2 that give you
the needed value of Model1. Something like this:
class Model2(ModelSQL, ModelView):
_name = "model2.model2"
main_item = fields.Many2One('model1.model1', 'Main Item')
main_item_is_parent = fields.Function(fields.Boolean(
'Main Item is a parent'), 'get_main_item_is_parent',
on_change_with=['main_item'])
child_items = fields.Many2Many('model3', 'model2field',
'model1field', 'Example', help='',
domain = [
('parent', '=', Eval('main_item'))
], states = {
'invisible': Not(Eval('main_item_is_parent', False)),
})
def get_main_item_is_parent(self, ids, name):
pass
def on_change_with_main_item_is_parent(self, vals):
pass
Model2()
> But anyway, this kind of difficulty generaly means that there is a problem in
> the design.
Perhaps the design is not wrong. I did not well understand at first read.
I think next time it will be easier to explain with real example.
--
Cédric Krier
B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/
pgpJjSQNbUaQ8.pgp
Description: PGP signature
