On 09/09/10 05:46 -0700, Vincent wrote:
> Hi all,
> 
> I'm also quite new to Tryton development and I really like what I've
> seen so far. I'm working on some modules to make myself more familair
> with the framework.
> 
> I'm encountering a small issue with a one2many field.
> 
> My class includes two one2many fields: "party" and "contact".
> 
> party = fields.Many2One("party.party", 'Party', required=True)
> contact = fields.Many2One("party.address", 'Contactperson',
> required=True,
> domain = [
> ('party', '=', Eval('party')),
> ('delivery', '=', False),
> ('invoice', '=', False),
> ],
> 
> When I make a dedicated module with a form, this works. When I change
> party, I can only select contactpersons from that party (technically
> it is redundant to store both in the same record, but from usability
> perspective I really want the user to first select the company, then
> the contactperson. I may solve this technically later by using a
> Function field for party or something). However, for now everything
> works as expected.
> 
> Then I inherit the party.party object and add a One2Many field to
> above's described model and create an altered view.
> 
> This is the field that I add into the inherited party.party model:
> visitreports = fields.One2Many('party.visit', 'party', 'Visit
> reports')
> 
> Still works correctly, I see the objects for the selected party now.
> However, when I click "New record" button on this One2Many field, I
> have a small problem. The window that is displayed now does not
> contain the "party" field (which is understandable), but now the
> "contact" field does not work as a result. It doesn't find any
> contactperson. I guess it can't evaluate Eval('party') in this
> scenario correctly (I do not see any erros in the logs, however).
> 
> Would there be a way to solve this, so that this construction will
> work in both standalone forms and One2Many fields?

In fact, you have an issue because there is a circular dependency.

You can not solve the domain because there is a simple case where it doesn't
work. Per example, if you create a new party without saving, add an address
still without saving and now you try to create a visit for this party you will
not find any address because it is not yet saved.

So there is a simple solution which is is: don't cerate a one2many but use a
relate button.

But I think you are using address like a contact but this is a wrong usage. An
address represents just a place in the world. To represent a person you must
use "party".

-- 
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: pgpcV74HypAQi.pgp
Description: PGP signature

Reply via email to