Skip to main content

Python CSV to OpenERP importation library

Project description

csv2oerp is a simple tool to perform a data migration, through an OpenERP mapping bounded to a CSV file. You can easily order your data as the manner of OpenERP (models, fields). The structure of the mapping is simple and intuitive, you can also perform a pre-process on data being imported, omit it or just modify it.

Quick start

Import csv2oerp and some callbacks:

from csv2oerp import Import_session
from csv2oerp.fields import Column, Custom, Relation
from csv2oerp.callbacks import get_id, get_ids

Configure OpenERP connection:

host = ''
port = 8069
dbname = 'database'
user = 'admin'
pwd = 'admin'
csv2oerp.connect(host, port, user, pwd, dbname)

Create a new importation instance:

example_file = Import_session()

Set the CSV file to use:

example_file.set_input_file('example_file.csv', ',', '"', 'utf-8')

Define a custom callback(Field’s value pre-treatment):

def country_code(self, model, field, value, line):
    """Return the first two uppered characters from current column value
    return value[:2].upper()

Define your mapping to link both csv and OpenERP:

mapping = {
    # Define a base model (Always in list form)
    'res.partner.address': [

        # Custom field's value
        'type':         Custom('default', search=True),

        # Concatenated columns fields
        'street':       Column([7, 6]),
        'street2':      Column([8, 5]),

        # Simple fields
        'zip':          Column(9),
        'city':         Column(10),
        'cedex':        Column(68),
        'phone':        Column(14),
        'fax':          Column(15),
        'email':        Column(17),

        # Model's relation with dynamic insertion from OpenERP database
        # Not native object from OpenERP framework
        'region_id':    Custom(11, get_id('res.region', ['name']))
        'dep_id':       Custom(12, get_id('res.dep', ['name']))

        # Model's relations not updated if exists
        'country_id':   Relation('REL_res_partner_address,'),

        # Model's relations with unique value between objects
        'partner_id':   Relation('REL_res_partner_address::res.partner', search=True),


    # Define relations between models
    'REL_res_partner_address::res.partner': {
        'name':         Column(1),
        'siren':        Column(2),
        'website':      Column(16),
        'comment':      Column(56),

    # Relation without write if exists
    'REL_res_partner_address,':  {
        'code':         Column(13, callback=_country_code, search=True),
        'name':         Column(13, search=True),

Finally start the import process:


And show statistics of objects’s activities during the importation process:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv2oerp-0.6.2.tar.gz (31.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page