How to create an address on a wizard

Hello. I am trying to import some data from a file trough a wizard.
Every goes right on, but when I create the address for a particular party, something goes wrong.
Part of the code is like this:

(.....)
Party = pool.get('party.party')
employer = {
     'name': person_data.employer,                           
     }                     
if person_data.employer_street\
or person_data.employer_location\
or person_data.employer_zip_code:                                                     
     address = {                                
                 'street':  person_data.employer_street,
                 'city': person_data.employer_location,
                 'zip': person_data.employer_zip_code,
                          }
     employer['address'] = [('create',address)]
employer = Party.create([employer])
(....)

And it gives me this error:

(....)
    employer = Party.create([employer])
  File "/trytond/modules/health/health.py", line 744, in create
    return super(Party, cls).create(vlist)
  File "/trytond/modules/party/party.py", line 192, in create
    return super(Party, cls).create(vlist)
  File "/trytond/model/modelsql.py", line 596, in create
    field.set(cls, fname, *fargs)
  File "/trytond/model/fields/one2many.py", line 215, in set
    actions[action](ids, *args)
  File "/trytond/model/fields/one2many.py", line 154, in create
    values = values.copy()
    AttributeError: 'str' object has no attribute 'copy'

Any help, would be very appreciated.
Regards
Francisco

Create operation in o2m relation need a list of dicts. Try:

employer[‘address’] = [(‘create’,[address])]

1 Like

Thank you so much! I miss that part. I always use with list, but this time I totally forgot it
Changing that, gives me gives me this error:

  employer = Party.create([employer])
  File "/trytond/modules/health/health.py", line 744, in create
    return super(Party, cls).create(vlist)
  File "/trytond/modules/party/party.py", line 192, in create
    return super(Party, cls).create(vlist)
  File "/trytond/model/modelsql.py", line 596, in create
    field.set(cls, fname, *fargs)
  File "/trytond/model/fields/one2many.py", line 222, in set
    Target.create(to_create)
  File "/trytond/model/modelsql.py", line 524, in create
    insert_values.append(field.sql_format(value))
  File "/trytond/model/fields/char.py", line 54, in sql_format
    assert isinstance(value, str)
AssertionError

It looks like one of the value for street, city or zip is not a string.

1 Like

It was that :(. Thank you all

Regards
Francisco

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.