Migrating sales from xl to odoo using XML-RPC
<p>Im trying to migrate sales order from excel sheet to odoo using xmlrpc so far i have the products working,client working but when i try to insert the sale order i get this error</p>

<pre><code>Traceback (most recent call last):
  File "/home/oasis/PycharmProjects/somig/migrator.py", line 75, in &lt;module&gt;
    'validity_date':"2016-01-18",
  File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1283, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1316, in single_request
    return self.parse_response(response)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1493, in parse_response
    return u.close()
  File "/usr/lib/python2.7/xmlrpclib.py", line 800, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: &lt;Fault 1: 'Traceback (most recent call last):\n  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 56, in xmlrpc_return\n    result = openerp.http.dispatch_rpc(service, method, params)\n  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc\n    result = dispatch(method, params)\n  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch\n    res = fn(db, uid, *params)\n  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 173, in execute_kw\n    return execute(db, uid, obj, method, *args, **kw or {})\n  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper\n    return f(dbname, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 181, in execute\n    res = execute_cr(cr, uid, obj, method, *args, **kw)\n  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 170, in execute_cr\n    return getattr(object, method)(cr, uid, *args, **kw)\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 250, in wrapper\n    return old_api(self, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 354, in old_api\n    result = method(recs, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/addons/sale/sale.py", line 232, in create\n    result = super(SaleOrder, self).create(vals)\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 248, in wrapper\n    return new_api(self, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/mail_thread.py", line 233, in create\n    thread = super(MailThread, self).create(values)\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 248, in wrapper\n    return new_api(self, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4157, in create\n    record = self.browse(self._create(old_vals))\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 248, in wrapper\n    return new_api(self, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 490, in new_api\n    result = method(self._model, cr, uid, *args, **old_kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4301, in _create\n    tuple([u[2] for u in updates if len(u) &gt; 2])\n  File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 141, in wrapper\n    return f(self, *args, **kwargs)\n  File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 220, in execute\n    res = self._obj.execute(query, params)\nProgrammingError: column "partner_id" is of type integer but expression is of type integer[]\nLINE 1: ...1, NULL, \'draft\', 6, 1, 1, \'2016-09-03 16:50:24\', ARRAY[6], ...\n                                                             ^\nHINT:  You will need to rewrite or cast the expression.\n\n'&gt;

Process finished with exit code 1
</code></pre>

<p>my code is the following</p>

<pre><code>import psycopg2
import psycopg2.extras
import pyexcel_xls
import pyexcel as pe
from pyexcel_xls import get_data
from datetime import datetime
import xmlrpclib
import json

url = 'http://localhost:8070'
db = 'fresh'
username = 'admin'
password = 'odoo'
#data = get_data("salesorder.xls")
#print(json.dumps(data))
records = pe.get_records(file_name="salesorder.xls")
for record in records:
    print record['name']
    names = record['name']
    print record['location']
    print record['zip']
    print record['republic']
    dates = record['date']
    print dates
    print datetime.strptime(dates,'%d/%M/%Y')
    lastdat=datetime.strptime(dates,'%d/%M/%Y')
    print record['product']
    productname= record['product']


#Check if the customer is in or else insert him
    common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
    uid = common.authenticate(db, username, password, {})
    output = common.version()
    models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
    partnerids = models.execute_kw(db, uid, password,
                    'res.partner', 'search', [[['name', '=', record['name']]]])

    if partnerids:
        print partnerids

    else:
        newpartn = models.execute_kw(db, uid, password, 'res.partner', 'create', [{
            'name': names,
        }])
        partnerids=newpartn
        print partnerids
#Check if a product is in else insert a new product
    common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
    uid = common.authenticate(db, username, password, {})
    output = common.version()
    models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
    productids = models.execute_kw(db, uid, password,
                                   'product.product', 'search', [[['name', '=', record['product']]]])

    if productids:
        print productids

    else:
        newproduct = models.execute_kw(db, uid, password, 'product.product', 'create', [{
            'name': productname,
            'default_code': partnerids
        }])
        productids=newproduct
        print productids



    uid = common.authenticate(db, username, password, {})
    print output
    models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
    id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
        'partner_id': partnerids,
     #   'name': names,
        'validity_date':"2016-01-18",
        #'payment_term_id':1,
        # 'user_id':"1"
        # 'state':"sale"


    }])
    print id
</code></pre>

<p>the 75th line is the one of validity date</p>

<p>I think the issue is that you execute a search for partnerids which will result in an array. However if you do not find any you create a partner which is represented by an integer. You then assign partnerids to the partner_id in your sale.order. </p>

<p>Sometimes you are assigning it an integer and other times an array, depending on if you are using the partnerids from the search or the newly created partner.</p>

<p>If you are sure that your search for partnerids will never result in two partners having the same name then you can use the first record returned in your search which I display below. I reassigned partnerids on a second line simply to illustrate the difference. </p>

<p>If you are not sure if you have duplicates this will be the wrong thing to do and you should refine your search to select the correct partner.</p>

<pre><code>    partnerids = models.execute_kw(db, uid, password,
                'res.partner', 'search', [[['name', '=', record['name']]]])
    partnerids = partnerids[0] if partnerids else False 

if partnerids:
    print partnerids

else:
    newpartn = models.execute_kw(db, uid, password, 'res.partner', 'create', [{
        'name': names,
    }])
    partnerids=newpartn
</code></pre>

python openerp xml-rpc