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.

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')  },
                               )

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

Best regards, Vincent

-- 
[email protected] mailing list

Reply via email to