On 09/11/10 04:02 -0800, Vincent wrote:
> Hi,
> 
> In party.party I have added a Many2One field to, as I don´t want to
> distract from this problem I´ll call it, "Model X". I'll have this
> problem with various models which are similair. You can think of Model
> X as "visit reports" for example, but we have more similair
> constructions.
> 
> In this Model X I have a field for party.address, so I really need
> Party ID when user clicks on the many2one field's Add button on the
> Party form.
> 
> I am aware of the fact that this will not work when user has not yet
> saved the party and/or its new address, if this is the case it's a
> technical restriction I probably have to live with.

It is not technical but a design restriction. Because you get a circular
dependency.

> 
> Not being able to simply retrieve the "party" field of model X, on
> Tryton's IRC channel it was suggested to use the context for this.
> 
> So, in party.party I have added following field:
> 
>     modelxrec= fields.One2Many('model.x', 'party', 'X records',
>                                context={'party' :
> Eval('active_id')  },
>                                )


Is it a Many2One or a One2Many?

> 
> Then in Model X I have the address field defined like:
> 
>     address = fields.Many2One('party.address', 'Address',
> required=True,
>                               domain=[
>                                        ('party',
>                                        If(In('party', Eval('context',
> {})), '=', '!='),
>                                        Get(Eval('context', {}),
> 'party', 0))
>                                      ]
>                               )
> 
> I think this should work, but it doesn't. When adding various print
> statements to Pyson eval functions I don't see ´party´ in the printed
> contexts (but maybe I am not interpreting the printed values
> correctly). However, if I manually do a
> Transaction().context.get('party') and return it in a dummy Default
> field of the Model X, then I see the party ID which I expected.
> 
> Is my assumption that the Pyson code should be able to find "party" in
> the context correct?
> 
> I really don't want to work with relate buttons on the party.party
> model in this case, it's simply not an acceptable solution from a
> usability point of view.

I don't understand why?
For me, what you are creating is something like a "case" so it is like if you
wanted to create a sale order from within the Party form.

> It shouldn't be too hard to find the Party
> ID, as the many2one field itself should know what his parent record
> is, so I think (hope) there's an easier solution.
> 
> Any help is greatly appreciated.

There is perhaps somewhere in the client a context that is not passed but it
is hard to find it like that, you should give a simple module to display the
issue if you may not show your code. This will allow everybody to talk, run
and test the same code.

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

Attachment: pgpiKZQ9FcbSK.pgp
Description: PGP signature

Reply via email to