Hi,
on the migration to 2.2 I have a problem with reverse domains.
In my 1.8 code I could use a structure like this. But this no longer
works in Tryton 2.2 (see ###):
class Test(ModelSQL, ModelView):
_name = 'test.test'
contact_person = fields.Many2One('party.party', 'Contact Person',
required=True, domain=[
('party_type', '=', 'person'),
### The following clause does no longer work in 2.2
### When I create a new party from within field contact_person,
### the field organization_members is filled with the correct
### party from the context [1] but I can not save the record.
### In the client, the field stays colored red like an
### unsatisfied required.
('organization_members', 'in', [Eval('party'),]),
], context={
'organization_members': Eval('party'),
}, states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['party', 'state'])
Test()
Here is the depending code to complete the above structure:
class Party(ModelSQL, ModelView):
_name = 'party.party'
party_type = fields.Selection([
("organization", "Organization"),
("person", "Person"),
], "Party Type", select=1, readonly=False, on_change=[
'party_type',
], states={
'readonly': Not(Bool(Eval('active'))),
}, depends=['active'])
organization_members = fields.Many2Many(
'party.rollup.organization-person', 'person',
'organization', 'Member of Organizations', domain=[
('party_type', '=', 'organization'),
], states={
'readonly': Not(Bool(Eval('active'))),
'invisible': Equal(Eval('party_type'), 'organization'),
}, depends=[
'party_type', 'active',
], help='Organizations where this person is member.')
### [1]
def default_organization_members(self):
res = Transaction().context.get('organization_members', [])
if isinstance(res, (int, long)):
res = [res]
return res
Party()
class PartyRollupOrganizationPerson(ModelSQL, ModelView):
'''Mapping between parties with party types person and
organization'''
_name = 'party.rollup.organization-person'
_rec_name = 'person'
_description = __doc__
person = fields.Many2One('party.party', 'Person', required=True,
domain=[
('party_type', '=', 'person'),
], context={'party_type': 'person'}, ondelete='CASCADE')
organization = fields.Many2One('party.party', 'Organization',
required=True, domain=[
('party_type', '=', 'organization'),
], ondelete='CASCADE')
PartyRollupOrganizationPerson()
Anyone has an idea, what I am doing wrong?
Cheers Udo
--
_____________________________
virtual things
Preisler & Spallek GbR
München - Aachen
Windeckstr. 77
81375 München
Tel: +49 (89) 710 481 55
Fax: +49 (89) 710 481 56
[email protected]
http://www.virtual-things.biz
--
[email protected] mailing list