Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

put a customer under a company using XML-RPC

By
Adrian
on 3/13/13, 7:12 AM 858 views

I'm trying to import Both customers and companies into OpenERP from another database. I can import both customers and company, but i am unable to link them: this is the code i am trying to use:

     if data:
            for erprow in data:
                #mielöt updatelünk vagy létrehozunk csekoljuk le hogy alá tudjuk e rendelniegy cégnek
                cegargs = [('panda_id', '=', int(csvrow[1])),]
                cegids = sock.execute(dbname, uid, pwd, model, 'search', cegargs)
                cegfields = ['id', 'name', 'child_ids',]
                cegdata = sock.execute(dbname, uid, pwd, 'res.partner', 'read', cegids, cegfields)
                """if cegdata:
                    #childcustomer = str(erprow['id']) + '/' + str(cegdata[0]['id'])
                    child = cegdata[0]['child_ids']
                    if not child:
                        child = False
                    update = True
                    print cegdata[0]['child_ids']
                    if erprow['id'] in child:
                        update = False
                    else:
                        child.append(int(erprow['id']))
                    if update:
                        cegvalues = {}
                        cegvalues['child_ids'] = child
                        results = sock.execute(dbname, uid, pwd, 'res.partner', 'write', cegids, cegvalues)
                    print '-------', cegdata[0]['child_ids']"""
                parent_id = False
                if cegdata:
                    parent_id = [int(cegdata[0]['id']), cegdata[0]['name']]
                # a tömböknek (dictionary pythomban) nevük van....
                values = {}
                #string be convertálom különben mindig külömböző lesz
                """if str(erprow['active']) != str(csvrow[0]):
                    values['active'] = csvrow[0]"""
                # x_panda_id ki hagyva mert az alapján vana keresés...
                if erprow['zip'] != csvrow[11]:
                    values['zip'] = csvrow[11]
                #a country kicsit nezebb mivel Openerpnek van saját táblája országokrol és IDvel müködik.
                if erprow['country'] != country_tomb:   
                    values['country'] = country_id
                    values['country_id'] = country_id
                if erprow['name'] != nev:
                    values['name'] = nev
                if erprow['street'] != csvrow[13]:
                    values['street'] = csvrow[13]
                """if erprow['street2'] != csvrow[6]:
                    values['street2'] = csvrow[6]"""
                if erprow['city'] != csvrow[12]:
                    values['city'] = csvrow[12]
                """if erprow['comment'] != csvrow[8]:
                    values['comment'] = csvrow[8]"""
                if erprow['email'] != csvrow[9]:
                    values['email'] = csvrow[9]
                if erprow['fax'] != csvrow[8]:
                    values['fax'] = csvrow[8]
                if erprow['mobile'] != csvrow[10]:
                    values['mobile'] = csvrow[10]
                if erprow['function'] != csvrow[5]:
                    values['function'] = csvrow[5]
                if erprow['phone'] != telefon:
                    values['phone'] = telefon
                if erprow['parent_id'] != parent_id:
                    erprow['parent_id'] = parent_id
                if cegdata:
                    if erprow['company_id'] != int(cegdata[0]['id']):
                        values['company_id'] = cegdata[0]['id']
                if values: 
                    number += 1
                    results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
                    print loop, '. ', number , ". results frissités pandából...", parent_id
                else:
                    number += 1
                    print loop, '. ', number , ". sor létezik de nincs frisités.", parent_id


        else:
            #mielöt updatelünk vagy létrehozunk csekoljuk le hogy alá tudjuk e rendelniegy cégnek
            cegargs = [('panda_id', '=', int(csvrow[1])),]
            cegids = sock.execute(dbname, uid, pwd, model, 'search', cegargs)
            cegfields = ['id', 'name',]
            cegdata = sock.execute(dbname, uid, pwd, 'res.partner', 'read', cegids, cegfields)
            parent_id = False
            if cegdata:
                parent_id = [int(cegdata[0]['id']), cegdata[0]['name']]
            number += 1
            print loop, '. ', number, ".Nem létezik - Létrehozzás"
            partner_data = {'name':nev, 'active': True, 'panda_id': csvrow[0], 'zip' : csvrow[11], 'country_id': country_id, 'street': csvrow[13],  'city': csvrow[12], 'email': csvrow[9], 'fax': csvrow[8], 'mobile': csvrow[10], 'function': csvrow[5], 'phone': telefon, 'parent_id': parent_id,}
            partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
    loop += 1
    print loop, local_number

it has a lot of print due to this script i run from command line and not openerp scheduler. Sadly i cant figure out how to link them as Company-> child.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/13/13, 7:12 AM
Seen: 858 times
Last updated: 3/16/15, 8:10 AM