On 26 Aug 05:10, TPH wrote:
> Hello,
>
> could somebody tell me please why this is not working and tell me whats the
> correct way :
>
> Party = Model.get('party.party')
> party = Party.find()
>
> for p in party:
> if '0815' in p.phone:
> for n, c in enumerate(p.contact_mechanisms):
> if c.value == '0815':
> p.contact_mechanisms.pop(n)
> p.save()
>
>
> I working with Tryton 2.4 an Proteus
>
> Error message: Fault 1: UserError Cannot change the party of an contact
> mechanism
By doing a pop, you just remove the contact mechanism from the party but
you don't delete it. But contact mechanism can not exist without being
linked to a party. So you have to delete it.
You can also use the remove method instead of pop.
p.contact_mechanisms.remove(p.contact_mechanisms[n])
I know it could be a little bit confusing, because Python list doesn't
have the difference so in proteus we did:
pop -> remove
remove -> delete
--
Cédric Krier - B2CK SPRL
Email/Jabber: [email protected]
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
pgpt79wikav8p.pgp
Description: PGP signature
