On 2015-08-03 22:22, Fabien Castarède wrote:
> Bonjour,
> 
> Voici comment je procède pour créer un nouveau tiers avec ses moyens de 
> contact :
> 
> appstruct = form.validate(self.request.POST.items())
> contact_mechanisms_appstruct = appstruct.pop('contact_mechanisms', [])
> 
> party = self.Model.create([appstruct, ])[0]
> for cm in contact_mechanisms_appstruct:
>     cm.update({'party': party})
> party.contact_mechanisms = self.pool.get('party.contact_mechanism').create(
> contact_mechanisms_appstruct)
> 
> from trytond.transaction import Transaction
> cursor = Transaction().cursor
> cursor.commit()
> 
> Cela fonctionne, mais y aurait-il une meilleur syntaxe ? Qui permettrait de 
> s'affranchir de :
> 
> for cm in contact_mechanisms_appstruct:
>     cm.update({'party': party})

Les champs One2Many peuvent prendre comme valeur des opérations à
appliquer sur la cible :

http://doc.tryton.org/3.6/trytond/doc/ref/models/fields.html#trytond.model.fields.One2Many


-- 
Cédric Krier - B2CK SPRL
Email/Jabber: [email protected]
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Répondre à