Hi ! I am tryng to update existing phones list and add some new ones over a script and what i can do is to create new parties with all the data, but what i can’t do is to update for each partie the extra phone number.
What i succeded is to migrate multiple addreses for each partie.
What i can’t understand, is how should i do to add each phone for each “original” partie.
I am sure that some of you allready did this before please help ! any piece of code to see how is done? or explanation ? anything that could help ! thanks in advance !
Thanks for answering so fast Cédric !
That, understanding that i have to do for example:
p = Party()
mechanism = p.contact_mechanism.new()
mechanism.save() # but this didn't work well..
tried also:
mechanism = ContactMechanism.find([])
if Party.find(['id', '=', ids_from_xslx_file[i]], limit=1)
for cm in mechanism:
try:
if phone_number.startswith(..):
cm.value = phone_number
cm.type = 'phone'
cm.save()
But this one overwrites the existing phones… not so good. Maybe i didn’t understood exactly how it works internally. Also i am kind of noob with Python in general but I’m willing to learn more
for i in range(len(df)):
if Party.find(['code', '=', "C" + sanitize(df['ID_Tryton'][i])], limit=1):
p = Party()
cm = p.contact_mechanisms.new()
try:
if sanitize_phone(df['TELF1'][i]).startswith('9'):
cm.value = sanitize_phone(df['TELF1'][i])
cm.type = 'phone'
elif sanitize_phone(df['TELF1'][i]).startswith('6'):
cm.value = sanitize_phone(df['TELF1'][i])
cm.type = 'mobile'
except Exception as e:
print(e)
pass
to_save.append(p)
Party.save(to_save)`
I think I’m getting close to solve it
Parties are created, but as new ones, not by adding each phone number for an existing party wich i try to find it by internal code as i have stored clients as C+ inicial_id from the migration file.xlsx.
I tought about that…because instanciation of Party() is used when i create new records…doing a clean migration…
if Party.find(['code', '=', "C" + sanitize(df['ID_Tryton'][i])], limit=1):
# p = Party()
p, = Party.find(['code', '=', "C" + sanitize(df['ID_Tryton'][i])])
if p:
cm = p.contact_mechanisms.new()
try:
if sanitize_phone(df['TELF1'][i]).startswith('9'):
if sanitize_phone(df['TELF1'][i]):
cm.value = sanitize_phone(df['TELF1'][i])
cm.type = 'phone'
elif sanitize_phone(df['TELF1'][i]).startswith('6'):
if sanitize_phone(df['TELF1'][i]):
cm.value = sanitize_phone(df['TELF1'][i])
cm.type = 'mobile'
to_save.append(p)
# print(cm.value, cm.type)
except Exception as e:
print(e)
pass
Party.save(to_save)
Replaced the search ID_Tryton with Client_ID and it worked
And this is just the start… Thank you for your patience ! Now all i have to do is validate the numbers with +34 and write the comments for each one